:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color-scheme: light dark;

  --bg: #ffffff;
  --fg: #111111;
  --border: #dddddd;
  --border-soft: #cccccc;
  --subtle: #fafafa;
  --subtle-alt: #f5f5f5;

  --msg-info: #2470ff;
  --msg-warn: #b8860b;
  --msg-error: #d32f2f;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101010;
    --fg: #f3f3f3;
    --border: #333333;
    --border-soft: #444444;
    --subtle: #151515;
    --subtle-alt: #181818;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
}

header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  background: var(--subtle);
}

header h1 {
  font-size: 1rem;
  margin: 0;
  margin-right: 1rem;
  font-weight: 600;
}

label {
  font-size: 0.85rem;
  margin-right: 0.2rem;
}

select,
button,
input[type="checkbox"],
input[type="text"] {
  font: inherit;
}

select,
button,
input[type="text"] {
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border-soft);
  background: var(--bg);
  color: var(--fg);
}

button {
  cursor: pointer;
}

button:hover {
  background: var(--subtle-alt);
}

#status {
  margin-left: auto;
  font-size: 0.8rem;
  opacity: 0.85;
  white-space: nowrap;
}

main {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  min-height: 0;
}

/* Панелі (ліва/права) */
.panel {
  padding: 0.75rem;
  flex: 1 1 320px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-right: 1px solid var(--border);
  min-height: 0;
  background: var(--bg);
}

.panel:last-child {
  border-right: none;
}

/* Текстові поля */
textarea {
  width: 100%;
  min-height: 200px;
  resize: vertical;
  font-family: "JetBrains Mono", Consolas, "Fira Code", monospace;
  font-size: 0.85rem;
  padding: 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border-soft);
  background: var(--bg);
  color: var(--fg);
}

/* Прев’ю */
#preview-wrapper {
  flex: 1;
  min-height: 200px;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: auto;
  background: var(--subtle);
  padding: 0.5rem;
}

#preview {
  display: inline-block;
}

#output-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

#output-toolbar span {
  font-size: 0.8rem;
  opacity: 0.8;
}

/* Messages */
#messages {
  margin-top: 0.75rem;
  border-top: 1px solid var(--border);
  padding-top: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

#messages-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}

#messages-body {
  max-height: 120px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.4rem 0.5rem;
  font-family: "JetBrains Mono", Consolas, "Fira Code", monospace;
  font-size: 0.75rem;
  background: var(--subtle);
  white-space: pre-wrap;
}

.msg-line.info {
  color: var(--msg-info);
}

.msg-line.warn {
  color: var(--msg-warn);
}

.msg-line.error {
  color: var(--msg-error);
}

/* Image tools */
#image-tools {
  margin-top: 0.75rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#image-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

#image-preview-wrapper {
  border: 1px dashed var(--border-soft);
  border-radius: 4px;
  padding: 0.5rem;
  background: var(--subtle);
  display: inline-block;
  max-width: 100%;
  overflow: auto;
}

#image-preview {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Font tools */
#font-tools {
  margin-top: 0.75rem;
  border-top: 1px solid var(--border);
  padding-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#font-loader-input {
  min-height: 80px;
  font-size: 0.75rem;
}

#font-loader-hint {
  font-size: 0.75rem;
  opacity: 0.8;
}

small {
  font-size: 0.75rem;
  opacity: 0.8;
}

/* Допоміжні елементи */
.input-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.demo-buttons {
  display: inline-flex;
  gap: 0.5rem;
}

.demo-buttons button {
  font-size: 0.85rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border-soft);
  background: var(--subtle-alt);
}

/* Мобільна адаптація */
@media (max-width: 768px) {
  header {
    align-items: flex-start;
  }

  header h1 {
    flex-basis: 100%;
    margin-right: 0;
  }

  #status {
    margin-left: 0;
    flex-basis: 100%;
  }

  main {
    flex-direction: column;
  }

  .panel {
    flex: 1 1 auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .panel:last-child {
    border-bottom: none;
  }

  textarea {
    min-height: 160px;
  }

  #preview-wrapper {
    min-height: 180px;
  }
}
