/* ============================================================================
   shell.css — top of the page: brand bar, mode switcher, board console, HUD,
   legend, toasts and the How-to-play card. Pairs with shell.js.
   Load LAST (after styles.css, reverse.css, the inline <style>, mobile.css and
   draft.css) so equal-specificity rules here win.
   ============================================================================ */

:root {
  --mode-daily: #e03f30;
  --mode-draft: #e7ba6b;
  --mode-reverse: #4bb5ab;
  --shell-panel: rgba(13, 12, 15, 0.86);
  --shell-line: rgba(204, 48, 34, 0.22);
  --shell-line-soft: rgba(255, 255, 255, 0.06);
}

/* Shared reset so the site-wide pink pill button style doesn't leak into the
   new controls. :where() keeps it at zero specificity. */
:where(.topbar, .mode-tabs, .console, .toast-stack, .howto) button {
  all: unset;
  box-sizing: border-box;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
:where(.topbar, .mode-tabs, .console, .howto) button:focus-visible {
  outline: 2px solid #f09189;
  outline-offset: 2px;
}

/* ── Brand bar ──────────────────────────────────────────────────────────── */
.app-header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 0 0.9rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}
.brand h1 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2.1rem);
  line-height: 1;
  white-space: nowrap;
}
.brand-tag {
  display: block;
  margin-top: 0.3rem;
  font-family: var(--pixel-font);
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

/* ── Logo: the route sign ─────────────────────────────────────────────────
   A location banner in the spirit of the DS games: a framed plate with a
   small landscape inside (sky, hills, trees, drifting clouds), standing in
   tall grass with a few flowers. Art: brand/*.png, made by
   scripts/gen_brand_art.py on a 164 x 40 pixel canvas.
   --k is the pixel scale: 2 on desktop, 4/3 on phones, so every art pixel
   lands on whole screen pixels. Motion: a gust of wind rolls through the
   grass (16 frames, ~100ms each) and the clouds drift. The grass tapers off
   at both ends, so the sign has no hard rectangular edge. All motion stops
   for prefers-reduced-motion. */
.route-sign {
  --k: 2;
  position: relative;
  display: block;
  width: calc(164px * var(--k));
  height: calc(40px * var(--k));
  margin: 0;
}
.rs-grass {
  position: absolute;
  inset: 0;
  background-repeat: no-repeat;
  background-size: 100% 1600%;               /* sixteen frames stacked */
  image-rendering: pixelated;
  pointer-events: none;
  animation: rs-wind 1.6s steps(16, jump-none) infinite;
}
.rs-back  { z-index: 0; background-image: var(--px-sign-back); }
.rs-front { z-index: 3; background-image: var(--px-sign-front); }
.rs-plate {
  position: absolute;
  z-index: 1;
  left: calc(17px * var(--k));
  top: calc(3px * var(--k));
  width: calc(130px * var(--k));
  height: calc(28px * var(--k));
  background: var(--px-sign-plate) 0 0 / 100% 100% no-repeat;
  image-rendering: pixelated;
}
.rs-sky {                                    /* the clouds, inside the frame */
  position: absolute;
  left: calc(4px * var(--k));
  top: calc(4px * var(--k));
  width: calc(122px * var(--k));
  height: calc(12px * var(--k));
  overflow: hidden;
  background: var(--px-sign-clouds) 0 0 / calc(122px * var(--k)) 100% repeat-x;
  image-rendering: pixelated;
  animation: rs-clouds 60s steps(122) infinite;
}
.rs-name {
  position: absolute;
  z-index: 2;
  left: calc(26px * var(--k));
  top: calc(3px * var(--k));
  height: calc(28px * var(--k));
  display: flex;
  align-items: center;
  font-family: "Pixelify Sans", "Silkscreen", monospace;
  font-weight: 600;
  font-size: calc(15px * var(--k));
  line-height: 1;
  letter-spacing: 0.02em;
  color: #23262b;
  -webkit-text-fill-color: currentColor;
  text-transform: none;
  text-shadow: 0 calc(1px * var(--k)) 0 #f4f8f6;
}
@keyframes rs-wind {
  from { background-position: 0 0; }
  to   { background-position: 0 100%; }
}
@keyframes rs-clouds {
  to { background-position: calc(-122px * var(--k)) 0; }
}
.route-sign + .brand-tag { margin-top: 0.15rem; }

/* A single tuft, used beside headings (the welcome card). */
.brand-mark {
  flex: none;
  width: 32px;                           /* 16x13 art at 2x */
  height: 26px;
  background: var(--px-grass) center / contain no-repeat;
  image-rendering: pixelated;
}

.topbar-actions { display: flex; gap: 0.5rem; flex: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-width: 42px;
  min-height: 42px;
  padding: 0 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--shell-line);
  background: rgba(204, 48, 34, 0.06);
  color: var(--ink);
  font-family: var(--pixel-font);
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}
.icon-btn:hover { background: rgba(204, 48, 34, 0.16); border-color: rgba(237, 121, 110, 0.5); transform: translateY(-1px); }
.icon-btn-glyph { font-size: 1rem; line-height: 1; }
.icon-btn-q {
  font-family: var(--pixel-font);
  font-size: 0.95rem;
  font-weight: 700;
  color: #f09189;
}

/* ── Mode switcher ──────────────────────────────────────────────────────── */
nav.mode-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0 0 0.8rem;
  padding: 0;
  border: 0;
}
nav.mode-tabs .mode-tab {
  --tab: var(--mode-daily);
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-height: 62px;
  padding: 0.65rem 0.9rem;
  border-radius: 14px;
  border: 1px solid var(--shell-line-soft);
  background: var(--shell-panel);
  color: var(--ink);
  overflow: hidden;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}
nav.mode-tabs .mode-tab[data-mode="draft"] { --tab: var(--mode-draft); }
nav.mode-tabs .mode-tab[data-mode="reverse"] { --tab: var(--mode-reverse); }

nav.mode-tabs .mode-tab:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--tab) 45%, transparent);
}
/* The lit "cartridge": accent edge, soft glow and an LED bar along the bottom. */
nav.mode-tabs .mode-tab.active {
  border-color: color-mix(in srgb, var(--tab) 70%, transparent);
  background:
    var(--shell-panel);
  box-shadow: none;
  color: var(--ink);
}
nav.mode-tabs .mode-tab::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--tab);
  opacity: 0;
  transform: scaleX(0.4);
  transition: opacity 180ms ease, transform 220ms ease;
}
nav.mode-tabs .mode-tab.active::after { opacity: 1; transform: none; box-shadow: none; }

.mt-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  font-size: 1.15rem;
  background: color-mix(in srgb, var(--tab) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--tab) 30%, transparent);
}
.mt-text { display: grid; gap: 0.25rem; min-width: 0; text-align: left; }
.mt-name {
  font-family: var(--pixel-font);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.mode-tab.active .mt-name { color: #ffffff; }
.mt-sub {
  font-family: var(--pixel-font);
  font-size: 0.56rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Console: board label + actions + HUD in one panel ─────────────────── */
.console {
  margin: 0 0 0.75rem;
  border: 1px solid var(--shell-line);
  border-radius: 14px;
  background: var(--shell-panel);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
body.draft-building .console { display: none; }

.console .mode-context { margin: 0; }
.console .ctx-panel {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0;
  padding: 0.6rem 0.8rem;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.console .ctx-panel.hidden { display: none; }

/* Raw seed/meta text and the inline status line are replaced by the chip and
   toasts (shell.js keeps them updated from these elements). */
.console .ctx-meta,
.console .ctx-msg { display: none; }

.board-chip {
  order: -1;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin-right: auto;
  min-height: 34px;
  padding: 0 0.75rem;
  border-radius: 999px;
  font-family: var(--pixel-font);
  font-size: 0.66rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--shell-line-soft);
  white-space: nowrap;
}
.board-chip::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chip-dot, var(--mode-daily));
  box-shadow: none;
}
.ctx-panel[data-ctx="draft"] .board-chip { --chip-dot: var(--mode-draft); }
.ctx-panel[data-ctx="reverse"] .board-chip { --chip-dot: var(--mode-reverse); }
.board-chip:empty { display: none; }

.console .ctx-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 36px;
  padding: 0 0.85rem;
  border-radius: 10px;
  border: 1px solid var(--shell-line);
  background: rgba(204, 48, 34, 0.07);
  color: var(--ink);
  font-family: var(--pixel-font);
  font-size: 0.64rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  transition: background 140ms ease, border-color 140ms ease;
}
.console .ctx-btn:hover { background: rgba(204, 48, 34, 0.18); border-color: rgba(237, 121, 110, 0.5); transform: none; color: var(--ink); }

/* HUD sits under the context row, divided by a hairline. */
.console .hud-strip {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0 1rem;
  margin: 0;
  padding: 0.6rem 0.9rem;
  border: 0;
  border-top: 1px solid var(--shell-line-soft);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.console .hud-divider { display: none; }
.console .hud-section.hud-mid { padding: 0; gap: 0.65rem; justify-content: stretch; order: 0; flex-basis: auto; border: 0; }
.console .hud-bar { height: 8px; min-width: 0; }
.console .hud-score { font-size: 0.85rem; }
.console .hud-tag { font-size: 0.56rem; }

/* ── Legend: one quiet line under the board ─────────────────────────────── */
section.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.35rem 1rem;
  margin: 0.7rem 0 0;
  font-family: var(--pixel-font);
  font-size: 0.58rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
section.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
section.legend .dot { width: 7px; height: 7px; }
body.draft-building section.legend { display: none; }

/* Reverse progress gets the same console look. */
.rev-progress {
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--shell-line);
  border-radius: 14px;
  background: var(--shell-panel);
  margin-bottom: 0.75rem;
}
#revProgressText { font-family: var(--pixel-font); font-size: 0.8rem; }
#revProgressBar { background: #409c93; box-shadow: none; }

/* ── Toasts (replace the old inline status line) ───────────────────────── */
.toast-stack {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 9000;
  display: grid;
  gap: 0.4rem;
  width: min(92vw, 30rem);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.95rem;
  border-radius: 12px;
  font-family: var(--pixel-font);
  font-size: 0.64rem;
  line-height: 1.5;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: rgba(15, 14, 18, 0.96);
  border: 1px solid var(--toast, rgba(255, 255, 255, 0.14));
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.55);
  animation: toast-in 260ms cubic-bezier(.2, .7, .3, 1) both;
  cursor: pointer;
}
.toast::before {
  content: "";
  flex: none;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--toast, #a5a3b0);
}
.toast.out { animation: toast-out 200ms ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

/* ── How to play ────────────────────────────────────────────────────────── */
dialog.howto {
  width: min(92vw, 34rem);
  max-height: 88vh;
  margin: auto;
  padding: 0;
  border: 1px solid rgba(237, 121, 110, 0.35);
  border-radius: 18px;
  background:
    #0f0e12;
  color: var(--ink);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
  overflow: auto;
}
dialog.howto::backdrop { background: rgba(6, 5, 7, 0.72);  }
dialog.howto[open] { animation: toast-in 280ms cubic-bezier(.2, .7, .3, 1) both; }

.howto-inner { padding: 1.4rem 1.3rem 1.2rem; }
.howto-head { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 0.9rem; }
.howto-head .brand-mark { width: 32px; height: 26px; }
.howto h2 {
  margin: 0;
  font-family: var(--pixel-font);
  font-size: 1.05rem;
  line-height: 1.3;
  color: #ffffff;
}
.howto-lede {
  margin: 0 0 1rem;
  font-size: 0.86rem;
  line-height: 1.6;
  color: #d7cfc5;
}
.howto-modes { display: grid; gap: 0.5rem; margin-bottom: 1rem; }
.howto-mode {
  --tab: var(--mode-daily);
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 0.75rem;
  align-items: start;
  padding: 0.7rem 0.8rem;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, var(--tab) 30%, transparent);
  background: color-mix(in srgb, var(--tab) 7%, transparent);
}
.howto-mode[data-m="draft"] { --tab: var(--mode-draft); }
.howto-mode[data-m="reverse"] { --tab: var(--mode-reverse); }
.howto-mode .mt-icon { width: 34px; height: 34px; font-size: 1rem; }
.howto-mode strong {
  display: block;
  margin-bottom: 0.2rem;
  font-family: var(--pixel-font);
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #ffffff;
}
.howto-mode p { margin: 0; font-size: 0.8rem; line-height: 1.5; color: #c8beb0; }
.howto-tips {
  display: grid;
  gap: 0.35rem;
  margin: 0 0 1.1rem;
  padding: 0;
  list-style: none;
  font-size: 0.8rem;
  line-height: 1.5;
  color: #c8beb0;
}
.howto-tips li { display: flex; gap: 0.5rem; }
.howto-go {
  display: block;
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  text-align: center;
  line-height: 48px;
  font-family: var(--pixel-font);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #ffffff;
  background: #e03f30;
  box-shadow: none;
}
.howto-go:hover { filter: brightness(1.1); }

/* ── Header badge fitting (shell.js shrinks long labels to fit) ─────────── */
:is(.row-head, .rule-head, .m-chip, .m-rule) :is(.rule-badge, .type-badge-custom) {
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}
:is(.row-head, .rule-head, .m-chip, .m-rule) .rule-badge.text.fit-break { overflow-wrap: anywhere; }

/* Reverse tiles' Pokémon names match the pixel names on the forward board. */
.rev-cell .rev-cell-name {
  font-family: var(--pixel-font);
  font-size: 0.6rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 1.3;
}

/* ── Phones ─────────────────────────────────────────────────────────────── */
@media (max-width: 767px) {
  .app-header.topbar { margin-bottom: 0.7rem; gap: 0.6rem; }
  .brand { gap: 0.55rem; }
  .brand h1 { font-size: clamp(1.05rem, 5.4vw, 1.4rem); }
  .route-sign { --k: 1.3333; }             /* 219 x 53; 4 device px per art px on 3x phones */
  .brand-tag { display: none; }
  .icon-btn { padding: 0; width: 40px; min-width: 40px; min-height: 40px; }
  .icon-btn-label { display: none; }

  nav.mode-tabs { gap: 0.4rem; margin-bottom: 0.6rem; }
  nav.mode-tabs .mode-tab {
    flex-direction: column;
    justify-content: center;
    gap: 0.3rem;
    min-height: 64px;
    padding: 0.5rem 0.25rem 0.6rem;
    border-radius: 12px;
  }
  nav.mode-tabs .mode-tab::after { left: 22%; right: 22%; }
  .mt-icon { width: auto; height: auto; background: none; border: 0; font-size: 1.15rem; }
  .mt-text { text-align: center; }
  .mt-name { font-size: 0.64rem; }
  .mt-sub { display: none; }

  .console { margin-bottom: 0.6rem; border-radius: 12px; }
  .console .ctx-panel { padding: 0.5rem 0.6rem; gap: 0.4rem; }
  .board-chip { min-height: 32px; font-size: 0.58rem; padding: 0 0.6rem; }
  .console .ctx-btn { min-height: 34px; padding: 0 0.65rem; font-size: 0.56rem; }
  .console .ctx-panel[data-ctx="reverse"] .board-chip { flex-basis: 100%; justify-content: center; margin-right: 0; }
  .console .ctx-panel[data-ctx="reverse"] .ctx-btn { flex: 1 1 0; justify-content: center; padding: 0 0.3rem; }

  /* HUD on two rows: lives | hints, then progress full width. The text tags
     made the single row collide on phones, so only the essentials stay. */
  .console .hud-strip {
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "lives hints" "prog prog";
    gap: 0.45rem 0.5rem;
    padding: 0.5rem 0.7rem 0.6rem;
  }
  .console .hud-strip > .hud-section:first-child { grid-area: lives; }
  .console .hud-strip > .hud-section:last-child { grid-area: hints; justify-content: flex-end; }
  .console .hud-section.hud-mid { grid-area: prog; }
  .console .hud-mid .hud-tag { display: none; }
  .console .hud-score { font-size: 0.74rem; }
  .console .pip-life, .console .pip-hint { font-size: 1.1rem; }
  .console .hud-tag { font-size: 0.5rem; letter-spacing: 0.1em; }

  section.legend { font-size: 0.52rem; gap: 0.3rem 0.8rem; }

  .rev-progress { padding: 0.5rem 0.7rem; border-radius: 12px; margin-bottom: 0.6rem; }

  .toast { font-size: 0.6rem; }
  .howto-inner { padding: 1.2rem 1rem 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  .route-sign, .rs-grass, .rs-sky, .toast, dialog.howto[open] { animation: none !important; }
}
