/* The Deep Blue app shell (docs/redesign/CANVAS.md, item 2).
   Phones (< 1024 px): one header row (≤ 60 px), the quest strip, the current screen, and a bottom
   nav Coach · Journey · Play · Money · Me with Play raised in the centre. The chats are a drawer.
   Desktop (≥ 1024 px): sidebar 260 px | the current screen (chat ≤ 760 px) | right panel 340 px. */
:root {
  --hud-h: 60px;
  --nav-h: 64px;
  --side-col: 260px;
  --right-col: 340px;
}

/* ---------- Header (phones) ---------- */
.hud {
  position: fixed;
  z-index: 45;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--hud-h);
  padding: 0 var(--space-4);
  border-bottom: 1px solid var(--divider);
  background: var(--pane);
}
.hud-title {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.hud-avatar {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  cursor: pointer;
  transition: transform var(--motion-fast) var(--ease-out);
}
.hud-avatar:active { transform: scale(var(--press)); }
/* Finn sits inside the gold level ring; the ring fills with progress to the next level. */
.hud-ring {
  --p: 0;
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: conic-gradient(var(--gold) calc(var(--p) * 1%), var(--surface-soft) 0);
}
.hud-ring::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 50%;
  background: var(--navy);
}
.hud-ring .finn-slot,
.hud-ring .finn-host {
  position: relative;
  z-index: 1;
  display: block;
  width: 34px;
  height: 34px;
}
.hud-id {
  display: grid;
  min-width: 0;
  margin: 0 auto 0 0;
  line-height: 1.15;
}
.hud-id strong { font-size: var(--fs-16); font-weight: 800; letter-spacing: var(--tracking-head); color: var(--text-1); }
.hud-id > span { font-size: var(--fs-12); font-weight: 600; color: var(--text-2); white-space: nowrap; }
.hud-id .num { font-weight: 700; color: var(--gold); }

/* Streak and XP pills (header on phones, chat header on desktop). */
.hud-stat {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  height: 32px;
  margin: 0;
  padding: 0 var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  background: var(--surface-soft);
  font-size: var(--fs-13);
  white-space: nowrap;
}
.hud-stat.pill-streak { color: var(--text-1); }
.hud-stat.pill-streak .icon { color: var(--play-to); }
.hud-stat.pill-xp { border-color: color-mix(in srgb, var(--gold) 40%, transparent); background: var(--gold-bg); color: var(--gold); }

/* ---------- Quest strip (phones, Coach) ---------- */
.quest-strip {
  position: fixed;
  z-index: 44;
  top: var(--hud-h);
  left: 0;
  right: 0;
  display: none;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--pane);
  border-bottom: 1px solid var(--divider);
}
body[data-view="coach"] .quest-strip { display: grid; }
.quest-tile {
  display: grid;
  align-content: space-between;
  gap: var(--space-1);
  min-height: 56px;
  min-width: 0;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--r-12);
  background: var(--surface-soft);
  color: var(--text-1);
  font: 600 var(--fs-12)/1.25 var(--font-ui);
  text-align: left;
  cursor: pointer;
  transition: transform var(--motion-fast) var(--ease-out), border-color var(--motion-fast) var(--ease-out);
}
.quest-tile:hover { transform: translateY(var(--lift)); }
.quest-tile:active { transform: scale(var(--press)); }
/* R3-12: one line, so the strip keeps its 72 px and never covers the chat's first message. */
.quest-tile-title { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.quest-tile-xp { display: inline-flex; align-items: center; gap: var(--space-1); font-size: var(--fs-11); color: var(--text-2); }
.quest-tile.is-done { border-color: color-mix(in srgb, var(--mint) 40%, transparent); background: var(--mint-bg); cursor: default; }
.quest-tile.is-done .quest-tile-xp { color: var(--mint); }
.quest-tile.is-game { border-color: color-mix(in srgb, var(--play-to) 55%, transparent); background: color-mix(in srgb, var(--play-to) 12%, transparent); }
.quest-tile.is-game .quest-tile-xp { color: var(--play-from); }
.quest-strip-empty { grid-column: 1 / -1; margin: 0; color: var(--text-2); font-size: var(--fs-13); }

/* ---------- Bottom nav (phones): Coach · Journey · Play · Money · Me ---------- */
.app-nav {
  position: fixed;
  z-index: 60;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: end;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding: 0 var(--space-2) env(safe-area-inset-bottom);
  border-top: 1px solid var(--divider);
  background: var(--pane);
}
.app-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  height: var(--nav-h);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text-3);
  font: 600 var(--fs-11)/1 var(--font-ui);
  cursor: pointer;
  transition: color var(--motion-fast) var(--ease-out);
}
.app-nav button[aria-current="page"] { color: var(--text-1); }
.app-nav button[aria-current="page"] .icon { color: var(--link); }
/* Play: the one orange in the nav, raised above the bar. Games and Play only (tokens.css). */
.app-nav .nav-play {
  align-self: start;
  justify-self: center;
  width: 56px;
  height: 56px;
  margin-top: -18px;
  border-radius: 50%;
  background: var(--play);
  box-shadow: var(--play-glow);
  color: var(--on-bright);
  font-weight: 800;
}
.app-nav .nav-play span { display: none; }
.app-nav .nav-play .icon { fill: var(--on-bright); stroke: var(--on-bright); }
.app-nav .nav-play:active { transform: scale(var(--press)); }
.app-nav .nav-play:disabled { opacity: 0.5; cursor: default; }

/* ---------- Screens and the chat on phones ---------- */
.arcade-shell, .game-column { display: contents; }
.right-panel { display: none; }
.today-screen {
  display: none;
  position: fixed;
  z-index: 40;
  top: var(--hud-h);
  left: 0;
  right: 0;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
  overflow-x: hidden;
  overflow-y: auto;
  background: transparent;
}
body[data-view="journey"] #mapScreen,
body[data-view="money"] #moneyScreen,
body[data-view="me"] #meScreen { display: block; }
body:not([data-view="coach"]) .app-layout { display: none; }
.app-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  margin-top: calc(var(--hud-h) + 72px);   /* header + quest strip */
  height: calc(100dvh - var(--hud-h) - 72px - var(--nav-h) - env(safe-area-inset-bottom));
  background: transparent;
}
.app-layout > .main { height: 100%; }
.chat-head { display: none; }
.money-inner { padding-top: var(--space-4); }

/* The chats drawer (phones): from the left, under the header so Finn stays tappable to close it. */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed !important;
    z-index: var(--z-sheet);
    top: var(--hud-h) !important;
    left: 0;
    width: min(300px, 86vw);
    height: calc(100dvh - var(--hud-h)) !important;
    max-height: calc(100dvh - var(--hud-h)) !important;
    padding: var(--space-4);
    border-right: 1px solid var(--divider);
    background: var(--surface-solid);
    transform: translateX(-105%);
    transition: transform var(--motion) var(--ease-out);
  }
  body.sidebar-open .sidebar { transform: none !important; }
  .sidebar-backdrop {
    position: fixed;
    z-index: 55;
    inset: var(--hud-h) 0 0 0;
    background: var(--scrim);
  }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .sidebar .side-views,
  .sidebar .today-game { display: none; }  /* the bottom nav and the centre Play cover these on phones */
}

/* ---------- Desktop: sidebar 260 | centre ≤ 760 | right panel 340 ---------- */
@media (min-width: 1024px) {
  .hud, .quest-strip, .app-nav { display: none !important; }
  body[data-view] .arcade-shell {
    display: grid;
    grid-template-columns: var(--side-col) minmax(0, 1fr) var(--right-col);
    width: 100%;
    height: 100dvh;
  }
  /* Sidebar: logo, nav, Today's game, chats. */
  .sidebar {
    position: relative !important;
    grid-column: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    width: auto;
    height: 100dvh !important;
    max-height: none !important;
    padding: var(--space-5) var(--space-4);
    overflow-y: auto;
    border-right: 1px solid var(--divider);
    background: var(--pane);
    transform: none !important;
    visibility: visible !important;
  }
  .sidebar .sidebar-close,
  .sidebar .pane-resize,
  .sidebar-backdrop { display: none !important; }
  .sidebar-head { margin: 0; }
  /* The centre column: the current screen, the chat at most 760 px wide. */
  body[data-view] .game-column {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100dvh;
    overflow: hidden;
  }
  .today-screen {
    position: relative;
    inset: auto;
    z-index: var(--z-base);
    flex: 1 1 auto;
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
  }
  body[data-view="coach"] .app-layout {
    display: grid;
    flex: 1 1 auto;
    width: 100%;
    max-width: 760px;
    height: 100dvh;
    margin: 0 auto;
  }
  .app-layout > .main { display: flex; flex-direction: column; min-height: 0; }
  /* Slim chat header: the chat's title, streak and XP. */
  .chat-head {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex: none;
    height: 56px;
    padding: 0 var(--space-4);
    border-bottom: 1px solid var(--divider);
  }
  .chat-title {
    flex: 1;
    min-width: 0;
    margin: 0;
    overflow: hidden;
    font-size: var(--fs-15);
    font-weight: 700;
    letter-spacing: 0;
    color: var(--text-1);
    white-space: nowrap;
    text-overflow: ellipsis;
  }
  /* Right panel: level, world, quests, money (cards in shell.css, Deep Blue item 4). */
  .right-panel {
    grid-column: 3;
    display: block;
    height: 100dvh;
    padding: var(--space-5) var(--space-4);
    overflow-y: auto;
    border-left: 1px solid var(--divider);
    background: var(--pane);
  }
  .right-panel .rail { padding: 0; background: transparent; border: 0; }
  /* Journey, Money and Me use the centre column's width, not a phone's. */
  .game-column .today-inner { max-width: 720px; padding-inline: var(--space-6); }
}

/* Sidebar nav and Today's game (desktop sidebar). */
.side-views { display: grid; gap: var(--space-1); }
.side-views button {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 44px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--r-12);
  background: transparent;
  color: var(--text-2);
  font: 600 var(--fs-15)/1 var(--font-ui);
  text-align: left;
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out), color var(--motion-fast) var(--ease-out);
}
.side-views button:hover { background: var(--surface-soft); color: var(--text-1); }
.side-views button[aria-current="page"] { background: var(--blue-bg); color: var(--text-1); }
.side-views button[aria-current="page"] .icon { color: var(--link); }
.today-game {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--border-card);
  border-radius: var(--r-18);
  background: var(--surface-soft);
}
.today-game-label { margin: 0; font-size: var(--fs-11); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-2); }
.today-game-row { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.today-game-thumb { display: block; width: 56px; height: 56px; flex: none; overflow: hidden; border-radius: var(--r-12); }
.today-game-thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.today-game-text { display: grid; min-width: 0; }
.today-game-text strong { overflow: hidden; font-size: var(--fs-15); font-weight: 700; color: var(--text-1); white-space: nowrap; text-overflow: ellipsis; }
.today-game-text small { font-size: var(--fs-12); color: var(--text-2); }
.today-game-empty { margin: 0; font-size: var(--fs-13); color: var(--text-2); }
/* The orange Play button: games and Play only. */
.btn-play {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  padding: 0 var(--space-4);
  border: 0;
  border-radius: var(--r-12);
  background: var(--play);
  box-shadow: var(--play-glow);
  color: var(--on-bright);
  font: 800 var(--fs-14)/1 var(--font-ui);
  cursor: pointer;
  transition: transform var(--motion-fast) var(--ease-out);
}
.btn-play .icon { fill: var(--on-bright); stroke: var(--on-bright); }
.btn-play:hover { transform: translateY(var(--lift)); }
.btn-play:active { transform: scale(var(--press)); }

/* The legacy "Your profile" box gives way to Money (item 5 removes it). */
.sidebar .profile-card { display: none; }
/* Quests live in the strip (phones) and the right panel (desktop), not as a chat message. Today still
   renders the card's data; it just isn't shown twice. */
#questCardMsg { display: none !important; }
/* The sidebar header is the logo alone. */
.sidebar .beta, .sidebar .sidebar-meta { display: none; }

@media (prefers-reduced-motion: reduce) {
  .quest-tile, .btn-play, .hud-avatar, .side-views button, .sidebar { transition: none; }
}
