/* Базовые стили: палитра (переменные ставит js/theme.js), типографика, кнопки, формы, меню, диалоги, тосты. */
:root {
  --bg: #F6F2EA; --card: #FFFFFF; --fg: #23201A; --muted: #6E675B; --outline: #E2DBCB;
  --accent: #4F46E5; --on-accent: #FFFFFF; --accent-soft: #E3E1EF;
  --danger: #B3261E; --warn-bg: #FFF1D6; --warn-fg: #7A4B00; --warn-border: #E8C27A;
  --shadow: 0 4px 18px rgba(30, 24, 10, .14);
  --gutter: 16px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans KR", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans CJK KR", "Noto Sans CJK SC", "Noto Sans CJK JP", "PingFang SC", "Hiragino Sans", "Yu Gothic", sans-serif;
  --font-ko: "Noto Sans KR", "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans CJK KR", "Nanum Gothic", system-ui, sans-serif;
  color-scheme: light;
}
:root[data-kind="dark"] {
  --danger: #F2B8B5; --warn-bg: #3A2C10; --warn-fg: #F4D58D; --warn-border: #6B5320;
  --shadow: 0 4px 18px rgba(0, 0, 0, .5); color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--fg); font: 16px/1.45 var(--font);
  overflow: hidden; overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.ko { font-family: var(--font-ko); }

.root { position: fixed; inset: 0; height: 100dvh; display: flex; flex-direction: column; }

/* ---- кнопки ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 22px;
  border: 0; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 16px;
  transition: transform .12s ease, opacity .2s ease, background-color .2s ease;
}
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.is-ghost { background: transparent; color: var(--accent); }
.btn.is-soft { background: var(--accent-soft); color: var(--fg); }
.btn.is-danger { background: transparent; color: var(--danger); }
.btn.is-block { width: 100%; }

.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 44px; height: 44px; flex: none; padding: 0;
  border: 0; border-radius: 50%; background: transparent; color: var(--muted);
  transition: background-color .15s ease, transform .12s ease, color .15s ease;
}
.icon-btn:hover:not(:disabled) { background: var(--accent-soft); }
.icon-btn:active:not(:disabled) { transform: scale(.92); }
.icon-btn.is-accent { color: var(--accent); background: var(--accent-soft); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.icon-btn svg, .btn svg { width: 24px; height: 24px; flex: none; display: block; }
.icon-btn.is-sm svg { width: 20px; height: 20px; }

/* ---- формы ---- */
.field { display: grid; gap: 6px; }
.field > label { font-size: 14px; font-weight: 600; color: var(--muted); }
.input {
  width: 100%; min-height: 50px; padding: 0 16px; border: 1.5px solid var(--outline); border-radius: 14px;
  background: var(--card); color: var(--fg); font-size: 16px; /* 16px: iOS не приближает страницу при фокусе */
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input-row { position: relative; }
.input-row .input { padding-right: 52px; }
.input-row .icon-btn { position: absolute; right: 3px; top: 3px; width: 44px; height: 44px; }
.error-text { color: var(--danger); font-size: 14px; font-weight: 500; min-height: 1.4em; }

.pill {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 999px;
  border: 1.5px solid var(--outline); background: transparent; font-weight: 500; font-size: 15px;
}
.pill[aria-pressed="true"], .pill[aria-checked="true"] { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }

.range { width: 100%; height: 32px; accent-color: var(--accent); margin: 0; }

/* ---- меню (всплывающее) ---- */
.menu {
  position: fixed; z-index: 60; color: var(--fg); min-width: 200px; max-width: min(320px, calc(100vw - 24px)); padding: 6px;
  background: var(--card); border-radius: 18px; box-shadow: var(--shadow); border: 1px solid var(--outline);
  animation: pop .14s ease-out; transform-origin: var(--ox, 50%) var(--oy, 0%);
}
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 46px; padding: 0 14px; text-align: left;
  background: transparent; border: 0; border-radius: 12px; font-size: 16px;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--accent-soft); outline: none; }
.menu-item[aria-checked="true"] { color: var(--accent); font-weight: 700; }
.menu-item.is-danger { color: var(--danger); }
.menu-item.is-dim { color: var(--muted); font-weight: 400; }
.menu-item.is-dim[aria-checked="true"] { color: var(--accent); font-weight: 700; }
.menu-item svg { width: 22px; height: 22px; flex: none; color: var(--muted); }
.menu-label { padding: 10px 14px 4px; font-size: 13px; color: var(--muted); }
.menu-sep { height: 1px; margin: 4px 8px; background: var(--outline); }
.menu.speed-menu { min-width: 0; width: 76px; padding: 4px; display: grid; gap: 2px; border-radius: 22px; }
.speed-menu .menu-item { justify-content: center; min-height: 40px; padding: 0; border-radius: 999px; }
.speed-menu .menu-item[aria-checked="true"] { background: var(--accent); color: var(--on-accent); }
@keyframes pop { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }

/* ---- диалоги и листы ---- */
dialog { border: 0; padding: 0; background: transparent; color: var(--fg); max-width: none; max-height: none; }
dialog::backdrop { background: rgba(20, 16, 6, .5); animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; } }
.dialog-card {
  width: min(440px, calc(100vw - 32px)); padding: 22px 22px 14px; background: var(--card); border-radius: 26px;
  box-shadow: var(--shadow); display: grid; gap: 12px; animation: pop .18s ease-out;
}
.dialog-card h2 { font-size: 20px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 4px; flex-wrap: wrap; }
dialog.sheet { margin: auto auto 0; width: 100%; }
dialog.sheet .sheet-card {
  width: min(560px, 100%); margin: 0 auto; max-height: 90dvh; overflow: auto; background: var(--card);
  border-radius: 28px 28px 0 0; padding: 12px 20px calc(18px + var(--safe-b)); display: grid; gap: 14px;
  box-shadow: var(--shadow); animation: slide-up .24s ease-out;
}
.sheet-grab { width: 44px; height: 5px; border-radius: 3px; background: var(--outline); margin: 0 auto 4px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 22px; }
@keyframes slide-up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) {
  dialog.sheet { margin: auto; }
  dialog.sheet .sheet-card { border-radius: 28px; padding-bottom: 20px; }
}

/* ---- тосты ---- */
.toasts {
  position: fixed; inset: auto 0 calc(16px + var(--safe-b)) 0; z-index: 90; display: grid; justify-items: center; gap: 8px;
  padding: 0 var(--gutter); margin: 0; border: 0; width: auto; height: auto; background: transparent; overflow: visible; pointer-events: none;
}
.toasts:empty { display: none; }
.toast {
  max-width: min(560px, 100%); padding: 12px 18px; border-radius: 16px; background: var(--fg); color: var(--bg);
  box-shadow: var(--shadow); font-size: 15px; animation: pop .18s ease-out; pointer-events: auto;
}
.toast.is-error { background: var(--danger); color: #fff; }
:root[data-kind="dark"] .toast.is-error { color: #1b1b1b; }

/* ---- флаги ---- */
.flag { display: inline-block; width: 36px; height: 24px; border-radius: 4px; overflow: hidden; flex: none; box-shadow: 0 0 0 1px rgba(0, 0, 0, .18); line-height: 0; }
.flag svg { width: 100%; height: 100%; display: block; }
.flag.is-lg { width: 60px; height: 40px; border-radius: 6px; }
.flag.is-sm { width: 27px; height: 18px; border-radius: 3px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
