:root {
  --bg-deep: #0e182b;
  --bg-slate: #1c2f4a;
  --glass-surface: rgba(18, 30, 52, 0.80);
  --glass-border: rgba(245, 196, 94, 0.36);
  --gold-primary: #f5c45e;
  --gold-bright: #ffe194;
  --cream-text: #f9f3e6;
  --muted-text: #bfd0e6;
  --catrina-pink: #e84a8a;
  --leo-blue: #3b82f6;
  --jet-orange: #f97316;
  --skye-amber: #f59e0b;
  --turquoise-sluice: #2ec4b6;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --vvw: 100vw;
  --vvh: 100vh;
}

*, *::before, *::after {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--bg-deep);
  color: var(--cream-text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "PingFang TC", "Hiragino Sans", sans-serif;
  overflow: hidden;
}

/* Dynamic viewport units per modern-web-guidance responsive-design */
.jumi-stage-shell {
  position: relative;
  width: 100vw;
  width: 100dvw;
  width: var(--vvw, 100dvw);
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  height: var(--vvh, 100dvh);
  overflow: hidden;
  background: radial-gradient(circle at 50% 25%, #233b5e 0%, #0e182b 78%);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* Title & Hero Select Overlay with @container responsive sizing */
.title-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: max(8px, var(--safe-t, 0px), env(safe-area-inset-top, 0px)) max(14px, var(--safe-r, 0px), env(safe-area-inset-right, 0px)) max(8px, var(--safe-b, 0px), env(safe-area-inset-bottom, 0px)) max(14px, var(--safe-l, 0px), env(safe-area-inset-left, 0px));
  background:
    linear-gradient(180deg, rgba(10, 18, 34, 0.30) 0%, rgba(8, 15, 28, 0.62) 100%),
    url("./assets/bg-title-keyart.webp") center center / cover no-repeat;
  container-type: inline-size;
  touch-action: none;
}

.title-overlay[hidden],
.hud-touch-layer[hidden],
.bilingual-toast[hidden],
.victory-banner[hidden],
.portrait-guard[hidden],
.btn-back-to-hub[hidden] {
  display: none !important;
}

.title-card-container {
  width: min(920px, 96cqi);
  max-width: calc(100vw - max(16px, var(--safe-l, 0px)) - max(16px, var(--safe-r, 0px)));
  max-height: 95vh;
  max-height: 95svh;
  max-height: calc(var(--vvh, 100vh) - max(8px, var(--safe-t, 0px)) - max(8px, var(--safe-b, 0px)) - 8px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
  gap: clamp(6px, 1.5vh, 16px);
  gap: clamp(6px, 1.5dvh, 16px);
  padding: 12px 18px;
  padding: clamp(10px, 2vh, 22px) clamp(12px, 2.4cqi, 26px);
  padding: clamp(10px, 2dvh, 22px) clamp(12px, 2.4cqi, 26px);
  border-radius: 22px;
  background-color: rgba(14, 24, 44, 0.78);
  background-image: linear-gradient(180deg, rgba(255, 244, 214, 0.07) 0%, rgba(255, 244, 214, 0) 40%);
  border: 1.5px solid rgba(245, 196, 94, 0.44);
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.62), inset 0 1px 0 rgba(255, 255, 255, 0.18), inset 0 0 0 1px rgba(245, 196, 94, 0.1);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.title-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.compass-emblem {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.35rem;
  color: #1d1405;
  background: radial-gradient(circle at 35% 30%, var(--gold-bright), var(--gold-primary));
  box-shadow: 0 0 22px rgba(245, 196, 94, 0.65);
  flex-shrink: 0;
}

.title-headings {
  flex: 1 1 240px;
}

.eyebrow-tag {
  margin: 0;
  font-size: clamp(0.62rem, 0.5rem + 0.35vw, 0.76rem);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold-primary);
  font-weight: 700;
}

.title-headings h1 {
  margin: 2px 0;
  font-size: clamp(1.15rem, 0.85rem + 1.5vw, 1.9rem);
  line-height: 1.15;
  color: var(--cream-text);
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
}

.title-subtitle {
  margin: 0;
  font-size: clamp(0.76rem, 0.65rem + 0.45vw, 0.96rem);
  color: var(--muted-text);
}

.top-lang-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.pill-select {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(12, 22, 40, 0.85);
  border: 1px solid rgba(245, 196, 94, 0.32);
  font-size: 0.78rem;
  color: var(--muted-text);
}

.pill-select select {
  background: transparent;
  color: var(--gold-bright);
  border: none;
  font-weight: 700;
  font-size: 0.82rem;
  outline: none;
  cursor: pointer;
}

/* Equal 5-Card Hero Grid (OR-01 zero default bias) */
.hero-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: clamp(8px, 1.4cqi, 16px);
}

.hero-card {
  position: relative;
  min-height: 86px;
  max-height: 178px;
  border-radius: 18px;
  border: 2px solid rgba(255, 248, 232, 0.22);
  background: linear-gradient(165deg, rgba(28, 46, 76, 0.78), rgba(12, 21, 38, 0.88));
  color: var(--cream-text);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 6px;
  cursor: pointer;
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.hero-card:hover {
  transform: translateY(-2px);
  border-color: rgba(245, 196, 94, 0.72);
}

.hero-card.is-selected,
.hero-card[aria-checked="true"] {
  border-color: var(--gold-bright);
  box-shadow: 0 0 0 3px rgba(245, 196, 94, 0.46), 0 12px 28px rgba(0, 0, 0, 0.52);
  background: linear-gradient(165deg, rgba(66, 48, 92, 0.88), rgba(22, 36, 64, 0.94));
  transform: translateY(-2px) scale(1.015);
}

.hero-avatar {
  width: 64px;
  height: 64px;
  width: clamp(46px, 11vh, 84px);
  height: clamp(46px, 11vh, 84px);
  width: clamp(46px, 11dvh, 84px);
  height: clamp(46px, 11dvh, 84px);
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 2px solid rgba(255, 242, 198, 0.65);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.42), inset 0 0 14px rgba(255, 255, 255, 0.22);
}

.hero-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

.hero-avatar-catrina { background: radial-gradient(circle at 50% 35%, #5c2a6d, #231338); }
.hero-avatar-leo { background: radial-gradient(circle at 50% 35%, #2a4c7d, #13223b); }
.hero-avatar-jet { background: radial-gradient(circle at 50% 35%, #255799, #122646); }
.hero-avatar-skye { background: radial-gradient(circle at 50% 35%, #3b5fa3, #17284a); }
.hero-avatar-chumba { background: radial-gradient(circle at 50% 35%, #4b3f9e, #1a1448); }

.hero-name {
  font-weight: 800;
  font-size: clamp(0.88rem, 0.75rem + 0.5vw, 1.12rem);
}

.hero-prop {
  font-size: clamp(0.66rem, 0.58rem + 0.3vw, 0.8rem);
  color: var(--muted-text);
  text-align: center;
}

.title-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.mode-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.mode-chip {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid rgba(255, 255, 255, 0.2);
  background: rgba(15, 25, 45, 0.8);
  color: var(--muted-text);
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}

.mode-chip.is-active {
  border-color: var(--turquoise-sluice);
  background: rgba(46, 196, 182, 0.2);
  color: #e6fffa;
}

.room-code-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(10, 18, 34, 0.9);
  border: 1px solid var(--turquoise-sluice);
  font-size: 0.78rem;
}

.room-code-wrap input {
  width: 74px;
  background: transparent;
  border: none;
  color: var(--gold-bright);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  outline: none;
}

.bench-link {
  color: var(--gold-primary);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px dashed rgba(245, 196, 94, 0.42);
}

.bench-link:hover {
  background: rgba(245, 196, 94, 0.12);
}

.btn-play-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 168px;
  min-height: 50px;
  padding: 10px 28px;
  border-radius: 999px;
  border: 2px solid #fff2c2;
  background: linear-gradient(180deg, #ffe28a 0%, #f0b138 100%);
  color: #231503;
  font-size: clamp(1rem, 0.85rem + 0.5vw, 1.22rem);
  font-weight: 900;
  letter-spacing: 0.03em;
  box-shadow: 0 8px 26px rgba(245, 196, 94, 0.52);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
}

.btn-play-cta:active {
  transform: scale(0.97);
}

/* HUD & Landscape Dual-Thumb Controls Layer (CTRL P01..P03) */
.hud-touch-layer {
  position: absolute;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  touch-action: none;
}

.bilingual-toast {
  position: absolute;
  top: 52px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 12;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 18px;
  border-radius: 999px;
  background: rgba(16, 28, 52, 0.88);
  border: 1.5px solid var(--gold-primary);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-weight: 800;
  font-size: clamp(0.88rem, 0.75rem + 0.45vw, 1.08rem);
  pointer-events: none;
}

.bilingual-star { color: var(--gold-bright); }
.bilingual-word-a { color: #7dd3fc; }
.bilingual-word-b { color: #fde68a; }
.bilingual-sep { color: rgba(255, 255, 255, 0.4); }

/* Victory Banner */
.victory-banner {
  position: absolute;
  inset: 0;
  z-index: 18;
  display: grid;
  place-items: center;
  padding: max(12px, var(--safe-t, 0px), env(safe-area-inset-top, 0px)) max(16px, var(--safe-r, 0px), env(safe-area-inset-right, 0px)) max(12px, var(--safe-b, 0px), env(safe-area-inset-bottom, 0px)) max(16px, var(--safe-l, 0px), env(safe-area-inset-left, 0px));
  overflow-y: auto;
  overscroll-behavior: contain;
  background: radial-gradient(ellipse at 50% 45%, rgba(12, 22, 40, 0.62) 0%, rgba(8, 14, 28, 0.74) 100%);
}

.victory-card {
  width: min(100%, 520px);
  max-width: 520px;
  max-height: calc(100vh - 24px);
  max-height: calc(var(--vvh, 100vh) - max(12px, var(--safe-t, 0px)) - max(12px, var(--safe-b, 0px)) - 16px);
  overflow-y: auto;
  padding: 24px 30px;
  border-radius: 24px;
  background: rgba(18, 32, 58, 0.94);
  border: 2px solid var(--gold-bright);
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}

.victory-star { font-size: 1.8rem; margin-bottom: 6px; }
.victory-actions { display: flex; gap: 12px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

.btn-gold-pill {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 20px;
  border-radius: 999px;
  border: 1.5px solid var(--gold-bright);
  background: linear-gradient(180deg, #ffe088, #eba834);
  color: #201304;
  font-weight: 800;
  cursor: pointer;
}

.btn-outline-pill, .btn-subtle-pill {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 18px;
  border-radius: 999px;
  border: 1.5px solid rgba(245, 196, 94, 0.5);
  background: rgba(15, 27, 48, 0.85);
  color: var(--cream-text);
  font-weight: 700;
  font-size: 0.82rem;
  text-decoration: none;
  cursor: pointer;
}

/* Native <dialog> Modal Rules per modern-web-guidance `dialog` guide */
dialog.jumi-modal-dialog {
  width: min(640px, calc(100vw - 2 * max(16px, var(--safe-l, 0px), var(--safe-r, 0px)) - 12px));
  width: min(640px, calc(var(--vvw, 100vw) - 2 * max(16px, var(--safe-l, 0px), var(--safe-r, 0px)) - 12px));
  max-width: min(640px, calc(100vw - 2 * max(16px, var(--safe-l, 0px), var(--safe-r, 0px)) - 12px));
  max-width: min(640px, calc(var(--vvw, 100vw) - 2 * max(16px, var(--safe-l, 0px), var(--safe-r, 0px)) - 12px));
  max-height: 88vh;
  max-height: 88svh;
  max-height: calc(var(--vvh, 100vh) - max(8px, var(--safe-t, 0px)) - max(8px, var(--safe-b, 0px)) - 12px);
  padding: 18px 22px;
  border-radius: 22px;
  border: 1.5px solid var(--gold-primary);
  background: rgba(16, 28, 50, 0.96);
  color: var(--cream-text);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.7);
  overflow-y: auto;
  overflow-x: hidden;
  touch-action: pan-y;
}

dialog:modal {
  overscroll-behavior: contain;
}

dialog::backdrop {
  background: radial-gradient(ellipse at 50% 45%, rgba(8, 14, 28, 0.72) 0%, rgba(4, 9, 20, 0.82) 100%);
  overflow: hidden;
  overscroll-behavior: contain;
}

.modal-inner {
  padding: 2px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-header, .modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.modal-header h2 { margin: 0; font-size: 1.12rem; color: var(--gold-bright); }
.parent-helper-body { font-size: 0.9rem; line-height: 1.48; color: var(--cream-text); }
.wake-inner { padding: 28px 34px; text-align: center; display: grid; gap: 14px; place-items: center; }

.portrait-guard {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  background: rgba(10, 18, 34, 0.95);
  text-align: center;
  padding: 24px;
}

@media (orientation: portrait) and (max-aspect-ratio: 1 / 1) {
  .portrait-guard:not([hidden]) { display: grid; }
}

.rotate-icon { font-size: 2.6rem; margin-bottom: 10px; }

@container (max-width: 660px) {
  .title-card-container { padding: 10px 12px; gap: 8px; }
  .hero-card { min-height: 76px; padding: 5px; }
  .mode-chip, .btn-subtle-pill { min-height: 40px; padding: 6px 12px; }
}

/* Compact Safari iPhone landscape bar-open height (~280..360px) */
@media (max-height: 365px) {
  .title-overlay { padding: max(4px, var(--safe-t, 0px), env(safe-area-inset-top, 0px)) max(12px, var(--safe-r, 0px), env(safe-area-inset-right, 0px)) max(4px, var(--safe-b, 0px), env(safe-area-inset-bottom, 0px)) max(12px, var(--safe-l, 0px), env(safe-area-inset-left, 0px)); }
  .title-card-container { padding: 7px 14px; gap: 5px; border-radius: 16px; }
  .compass-emblem { width: 32px; height: 32px; font-size: 1rem; }
  .eyebrow-tag { display: none; }
  .title-headings h1 { font-size: 1.05rem; margin: 0; }
  .title-subtitle { font-size: 0.72rem; }
  .pill-select { padding: 3px 8px; font-size: 0.72rem; }
  .hero-grid { gap: 8px; }
  .hero-card { min-height: 68px; padding: 5px 4px; gap: 2px; border-radius: 13px; }
  .hero-avatar { width: 44px; height: 44px; }
  .hero-name { font-size: 0.82rem; }
  .hero-prop { font-size: 0.62rem; }
  .mode-chip, .btn-subtle-pill { min-height: 34px; padding: 4px 10px; font-size: 0.74rem; }
  .bench-link { padding: 4px 8px; font-size: 0.72rem; }
  .btn-play-cta { min-height: 38px; min-width: 132px; padding: 6px 20px; font-size: 0.94rem; }
  .bilingual-toast { top: 40px; padding: 4px 14px; font-size: 0.82rem; }

  .victory-banner {
    padding: max(8px, var(--safe-t, 0px), env(safe-area-inset-top, 0px)) max(12px, var(--safe-r, 0px), env(safe-area-inset-right, 0px)) max(8px, var(--safe-b, 0px), env(safe-area-inset-bottom, 0px)) max(12px, var(--safe-l, 0px), env(safe-area-inset-left, 0px));
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  .victory-card {
    width: min(100%, 680px);
    max-height: calc(100vh - 16px);
    max-height: calc(100svh - 16px);
    max-height: calc(var(--vvh, 100vh) - max(8px, var(--safe-t, 0px)) - max(8px, var(--safe-b, 0px)) - 8px);
    overflow-y: auto;
    padding: 10px 14px;
    border-radius: 18px;
  }
  .victory-star { font-size: 1.2rem; margin-bottom: 2px; }
  .victory-card h2 { margin: 4px 0; font-size: clamp(1rem, 3.6vh, 1.45rem); }
  .victory-card p { margin: 4px 0; font-size: 0.86rem; line-height: 1.3; }
  .victory-actions { gap: 6px; margin-top: 8px; }
  .victory-actions > * { min-height: 48px; padding: 6px 12px; }

  dialog.jumi-modal-dialog[open] {
    max-height: calc(100vh - 12px);
    max-height: calc(100svh - 12px);
    max-height: calc(var(--vvh, 100vh) - max(6px, var(--safe-t, 0px)) - max(6px, var(--safe-b, 0px)) - 8px);
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    border-radius: 16px;
  }
  .modal-inner { flex: 1 1 auto; min-height: 0; gap: 6px; }
  .modal-header, .modal-footer { gap: 6px; }
  .modal-header h2 { font-size: 1rem; }
  .parent-helper-body {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    font-size: 0.82rem;
    line-height: 1.35;
  }
  .modal-footer > button, .modal-footer > a { min-height: 48px; padding: 6px 12px; }
  .wake-inner { gap: 6px; padding: 8px 12px; }
  .wake-inner .compass-emblem { width: 30px; height: 30px; font-size: 0.9rem; }
  .wake-inner h2 { margin: 2px 0; font-size: 1.05rem; }
  .wake-inner .btn-play-cta { min-height: 48px; padding: 6px 14px; font-size: 0.9rem; }
}

/* Ultra-compact old iPhone SE1 / 5s (568x268) & Display Zoom / LINE webview (<315px tall) */
@media (max-width: 640px), (max-height: 315px) {
  .title-overlay {
    padding: max(4px, var(--safe-t, 0px)) max(8px, var(--safe-r, 0px)) max(4px, var(--safe-b, 0px)) max(8px, var(--safe-l, 0px));
  }
  .title-card-container {
    padding: 5px 10px;
    gap: 4px;
    border-radius: 14px;
  }
  .title-header { gap: 6px; }
  .compass-emblem { width: 28px; height: 28px; font-size: 0.9rem; }
  .title-headings { flex: 1 1 140px; min-width: 0; }
  .title-headings h1 { font-size: 0.96rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .title-subtitle, .hero-prop { display: none; }
  .top-lang-controls { gap: 4px; }
  .hero-grid { gap: 5px; }
  .hero-card { min-height: 54px; padding: 4px 3px; border-radius: 11px; }
  .hero-avatar { width: 34px; height: 34px; }
  .hero-name { font-size: 0.74rem; }
  .title-footer { gap: 6px; }
  .btn-play-cta { min-width: 118px; min-height: 48px; padding: 5px 16px; font-size: 0.88rem; }
}

@media (prefers-reduced-motion: reduce) {
  .hero-card,
  .btn-play-cta {
    transition: none;
  }
}
