/* ==========================================================================
   Windrose Rehber — app shell styles
   1 Tokens · 2 Reset · 3 Layout · 4 Appbar & omnibox · 5 Nav
   6 Typography · 7 Cards · 8 Buttons & chips · 9 Segmented · 10 List rows
   11 Progress ring · 12 Badges · 13 Sheet · 14 Toast · 15 Forms
   16 Utilities · 17 Motion & focus
   ========================================================================== */

/* --- 1 Tokens (SPEC §6) -------------------------------------------------- */
:root {
  color-scheme: dark;

  --bg: #0e1319;
  --surface: #151c25;
  --surface-2: #1b2430;
  --line: #263241;
  --text: #ece6da;
  --muted: #98a3b0;
  --accent: #f0a441;
  --accent-2: #4fb6c8;

  --accent-soft: rgba(240, 164, 65, .14);
  --accent-2-soft: rgba(79, 182, 200, .14);
  --danger: #e0644f;
  --ok: #57c46c;

  --biome-jungle: #3f9d5a;
  --biome-highlands: #c9a24a;
  --biome-swamp: #8b5cc7;
  --biome-ashlands: #d2553f;

  --rar-common: #b9c1cb;
  --rar-uncommon: #57c46c;
  --rar-rare: #4f9be8;
  --rar-epic: #b06ce8;
  --rar-legendary: #f0a441;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fs-xs: .75rem;
  --fs-sm: .8125rem;
  --fs-md: .9375rem;
  --fs-lg: 1.0625rem;
  --fs-xl: 1.25rem;
  --fs-2xl: 1.5rem;
  --lh: 1.5;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --r-pill: 999px;

  --tap: 44px;
  --rail-w: 232px;
  --tabbar-h: 58px;
  --dur: 160ms;

  --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);

  --z-nav: 30;
  --z-appbar: 40;
  --z-sheet: 60;
  --z-toast: 70;
}

/* --- 2 Reset ------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: var(--lh);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }
:where(ul, ol).plain { list-style: none; margin: 0; padding: 0; }
.icon { flex: none; }

.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--accent); color: #17202a; padding: var(--sp-3) var(--sp-4);
  border-radius: 0 0 var(--r) 0; font-weight: 600;
}
.skip-link:focus { left: 0; }

/* --- 3 Layout ------------------------------------------------------------ */
.shell { display: block; }
.view {
  display: block;
  padding: var(--sp-4);
  padding-left: max(var(--sp-4), var(--safe-l));
  padding-right: max(var(--sp-4), var(--safe-r));
  padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--sp-6));
  max-width: 900px;
  margin: 0 auto;
  outline: none;
}
/* Grid helpers declare one explicit track. The implicit `auto` track takes its
   minimum from the row's min-content, so a single long nowrap name (.truncate)
   stretches the track past the viewport and the page scrolls sideways.
   minmax(0, 1fr) caps the track at the container, so .truncate can ellipse. */
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-4); }
.stack-sm { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-2); }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.wrap { flex-wrap: wrap; }

/* --- 4 Appbar & omnibox -------------------------------------------------- */
.appbar {
  position: sticky; top: 0; z-index: var(--z-appbar);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--line);
  padding: calc(var(--safe-t) + var(--sp-2)) max(var(--sp-3), var(--safe-r)) var(--sp-2) max(var(--sp-3), var(--safe-l));
}
.appbar-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.brand {
  display: flex; align-items: center; gap: var(--sp-2);
  color: var(--text); font-weight: 600; font-size: var(--fs-lg);
  min-height: var(--tap); padding-right: var(--sp-2);
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--accent); display: inline-flex; }
.appbar-gear { color: var(--muted); }

.omnibox { position: relative; margin-top: var(--sp-2); }
.omnibox-field {
  display: flex; align-items: center; gap: var(--sp-2);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-pill); padding: 0 var(--sp-3);
  min-height: var(--tap);
}
.omnibox-field:focus-within { border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-2-soft); }
.omnibox-icon { color: var(--muted); flex: none; display: inline-flex; }
.omnibox-input {
  flex: 1 1 auto; min-width: 0; background: none; border: 0; outline: none;
  padding: var(--sp-2) 0; font-size: var(--fs-md);
}
.omnibox-input::-webkit-search-cancel-button { display: none; }
.omnibox-clear { flex: none; color: var(--muted); width: var(--tap); height: var(--tap); min-height: var(--tap); }

.omnibox-results {
  position: absolute; left: 0; right: 0; top: calc(100% + var(--sp-2));
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  max-height: min(60vh, 420px); overflow-y: auto; overscroll-behavior: contain;
  box-shadow: 0 12px 28px rgba(0, 0, 0, .45);
  padding: var(--sp-2);
}
.omnibox-group { padding: var(--sp-2) var(--sp-2) var(--sp-1); font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.omnibox-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-2); border-radius: var(--r-sm);
  min-height: var(--tap); cursor: pointer; color: var(--text);
}
.omnibox-item:hover { text-decoration: none; background: var(--surface-2); }
.omnibox-item[aria-selected="true"] { background: var(--accent-soft); outline: 1px solid var(--accent); }
.omnibox-item > span:first-child { color: var(--muted); flex: none; display: inline-flex; }
.omnibox-item .row-main { flex: 1 1 auto; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr); }
.omnibox-item .sub { color: var(--muted); font-size: var(--fs-sm); }
.omnibox-empty { padding: var(--sp-4); color: var(--muted); text-align: center; }

/* --- 5 Nav (tab bar < 900px, left rail >= 900px) ------------------------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-nav);
  display: flex; justify-content: space-around; align-items: stretch;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-top: 1px solid var(--line);
  padding: 0 max(var(--sp-1), var(--safe-l)) var(--safe-b) max(var(--sp-1), var(--safe-r));
}
.nav-link {
  flex: 1 1 0; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tabbar-h); padding: var(--sp-1) 2px;
  color: var(--muted); font-size: var(--fs-xs); font-weight: 500; text-align: center;
}
.nav-link:hover { text-decoration: none; color: var(--text); }
.nav-link .nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.nav-link[aria-current="page"] { color: var(--accent); }
.nav-rail-only { display: none; }

@media (min-width: 900px) {
  .shell {
    display: grid;
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
    gap: var(--sp-5);
    max-width: 1180px; margin: 0 auto;
    padding: 0 max(var(--sp-4), var(--safe-r)) 0 max(var(--sp-4), var(--safe-l));
  }
  .nav {
    position: sticky; top: calc(var(--safe-t) + 116px); align-self: start;
    inset: auto; display: grid; gap: 2px;
    background: none; backdrop-filter: none; border-top: 0;
    padding: var(--sp-4) 0;
  }
  .nav-link {
    flex-direction: row; justify-content: flex-start; gap: var(--sp-3);
    min-height: var(--tap); padding: 0 var(--sp-3);
    border-radius: var(--r-sm); font-size: var(--fs-md); text-align: left;
  }
  .nav-link[aria-current="page"] { background: var(--accent-soft); }
  .nav-rail-only { display: flex; }
  .view { padding: var(--sp-5) 0 var(--sp-6); max-width: 780px; margin: 0; }
  .appbar-gear { display: none; }
  .omnibox { max-width: 560px; }
  .appbar { padding-bottom: var(--sp-3); }
}

/* --- 6 Typography -------------------------------------------------------- */
h1, h2, h3, h4 { font-weight: 600; margin: 0; line-height: 1.3; }
h1 { font-size: var(--fs-2xl); }
h2 { font-size: var(--fs-xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: var(--fs-sm); }
.xsmall { font-size: var(--fs-xs); }
.num { font-variant-numeric: tabular-nums; }
.eyebrow { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.page-title { margin-bottom: var(--sp-1); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.prose p + p { margin-top: var(--sp-3); }
.prose ul { margin: var(--sp-2) 0 0; padding-left: 1.15em; }
.prose li + li { margin-top: var(--sp-1); }

/* --- 7 Cards ------------------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
}
.card.pad { padding: var(--sp-4); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.card-link { display: block; color: inherit; }
.card-link:hover { text-decoration: none; border-color: var(--accent); }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
.tile {
  display: flex; flex-direction: column; gap: var(--sp-2);
  padding: var(--sp-4); min-height: 96px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); color: inherit;
}
.tile:hover { text-decoration: none; border-color: var(--accent); background: var(--surface-2); }
.tile-icon { color: var(--accent); }
.tile-title { font-weight: 600; }
.banner {
  display: flex; gap: var(--sp-3); align-items: flex-start;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r);
  padding: var(--sp-3); color: var(--muted); font-size: var(--fs-sm);
}
.banner .banner-icon { color: var(--accent-2); flex: none; }

/* --- 8 Buttons & chips --------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--tap); padding: 0 var(--sp-4);
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  font-size: var(--fs-md); font-weight: 600; cursor: pointer;
  transition: background var(--dur) ease, border-color var(--dur) ease;
}
.btn:hover { text-decoration: none; background: var(--line); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #1a1207; }
.btn-primary:hover { background: #f5b45f; background: color-mix(in srgb, var(--accent) 88%, #fff); }
.btn-ghost { background: none; border-color: transparent; font-weight: 500; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--line)); background: none; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); }
.btn-block { width: 100%; }
.btn-sm { min-height: var(--tap); padding: 0 var(--sp-3); font-size: var(--fs-sm); }
.btn-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: var(--tap); height: var(--tap); min-height: var(--tap);
  background: none; border: 0; border-radius: var(--r-pill); cursor: pointer; color: inherit;
}
.iconbtn:hover { background: var(--surface-2); text-decoration: none; }

.chip {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  min-height: var(--tap); padding: 0 var(--sp-3);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-pill);
  font-size: var(--fs-sm); cursor: pointer; color: inherit;
}
.chip:hover { text-decoration: none; border-color: var(--accent-2); }
.chip[aria-pressed="true"], .chip.is-on { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--sp-2); }

/* --- 9 Segmented control ------------------------------------------------- */
.seg {
  display: inline-flex; width: 100%; padding: 3px; gap: 3px;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm);
}
.seg-btn {
  flex: 1 1 0; min-width: 0; min-height: var(--tap); padding: 0 var(--sp-2);
  background: none; border: 0; border-radius: 6px; cursor: pointer;
  font-size: var(--fs-sm); font-weight: 600; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.seg-btn:hover { color: var(--text); }
.seg-btn[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.35); }

/* --- 10 List rows -------------------------------------------------------- */
.list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }  /* 0-min track, see .stack */
.list > * + * { border-top: 1px solid var(--line); }
.row-item {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: var(--tap); padding: var(--sp-3) var(--sp-4); color: inherit;
}
.row-item:hover { text-decoration: none; background: var(--surface-2); }
.row-item .row-main { flex: 1 1 auto; min-width: 0; }
.row-item .row-sub { color: var(--muted); font-size: var(--fs-sm); }
.row-item .row-end { flex: none; color: var(--muted); display: inline-flex; align-items: center; gap: var(--sp-2); }
.ent-icon {
  width: 32px; height: 32px; flex: none; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--line);
  object-fit: contain; padding: 2px; color: var(--muted);
}
.ent-icon-ph { display: inline-flex; align-items: center; justify-content: center; }

/* --- 11 Progress ring ---------------------------------------------------- */
.ring { display: inline-grid; place-items: center; position: relative; flex: none; }
.ring svg { transform: rotate(-90deg); }
.ring-track { stroke: var(--line); fill: none; }
.ring-bar { stroke: var(--accent); fill: none; stroke-linecap: round; transition: stroke-dasharray var(--dur) ease; }
.ring-bar.is-done { stroke: var(--ok); }
.ring-label {
  position: absolute; font-size: var(--fs-xs); font-weight: 600;
  font-variant-numeric: tabular-nums; color: var(--muted);
}
.bar { height: 6px; border-radius: var(--r-pill); background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }

/* --- 12 Badges ----------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: var(--sp-1);
  padding: 2px var(--sp-2); border-radius: var(--r-pill);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.6;
  background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
}
.badge-accent { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.badge-ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.rar { color: var(--rar-common); border-color: color-mix(in srgb, var(--rar-common) 35%, var(--line)); }
.rar-common { --rc: var(--rar-common); }
.rar-uncommon { --rc: var(--rar-uncommon); }
.rar-rare { --rc: var(--rar-rare); }
.rar-epic { --rc: var(--rar-epic); }
.rar-legendary { --rc: var(--rar-legendary); }
.rar[class*="rar-"] { color: var(--rc, var(--rar-common)); border-color: color-mix(in srgb, var(--rc, var(--rar-common)) 35%, var(--line)); }
.biome-jungle { --bc: var(--biome-jungle); }
.biome-highlands { --bc: var(--biome-highlands); }
.biome-swamp { --bc: var(--biome-swamp); }
.biome-ashlands { --bc: var(--biome-ashlands); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bc, var(--muted)); flex: none; }

/* --- 13 Bottom sheet ----------------------------------------------------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: var(--z-sheet);
  background: rgba(6, 9, 13, .62); display: flex; align-items: flex-end; justify-content: center;
  animation: fade var(--dur) ease;
}
.sheet {
  width: 100%; max-width: 640px; max-height: 88vh;
  background: var(--surface); border: 1px solid var(--line); border-bottom: 0;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  display: flex; flex-direction: column; overflow: hidden;
  padding-bottom: var(--safe-b);
  animation: sheet-up 220ms cubic-bezier(.2, .8, .2, 1);
  touch-action: pan-y;
}
.sheet-grab { padding: var(--sp-2) 0 var(--sp-1); display: grid; place-items: center; cursor: grab; flex: none; }
.sheet-grab::before { content: ""; width: 42px; height: 4px; border-radius: var(--r-pill); background: var(--line); }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: 0 var(--sp-3) var(--sp-2) var(--sp-4); flex: none;
}
.sheet-body { padding: var(--sp-2) var(--sp-4) var(--sp-5); overflow-y: auto; overscroll-behavior: contain; }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (min-width: 900px) {
  .sheet-backdrop { align-items: center; }
  .sheet { max-width: 560px; border-radius: var(--r-lg); border-bottom: 1px solid var(--line); max-height: 80vh; animation: fade var(--dur) ease; }
  .sheet-grab { display: none; }
}

/* --- 14 Toasts ----------------------------------------------------------- */
.toasts {
  position: fixed; z-index: var(--z-toast);
  left: max(var(--sp-3), var(--safe-l)); right: max(var(--sp-3), var(--safe-r));
  bottom: calc(var(--tabbar-h) + var(--safe-b) + var(--sp-3));
  display: grid; gap: var(--sp-2); justify-items: center; pointer-events: none;
}
.toast {
  max-width: 460px; width: fit-content;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r);
  padding: var(--sp-3) var(--sp-4); font-size: var(--fs-sm);
  box-shadow: 0 8px 22px rgba(0, 0, 0, .45);
  animation: fade var(--dur) ease;
}
.toast-error { border-color: color-mix(in srgb, var(--danger) 55%, var(--line)); }
@media (min-width: 900px) { .toasts { bottom: calc(var(--safe-b) + var(--sp-4)); } }

/* --- 15 Forms ------------------------------------------------------------ */
label { display: block; }
.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--sp-2); }
.field > .label { font-weight: 600; font-size: var(--fs-sm); }
input[type="text"], input[type="search"], input[type="number"], textarea, select {
  width: 100%; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: var(--sp-3); min-height: var(--tap); outline: none;
}
textarea { min-height: 140px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: var(--fs-sm); }
input:focus, textarea:focus, select:focus { border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-2-soft); }

.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  min-height: var(--tap); padding: var(--sp-3) var(--sp-4); cursor: pointer;
}
.switch-row .switch-text { flex: 1 1 auto; min-width: 0; }
.switch {
  position: relative; flex: none; width: 48px; height: 28px; border-radius: var(--r-pill);
  background: var(--line); border: 1px solid var(--line); transition: background var(--dur) ease;
  cursor: pointer; padding: 0; appearance: none; -webkit-appearance: none;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 22px; height: 22px;
  border-radius: 50%; background: var(--muted); transition: transform var(--dur) ease, background var(--dur) ease;
}
.switch[aria-checked="true"] { background: var(--accent-soft); border-color: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(20px); background: var(--accent); }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* --- 16 Utilities -------------------------------------------------------- */
.empty { display: grid; gap: var(--sp-3); justify-items: center; text-align: center; padding: var(--sp-6) var(--sp-4); color: var(--muted); }
.empty-icon { color: var(--line); }
.empty h3 { color: var(--text); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.divider { height: 1px; background: var(--line); border: 0; margin: 0; }
.scroll-x { overflow-x: auto; overscroll-behavior-x: contain; }
.pad { padding: var(--sp-4); }
.mt-2 { margin-top: var(--sp-2); }
.mt-4 { margin-top: var(--sp-4); }

/* --- 17 Motion & focus --------------------------------------------------- */
:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
.nav-link:focus-visible, .omnibox-item:focus-visible { outline-offset: -2px; }

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