/* ——— Кольори й розміри ——— */

:root {
  color-scheme: light;
  --bg: #f5f4ef;
  --surface: #ffffff;
  --surface-2: #f1f0ea;
  --text: #1c1c1e;
  --muted: #6b6a65;
  --border: #e3e1d9;
  --border-strong: #cfccc2;
  --accent: #2a5bd7;
  --accent-hover: #2249b0;
  --accent-text: #ffffff;
  --accent-soft: rgba(42, 91, 215, 0.14);
  --mark-bg: rgba(255, 204, 0, 0.38);
  --ins-bg: #d9f3e1;
  --ins-text: #12632f;
  --del-bg: #fde3e0;
  --del-text: #b1251a;
  --danger: #b42318;
  --ok: #1d7038;
  --notice-bg: #fff6d4;
  --notice-text: #5f4a00;
  --notice-border: #efd98a;
  --skeleton: #ecebe5;
  --skeleton-shine: #f7f6f2;
  --shadow: 0 1px 2px rgba(20, 20, 15, 0.04), 0 6px 24px rgba(20, 20, 15, 0.06);

  --radius: 16px;
  --radius-sm: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --text-size: 17px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141518;
    --surface: #1c1d21;
    --surface-2: #23252a;
    --text: #ecebe8;
    --muted: #9c9b96;
    --border: #2e3036;
    --border-strong: #41444c;
    --accent: #7ea4ff;
    --accent-hover: #9ab8ff;
    --accent-text: #0c1222;
    --accent-soft: rgba(126, 164, 255, 0.2);
    --mark-bg: rgba(255, 204, 0, 0.24);
    --ins-bg: rgba(52, 168, 93, 0.22);
    --ins-text: #8ee0a7;
    --del-bg: rgba(232, 80, 72, 0.2);
    --del-text: #ff9a92;
    --danger: #ff8f87;
    --ok: #8ee0a7;
    --notice-bg: #2a2516;
    --notice-text: #f1d987;
    --notice-border: #4a3f1d;
    --skeleton: #26282d;
    --skeleton-shine: #2f3238;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 24px rgba(0, 0, 0, 0.25);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141518;
  --surface: #1c1d21;
  --surface-2: #23252a;
  --text: #ecebe8;
  --muted: #9c9b96;
  --border: #2e3036;
  --border-strong: #41444c;
  --accent: #7ea4ff;
  --accent-hover: #9ab8ff;
  --accent-text: #0c1222;
  --accent-soft: rgba(126, 164, 255, 0.2);
  --mark-bg: rgba(255, 204, 0, 0.24);
  --ins-bg: rgba(52, 168, 93, 0.22);
  --ins-text: #8ee0a7;
  --del-bg: rgba(232, 80, 72, 0.2);
  --del-text: #ff9a92;
  --danger: #ff8f87;
  --ok: #8ee0a7;
  --notice-bg: #2a2516;
  --notice-text: #f1d987;
  --notice-border: #4a3f1d;
  --skeleton: #26282d;
  --skeleton-shine: #2f3238;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 24px rgba(0, 0, 0, 0.25);
}

/* ——— Основа ——— */

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
select,
textarea {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ——— Шапка ——— */

.topbar {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 14px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
  border-radius: var(--radius-sm);
}

.brand-mark {
  width: 36px;
  height: 36px;
  color: var(--accent);
  flex: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-text strong {
  font-size: 19px;
  letter-spacing: -0.01em;
}

.brand-text span {
  font-size: 13px;
  color: var(--muted);
}

.icon-btn {
  width: 40px;
  height: 40px;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}

.icon-sun {
  display: none;
}

:root[data-theme="dark"] .icon-sun {
  display: block;
}

:root[data-theme="dark"] .icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun {
    display: block;
  }
  :root:not([data-theme="light"]) .icon-moon {
    display: none;
  }
}

/* ——— Панель режимів ——— */

.page {
  flex: 1;
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 4px max(16px, env(safe-area-inset-right)) 12px max(16px, env(safe-area-inset-left));
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 14px;
}

.tabs {
  display: inline-flex;
  padding: 4px;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 13px;
}

.tab {
  padding: 7px 16px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}

.tab:hover {
  color: var(--text);
}

.tab[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.langs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.select {
  height: 40px;
  min-width: 0;
  max-width: 220px;
  padding: 0 34px 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8984' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E")
    no-repeat right 10px center / 16px;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.select:hover {
  border-color: var(--border-strong);
}

.notice {
  margin: 0 0 14px;
  padding: 10px 14px;
  border: 1px solid var(--notice-border);
  border-radius: 12px;
  background: var(--notice-bg);
  color: var(--notice-text);
  font-size: 14px;
}

/* ——— Робоча область ——— */

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.panel:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow), 0 0 0 3px var(--accent-soft);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  padding: 10px 16px 0;
}

.panel-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.counter {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.counter.is-over {
  color: var(--danger);
  font-weight: 600;
}

.field {
  display: block;
  width: 100%;
  margin: 0;
  padding: 10px 16px 16px;
  border: 0;
  background: transparent;
  font-size: var(--text-size);
  line-height: 1.65;
  overflow-wrap: anywhere;
}

textarea.field {
  min-height: 36vh;
  resize: vertical;
}

textarea.field::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

.field:focus,
.field:focus-visible {
  outline: none;
}

.output {
  min-height: 28vh;
  white-space: pre-wrap;
  overflow: auto;
}

.output .placeholder {
  margin: 0;
  color: var(--muted);
  white-space: normal;
}

.output mark {
  background: var(--mark-bg);
  color: inherit;
  border-radius: 3px;
  padding: 0 1px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.output ins,
.output del {
  border-radius: 3px;
  padding: 0 2px;
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.output ins {
  background: var(--ins-bg);
  color: var(--ins-text);
  text-decoration: none;
}

.output del {
  background: var(--del-bg);
  color: var(--del-text);
  text-decoration: line-through;
  text-decoration-thickness: 1.5px;
}

.skeleton {
  display: block;
  height: 14px;
  margin: 8px 0 14px;
  border-radius: 7px;
  background: linear-gradient(90deg, var(--skeleton) 25%, var(--skeleton-shine) 50%, var(--skeleton) 75%);
  background-size: 300% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: 0 0;
  }
}

.view-switch {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.view-switch button {
  padding: 3px 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.view-switch button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.panel-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}

.hint {
  flex: 1;
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}

kbd {
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  font: inherit;
  font-size: 11px;
}

.status {
  flex: 1;
  min-width: 0;
  margin: 0 0 0 4px;
  font-size: 14px;
  color: var(--muted);
}

.status[data-kind="error"] {
  color: var(--danger);
}

.status[data-kind="ok"] {
  color: var(--ok);
}

.status[data-kind="busy"]::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
  animation: pulse 1s ease-in-out infinite alternate;
}

@keyframes pulse {
  from {
    opacity: 0.25;
  }
  to {
    opacity: 1;
  }
}

/* ——— Кнопки ——— */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  min-width: 168px;
  border-color: transparent;
  background: var(--accent);
  color: var(--accent-text);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary.is-busy {
  border-color: var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
}

.btn.is-done {
  border-color: var(--ok);
  color: var(--ok);
}

.spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.is-busy .spinner {
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ——— Підвал ——— */

.footer {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 6px max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.footer p {
  margin: 0;
}

/* ——— Телефон ——— */

@media (max-width: 599px) {
  .brand-text span {
    display: none;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .tabs {
    display: flex;
  }

  .tab {
    flex: 1;
  }

  .langs {
    width: 100%;
  }

  .select {
    flex: 1;
    max-width: none;
  }

  .hint {
    display: none;
  }

  #submit {
    flex: 1;
    min-width: 0;
  }

  #clear span {
    display: none;
  }

  #clear {
    padding: 0 12px;
  }
}

@media (hover: none) {
  .hint {
    visibility: hidden;
  }
}

/* ——— Комп'ютер: дві колонки поруч, висота на весь екран ——— */

@media (min-width: 900px) {
  .workspace {
    grid-template-columns: 1fr 1fr;
  }

  .panel {
    height: clamp(420px, calc(100dvh - 250px), 1100px);
  }

  textarea.field,
  .output {
    flex: 1;
    min-height: 0;
    resize: none;
    overflow: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition: none !important;
  }
}
