/* Reset + shared components (buttons, fields, sliders, menus, dialogs, toasts). */
*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none;
  background: #14100D; color: var(--fg);
  font: 400 15px/1.45 var(--font-ui);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.noscript { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: #EDE4D3; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }

/* ---------- Icons ---------- */
.i { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }
.i--fill { fill: currentColor; stroke: none; }
.is-on > .i, [aria-pressed="true"].fav > .i { fill: currentColor; }

/* ---------- Buttons ---------- */
.icon-btn {
  display: inline-grid; place-items: center; flex: none;
  width: var(--touch); height: var(--touch); border-radius: var(--r-md);
  color: var(--fg-dim);
  transition: background var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn:active { background: var(--active); transform: scale(.96); }
.icon-btn--sm { width: 36px; height: 36px; }
.icon-btn--sm .i { width: 18px; height: 18px; }
.icon-btn[aria-pressed="true"], .icon-btn[aria-expanded="true"] { color: var(--accent); }
@media (pointer: coarse) { .icon-btn--sm { width: var(--touch); height: var(--touch); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--touch); padding: 0 18px; border-radius: var(--r-pill);
  border: 1px solid var(--line-strong); color: var(--fg);
  font-size: 14px; font-weight: 500; letter-spacing: .01em; white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), transform var(--t-fast), opacity var(--t-fast);
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); background: var(--active); }
.btn--primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn--primary:hover { background: var(--accent); filter: brightness(1.07); }
.btn--danger { border-color: color-mix(in srgb, var(--c-danger) 70%, transparent); color: color-mix(in srgb, var(--c-danger) 70%, var(--fg)); }
.btn--danger:hover { background: color-mix(in srgb, var(--c-danger) 16%, transparent); }
.btn--sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn:disabled, .icon-btn:disabled { opacity: .4; cursor: not-allowed; }
.btn[data-loading="true"] { opacity: .7; pointer-events: none; }
.btn[data-loading="true"]::before { content: ""; width: 12px; height: 12px; border-radius: 50%; border: 1.5px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@media (pointer: coarse) { .btn--sm { min-height: var(--touch); } }
.link-btn { color: var(--accent); font-size: 13px; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent); min-height: 32px; }
.link-btn:hover { text-decoration-color: currentColor; }
.row { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }

/* ---------- Fields ---------- */
.field, .select, input[type="text"].field {
  width: 100%; min-height: var(--touch); padding: 0 14px;
  background: var(--field); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  color: var(--fg); font-size: 16px; /* 16px avoids iOS zoom on focus */
}
.field::placeholder { color: var(--fg-faint); }
.field:focus-visible, .select:focus-visible { outline-offset: 0; border-color: var(--focus); }
.field[aria-invalid="true"] { border-color: var(--c-danger); }
.select { appearance: none; padding-right: 34px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.select option { color: #222; background: #fff; }
.select--quiet { width: auto; min-height: 34px; padding-left: 8px; background-color: transparent; border-color: transparent; font-size: 13px; color: var(--fg-dim); }
.select--quiet:hover { background-color: var(--hover); }
.label { display: block; font: 500 11px/1.2 var(--font-label); letter-spacing: .12em; text-transform: uppercase; color: var(--fg-dim); }
.hint { font-size: 12.500px; line-height: 1.5; color: var(--fg-dim); }
.error-text { font-size: 13px; color: color-mix(in srgb, var(--c-danger) 75%, var(--fg)); }

/* Slider */
.slider { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; }
.slider output { font: 400 12px var(--font-label); color: var(--fg-dim); min-width: 3.5ch; text-align: right; }
.slider .label { grid-column: 1 / 2; }
.slider input { grid-column: 1 / -1; }
input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 30px; margin: 0; background: transparent; cursor: pointer; touch-action: pan-y;
}
input[type="range"]::-webkit-slider-runnable-track { height: 3px; border-radius: 3px; background: var(--line-strong); }
input[type="range"]::-moz-range-track { height: 3px; border-radius: 3px; background: var(--line-strong); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; margin-top: -8.500px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #F4E3B8, #B8955A 60%, #7A5C2C); border: 1px solid rgba(0,0,0,.35);
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
input[type="range"]::-moz-range-thumb {
  width: 19px; height: 19px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #F4E3B8, #B8955A 60%, #7A5C2C); border: 1px solid rgba(0,0,0,.35);
}
input[type="range"]:disabled { opacity: .4; cursor: not-allowed; }

/* Switch (a real checkbox) */
.switch { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); min-height: var(--touch); cursor: pointer; font-size: 14px; }
.switch > span:first-child { display: grid; gap: 2px; }
.switch small { color: var(--fg-dim); font-size: 12.500px; line-height: 1.4; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch i { flex: none; width: 42px; height: 24px; border-radius: 12px; background: var(--line-strong); position: relative; transition: background var(--t-med); }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--fg); transition: transform var(--t-med) var(--ease-spring); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); background: var(--accent-ink); }
.switch input:focus-visible + i { outline: 2px solid var(--focus); outline-offset: 2px; }
.switch input:disabled + i { opacity: .4; }

/* Segmented control (radio group) */
.seg { display: flex; padding: 3px; gap: 2px; border-radius: var(--r-md); background: var(--field); border: 1px solid var(--line); }
.seg label { flex: 1; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span { display: grid; place-items: center; min-height: 36px; padding: 0 8px; border-radius: 7px; font-size: 13px; color: var(--fg-dim); transition: background var(--t-fast), color var(--t-fast); text-align: center; }
.seg input:checked + span { background: var(--panel-raise); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.seg input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }
@media (pointer: coarse) { .seg span { min-height: 40px; } }

/* ---------- Menu (popover list) ---------- */
.menu {
  position: fixed; z-index: var(--z-menu); min-width: 208px; max-width: min(300px, calc(100vw - 16px)); max-height: min(70dvh, 520px); overflow: auto;
  padding: 6px; border-radius: var(--r-md); background: var(--panel-raise); border: 1px solid var(--line-strong); box-shadow: var(--shadow-panel);
  animation: pop var(--t-fast) var(--ease-out);
}
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0 10px; border-radius: 7px; text-align: left; font-size: 14px; color: var(--fg); }
.menu button:hover, .menu button:focus-visible { background: var(--hover); outline: none; }
.menu button .i { width: 18px; height: 18px; color: var(--fg-dim); }
.menu button.is-danger { color: color-mix(in srgb, var(--c-danger) 72%, var(--fg)); }
.menu button[aria-checked="true"]::after { content: "✓"; margin-left: auto; color: var(--accent); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 5px 4px; }
.menu__label { padding: 8px 10px 4px; font: 500 10.500px var(--font-label); letter-spacing: .12em; text-transform: uppercase; color: var(--fg-faint); }
@media (pointer: coarse) { .menu button { min-height: var(--touch); } }

/* ---------- Dialog ---------- */
dialog.dialog {
  width: min(480px, calc(100vw - 28px)); max-height: calc(100dvh - 28px); padding: 0; border: 1px solid var(--line-strong); border-radius: var(--r-lg);
  background: var(--panel-2); color: var(--fg); box-shadow: var(--shadow-panel); overflow: auto;
}
dialog.dialog[open] { animation: rise var(--t-med) var(--ease-out); }
dialog.dialog::backdrop { background: rgba(10, 8, 6, .58); animation: fade var(--t-med); }
.dialog__body { padding: 26px 26px 8px; display: grid; gap: 14px; }
.dialog__title { font: 500 26px/1.15 var(--font-display); letter-spacing: .005em; }
.dialog__text { color: var(--fg-dim); font-size: 14.500px; line-height: 1.55; }
.dialog__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; padding: 16px 26px 24px; }
.dialog--wide { width: min(560px, calc(100vw - 28px)); }
.choice-list { display: grid; gap: 8px; }
.choice { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; align-items: start; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: var(--r-md); cursor: pointer; text-align: left; transition: background var(--t-fast), border-color var(--t-fast); width: 100%; }
.choice:hover { background: var(--hover); }
.choice b { font-weight: 600; font-size: 14.500px; }
.choice small { grid-column: 2; color: var(--fg-dim); font-size: 13px; line-height: 1.45; }
.choice .i { grid-row: span 2; margin-top: 1px; color: var(--accent); }
.choice input { grid-row: span 2; margin: 4px 0 0; accent-color: var(--accent); width: 16px; height: 16px; }
.choice:has(input:checked) { border-color: var(--accent); background: var(--hover); }
@media (max-width: 520px) {
  dialog.dialog { margin-bottom: max(14px, var(--safe-b)); }
  .dialog__actions .btn { flex: 1 1 auto; }
}

/* ---------- Toasts ---------- */
.toasts { position: fixed; z-index: var(--z-toast); left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; width: max-content; max-width: calc(100vw - 24px); pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 12px; max-width: 100%;
  padding: 10px 16px; border-radius: var(--r-pill); font-size: 13.500px;
  background: #2A211B; color: #EDE4D3; border: 1px solid rgba(237,228,211,.18); box-shadow: 0 10px 30px rgba(0,0,0,.45);
  animation: rise var(--t-med) var(--ease-out);
}
.toast[data-kind="error"] { border-color: #B4563F; }
.toast .i { width: 17px; height: 17px; }
.toast[data-kind="error"] .i { color: #E08B74; }
.toast[data-kind="success"] .i { color: #B9C7A0; }
.toast button { color: #F2C88D; font-weight: 600; min-height: 30px; padding: 0 4px; white-space: nowrap; }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity var(--t-med), transform var(--t-med); }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.97) translateY(-3px); } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
