:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #16131c;
  --muted: #6e6a78;
  --hair: rgba(22, 19, 28, 0.08);
  --primary: #ff2d87;
  --primary-ink: #ffffff;
  --seg: #e6e5ec;
  --stage-bg: #0c0a12;
  --shadow: 0 10px 40px rgba(20, 10, 40, 0.08);
  --radius: 24px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0c12;
    --card: #1c1a24;
    --text: #f4f2f8;
    --muted: #9c98a8;
    --hair: rgba(255, 255, 255, 0.08);
    --seg: #2a2733;
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0d0c12;
  --card: #1c1a24;
  --text: #f4f2f8;
  --muted: #9c98a8;
  --hair: rgba(255, 255, 255, 0.08);
  --seg: #2a2733;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* the usable screen; phones that flip the page sideways swap these (see css/mobile.css) */
:root { --app-h: 100dvh; --app-w: 100dvw; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Plus Jakarta Sans", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button { font: inherit; color: inherit; border: 0; cursor: pointer; background: none; }

.app {
  height: var(--app-h);
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr);
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
  gap: 12px;
}

/* ------------------------------------------------------------ top bar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

.title-block { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.game-title { margin: 0; font-size: clamp(20px, 2.6vw, 30px); font-weight: 800; letter-spacing: -0.02em; white-space: nowrap; }
.room-name { color: var(--muted); font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.score-pill {
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: var(--card);
  border-radius: 999px;
  padding: 8px 16px;
  box-shadow: var(--shadow);
  transition: transform 0.25s;
}
.score-pill #scoreValue { font-size: 22px; font-weight: 800; }
.score-pill .of { color: var(--muted); font-size: 13px; font-weight: 600; }
.score-pill.bump { animation: bump 0.5s; }
@keyframes bump { 40% { transform: scale(1.12); } }

/* ------------------------------------------------------------ stage */
.stage-wrap { display: grid; place-items: center; min-height: 0; }

.stage {
  position: relative;
  width: min(100%, calc((var(--app-h) - 190px) * 1280 / 672));
  max-width: 1280px;
  aspect-ratio: 1280 / 672;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--stage-bg);
  box-shadow: 0 24px 80px rgba(10, 0, 30, 0.25);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#game { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.overlay { position: absolute; inset: 0; pointer-events: none; }
.overlay > * { pointer-events: auto; }

.hover-label {
  position: absolute;
  left: 0; top: 0;
  pointer-events: none !important;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(20, 16, 30, 0.72);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.hover-label.show { opacity: 1; }

.popover {
  position: absolute;
  left: 0; top: 0;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  box-shadow: 0 20px 60px rgba(10, 0, 30, 0.35);
  opacity: 0;
  scale: 0.92;
  transition: opacity 0.16s, scale 0.16s;
}
.popover.show { opacity: 1; scale: 1; }
.popover-title { font-weight: 800; font-size: 16px; padding: 0 6px 10px; }
.verb-row { display: flex; gap: 6px; }
.verb {
  width: 68px;
  display: grid;
  justify-items: center;
  gap: 4px;
  padding: 8px 4px 6px;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  transition: background 0.15s;
}
.verb:hover { background: var(--seg); color: var(--text); }
.verb-icon svg { width: 34px; height: 34px; display: block; }

/* ------------------------------------------------------------ narration */
.narration-host {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: grid;
  justify-items: center;
  padding: 0 16px 16px;
  pointer-events: none;
}
.narration {
  pointer-events: auto;
  grid-area: 1 / 1;
  width: min(640px, 100%);
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 22px 14px;
  box-shadow: 0 20px 60px rgba(10, 0, 30, 0.4);
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.2s, transform 0.2s;
}
.narration.show { opacity: 1; transform: none; }
.narration.has-portrait { display: grid; grid-template-columns: 76px 1fr; column-gap: 16px; align-items: start; }
.narration.has-portrait > :not(.portrait) { grid-column: 2; }
.narration.has-portrait .speaker { justify-self: start; }
.portrait {
  grid-row: 1 / span 4;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  object-fit: cover;
  object-position: top;
  background: linear-gradient(160deg, #ffe3f0, #e5dbff);
}
.speaker.hint { background: #fff3bf; color: #a35d00; }
.speaker {
  display: inline-block;
  background: #ffe3f0;
  color: #c2185b;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 8px;
}
.narration-text { margin: 0; font-size: clamp(15px, 1.6vw, 18px); line-height: 1.5; font-weight: 500; }
.tap-hint { margin-top: 10px; font-size: 12px; color: var(--muted); font-weight: 600; text-align: right; }
.choice-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.choice {
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--seg);
  font-weight: 700;
  font-size: 15px;
}
.choice:hover { background: color-mix(in srgb, var(--primary) 16%, var(--seg)); }
.choice.primary, .primary-btn { background: var(--primary); color: var(--primary-ink); }

.pending-chip {
  position: absolute;
  top: 14px;
  left: 50%;
  translate: -50% -60px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px 16px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  transition: translate 0.25s;
}
.pending-chip.show { translate: -50% 0; }
.pending-chip button { width: 28px; height: 28px; border-radius: 50%; background: rgba(255,255,255,0.25); color: #fff; font-size: 18px; line-height: 1; }

.toasts { position: absolute; top: 14px; right: 14px; display: grid; gap: 8px; pointer-events: none; }
.loading {
  position: absolute;
  left: 50%;
  top: 50%;
  translate: -50% -50%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  color: #fff;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  z-index: 3;
}
.loading.show { opacity: 1; }
.loading i { width: 18px; height: 18px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.25); border-top-color: var(--primary); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(20, 16, 30, 0.78);
  backdrop-filter: blur(12px);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  animation: toastIn 0.25s;
  transition: opacity 0.4s;
}
.toast.out { opacity: 0; }
@keyframes toastIn { from { transform: translateY(-8px); opacity: 0; } }

/* ------------------------------------------------------------ dock */
.dock {
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: 999px;
  padding: 8px 10px;
  box-shadow: var(--shadow);
}
.segmented { display: flex; background: var(--seg); border-radius: 999px; padding: 4px; }
.seg { padding: 8px 16px; border-radius: 999px; font-weight: 700; font-size: 14px; color: var(--muted); transition: background 0.2s, color 0.2s; }
.seg.active { background: var(--card); color: var(--text); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08); }
.dock-centre {
  width: 64px; height: 64px;
  margin: -18px 0;
  border-radius: 50%;
  background: var(--primary);
  display: grid;
  place-items: center;
  box-shadow: 0 10px 30px color-mix(in srgb, var(--primary) 45%, transparent);
  transition: transform 0.15s;
}
.dock-centre:hover { transform: translateY(-2px); }
.dock-centre svg { width: 34px; height: 34px; }
.dock-btn { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; background: var(--seg); }
.dock-btn svg { width: 28px; height: 28px; }

/* ------------------------------------------------------------ inventory sheet */
.scrim { position: fixed; inset: 0; background: rgba(10, 6, 20, 0.4); opacity: 0; pointer-events: none; transition: opacity 0.25s; }
.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  width: min(560px, 100%);
  translate: -50% 105%;
  background: var(--card);
  border-radius: 28px 28px 0 0;
  padding: 10px 20px max(24px, env(safe-area-inset-bottom));
  transition: translate 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
  box-shadow: 0 -10px 50px rgba(0, 0, 0, 0.25);
}
.sheet.open { translate: -50% 0; }
.sheet.open ~ .scrim, .scrim:has(+ .sheet.open) { opacity: 1; pointer-events: auto; }
.grabber { width: 40px; height: 5px; border-radius: 3px; background: var(--hair); margin: 0 auto 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-size: 26px; font-weight: 800; }
.money-pill { background: #d3f9d8; color: #2b8a3e; border-radius: 999px; padding: 6px 14px; font-weight: 800; }
.inv-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
.item-tile {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 16px 8px 12px;
  border-radius: 20px;
  background: var(--tile);
  color: #241c2c;
  font-weight: 700;
  font-size: 13px;
  transition: transform 0.15s;
}
.item-tile:hover { transform: translateY(-2px); }
.item-icon svg { width: 44px; height: 44px; }
.item-desc { margin: 16px 4px 0; line-height: 1.5; font-weight: 500; }

/* ------------------------------------------------------------ title screen */
.title-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background:
    radial-gradient(60% 60% at 70% 20%, rgba(255, 45, 135, 0.35), transparent 70%),
    radial-gradient(50% 60% at 20% 80%, rgba(80, 80, 255, 0.35), transparent 70%),
    #0c0a14;
  transition: opacity 0.5s;
  z-index: 10;
}
.title-screen.hide { opacity: 0; pointer-events: none; }
.title-card { text-align: center; color: #fff; max-width: 620px; }
.title-art { width: min(240px, 50vw); height: auto; filter: drop-shadow(0 20px 40px rgba(255, 45, 135, 0.35)); margin-bottom: 8px; }
.kicker { color: rgba(255, 255, 255, 0.6); font-weight: 600; margin: 0 0 6px; }
.big-title {
  margin: 0;
  font-size: clamp(44px, 9vw, 92px);
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.03em;
  background: linear-gradient(180deg, #fff 30%, #ffc2dd);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 40px rgba(255, 45, 135, 0.45);
}
.sub-title { font-size: clamp(18px, 2.6vw, 26px); font-weight: 600; color: #ff8fc0; margin: 10px 0 30px; }
.primary-btn { padding: 16px 34px; border-radius: 999px; font-weight: 800; font-size: 18px; box-shadow: 0 14px 40px rgba(255, 45, 135, 0.45); }
.title-note { color: rgba(255, 255, 255, 0.55); font-weight: 500; margin-top: 18px; }

@media (max-width: 640px) {
  .room-name { display: none; }
  .game-title { font-size: 18px; overflow: hidden; text-overflow: ellipsis; }
  .title-block { flex: 1 1 auto; }
  .pills { flex: none; }
  .money-chip { padding: 6px 12px; font-size: 15px; }
  .score-pill { padding: 6px 12px; }
  .score-pill #scoreValue { font-size: 19px; }
  .seg { padding: 6px 10px; font-size: 12px; }
  .dock { gap: 8px; max-width: 100%; }
  .dock-btn { width: 40px; height: 40px; }
  .stage { width: 100%; }
  .verb { width: 58px; }
  .inv-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .item-tile { padding: 12px 6px 10px; font-size: 12px; }
}

@media (max-width: 640px) {
  .narration.has-portrait { grid-template-columns: 52px 1fr; column-gap: 12px; }
  .narration.has-portrait > .choice-row { grid-column: 1 / -1; }
  .portrait { width: 52px; height: 52px; }
  .narration { padding: 16px 16px 12px; max-height: calc(var(--app-h) - 200px); overflow-y: auto; }
  .choice { padding: 9px 14px; font-size: 14px; }
}

@media (max-width: 700px), (max-aspect-ratio: 1/1) {
  .narration-host {
    position: fixed;
    left: 0; right: 0;
    bottom: calc(96px + env(safe-area-inset-bottom));
    padding: 0 16px;
    z-index: 5;
  }
}
