/* ==========================================================================
   MonsterReveal ── 夜空のシール帳
   Sections: 1 tokens · 2 base · 3 backdrop · 4 stickers (buttons, cards)
             5 title · 6 select/zukan · 7 play · 8 dialogs · 9 motion
   ========================================================================== */

/* ---- 1. Tokens ---- */
:root {
  --night-1: #1B1A3A;
  --night-2: #2A2457;
  --paper: #FFF6E3;
  --paper-shade: #F1E4C6;
  --ink: #24213F;
  --gold: #FFD45C;
  --danger: #FF6B81;
  --safe: #5FF2D4;
  --ice: #9ADCFF;
  --grey: #CFC8B3;

  /* Overwritten from JS with the current area colours */
  --area: #FF9F43;
  --area-dark: #E9803A;
  --area-light: #F6A55E;
  --area-rgb: 255, 159, 67;

  --font: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI", "Meiryo", sans-serif;
  --border: 3px solid var(--ink);
  --shadow: 0 4px 0 var(--ink);
  --radius: 18px;

  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
}

/* ---- 2. Base ---- */
*,
*::before,
*::after { box-sizing: border-box; }

html {
  height: 100%;
  background: var(--night-1);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  font-weight: 700;
  color: var(--paper);
  background: linear-gradient(180deg, var(--night-1), var(--night-2)) fixed;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* The play screen never scrolls and never zooms. */
body[data-screen="play"] {
  overflow: hidden;
  touch-action: none;
  position: fixed;
  inset: 0;
  width: 100%;
}

button { font: inherit; color: inherit; }
img { display: block; }
h1, h2, h3, p, dl, dd { margin: 0; }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--safe); outline-offset: 3px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.icon { width: 1.25em; height: 1.25em; flex: none; vertical-align: -0.22em; }

/* ---- 3. Backdrop: twinkling stars and soft colour blobs ---- */
.sky {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  background: linear-gradient(180deg, var(--night-1), var(--night-2));
}

.sky-blob {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  opacity: 0.5;
  animation: drift 18s ease-in-out infinite alternate;
}
.sky-blob--a { width: 70vmax; height: 70vmax; left: -28vmax; top: -22vmax; background: #6A4CFF; opacity: 0.38; }
.sky-blob--b { width: 56vmax; height: 56vmax; right: -24vmax; top: 30vh; background: #FF6BA8; opacity: 0.22; animation-duration: 24s; }
.sky-blob--c { width: 60vmax; height: 60vmax; left: -10vmax; bottom: -34vmax; background: #28D6C0; opacity: 0.2; animation-duration: 21s; }

.stars {
  position: absolute;
  top: 0; left: 0;
  width: 2px; height: 2px;
  border-radius: 50%;
  animation: twinkle 4.2s ease-in-out infinite alternate;
}
.stars--a {
  box-shadow:
    0vw 92vh 0 0 #fff, 29vw 21vh 0 0 #fff, 73vw 53vh 0 0 #fff, 33vw 75vh 0 0 #fff,
    76vw 54vh 0 0 #fff, 68vw 64vh 0 0 #fff, 82vw 24vh 0 0 #fff, 37vw 71vh 0 0 #fff,
    70vw 5vh 0 0 #fff, 68vw 47vh 0 0 #fff, 92vw 81vh 0 0 #fff, 12vw 51vh 0 0 #fff,
    92vw 69vh 0 0 #fff, 64vw 58vh 0 0 #fff, 91vw 91vh 0 0 #fff, 37vw 34vh 0 0 #fff,
    84vw 33vh 0 0 #fff, 15vw 30vh 0 0 #fff, 43vw 29vh 0 0 #fff, 94vw 56vh 0 0 #fff,
    73vw 88vh 0 0 #fff, 6vw 27vh 0 0 #fff;
}
.stars--b {
  width: 3px; height: 3px;
  animation-duration: 6.4s;
  animation-delay: -2s;
  box-shadow:
    56vw 51vh 0 0 #FFE9A8, 42vw 19vh 0 0 #FFE9A8, 91vw 5vh 0 0 #FFE9A8, 37vw 34vh 0 0 #FFE9A8,
    66vw 92vh 0 0 #FFE9A8, 51vw 17vh 0 0 #FFE9A8, 41vw 28vh 0 0 #FFE9A8, 36vw 42vh 0 0 #FFE9A8,
    33vw 53vh 0 0 #FFE9A8, 61vw 23vh 0 0 #FFE9A8, 91vw 46vh 0 0 #FFE9A8, 86vw 64vh 0 0 #FFE9A8,
    63vw 52vh 0 0 #FFE9A8, 50vw 69vh 0 0 #FFE9A8, 94vw 40vh 0 0 #FFE9A8, 71vw 25vh 0 0 #FFE9A8;
}
.stars--c {
  width: 4px; height: 4px;
  animation-duration: 3.4s;
  animation-delay: -1s;
  box-shadow:
    59vw 35vh 0 0 #fff, 33vw 39vh 0 0 #FFE9A8, 79vw 88vh 0 0 #fff, 11vw 82vh 0 0 #FFE9A8,
    8vw 41vh 0 0 #fff, 15vw 8vh 0 0 #FFE9A8, 98vw 22vh 0 0 #fff, 63vw 14vh 0 0 #FFE9A8,
    46vw 59vh 0 0 #fff;
}

/* ---- 4. Stickers: screens, buttons, cards ---- */
.app { position: relative; z-index: 1; }

.screen {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 640px;
  min-height: 100dvh;
  margin: 0 auto;
  padding: calc(var(--sat) + 14px) calc(var(--sar) + 16px) calc(var(--sab) + 14px) calc(var(--sal) + 16px);
}
.screen.is-entering { animation: screenIn 0.35s ease-out; }

.sticker {
  background: var(--paper);
  color: var(--ink);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  font-size: 17px;
  font-weight: 900;
  line-height: 1.2;
  color: var(--ink);
  background: var(--paper);
  border: var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform 0.08s, box-shadow 0.08s, filter 0.15s;
}
.btn:active:not(:disabled) { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: 0.55; filter: grayscale(0.7); cursor: not-allowed; }
.btn--primary { background: var(--gold); }
.btn--area { background: var(--area); }
.btn--danger { background: var(--danger); }
.btn--wide { width: 100%; }
.btn--small { min-height: 44px; padding: 6px 12px; font-size: 14px; }

.icon-btn {
  display: grid;
  place-items: center;
  flex: none;
  width: 46px;
  height: 46px;
  padding: 0;
  font-size: 22px;
  color: var(--ink);
  background: var(--paper);
  border: var(--border);
  border-radius: 15px;
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.08s, box-shadow 0.08s;
}
.icon-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.icon-btn .icon { width: 1em; height: 1em; }

.tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.04em;
  color: var(--ink);
  background: var(--paper-shade);
  border: 2px solid var(--ink);
  border-radius: 999px;
}
.tag--area { background: var(--area); }

/* Stars (outlined grey until earned) */
.star { display: inline-block; width: 1em; height: 1em; line-height: 0; }
.star .icon { width: 100%; height: 100%; vertical-align: top; fill: var(--grey); stroke: var(--ink); stroke-width: 1.7; paint-order: stroke; }
.star.is-lit .icon { fill: var(--gold); }

/* ---- 4b. Start gate ---- */
.screen--start { justify-content: center; align-items: center; }
.start-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: clamp(28px, 8vh, 56px);
}
/* .logo carries order: 1 for the title layout, so the action must come after it here. */
.start-action { order: 2; display: flex; flex-direction: column; align-items: center; gap: 12px; width: min(100%, 340px); }
.btn--gate { width: 100%; font-size: clamp(20px, 6vw, 26px); letter-spacing: 0.06em; }
.start-note { font-size: 14px; color: var(--paper); opacity: 0.85; }

/* ---- 5. Title ---- */
.screen--title { justify-content: center; align-items: center; }

.title-layout {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  gap: 14px;
}
.title-main { display: contents; }
.logo { order: 1; text-align: center; }
.title-art { order: 2; }
.title-stats { order: 3; }
.title-menu { order: 4; }

.logo-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  font-size: clamp(40px, 15vw, 68px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: 0.02em;
  --outline:
    4px 0 0 var(--ink), -4px 0 0 var(--ink), 0 4px 0 var(--ink), 0 -4px 0 var(--ink),
    3px 3px 0 var(--ink), -3px 3px 0 var(--ink), 3px -3px 0 var(--ink), -3px -3px 0 var(--ink),
    4px 2px 0 var(--ink), 4px -2px 0 var(--ink), -4px 2px 0 var(--ink), -4px -2px 0 var(--ink),
    2px 4px 0 var(--ink), -2px 4px 0 var(--ink), 2px -4px 0 var(--ink), -2px -4px 0 var(--ink);
}
.logo-line {
  display: block;
  text-shadow: var(--outline), 0 6px 0 var(--ink), 3px 6px 0 var(--ink), -3px 6px 0 var(--ink), 0 8px 0 var(--ink), 0 12px 18px rgba(0, 0, 0, 0.4);
}
.logo-line--top { color: var(--paper); transform: rotate(-3deg); }
.logo-line--bottom { color: var(--gold); margin-top: 6px; transform: rotate(2deg) translateX(10px); }

.logo-sub {
  margin-top: 20px;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.42em;
  text-indent: 0.42em;
  color: var(--paper);
}
.logo-sub::before,
.logo-sub::after {
  content: "";
  display: inline-block;
  width: 22px; height: 3px;
  margin: 0 8px;
  vertical-align: middle;
  background: var(--gold);
  border-radius: 2px;
}

.title-art { display: flex; justify-content: center; }
.title-card {
  position: relative;
  padding: 8px;
  background: var(--paper);
  border: var(--border);
  border-radius: 20px;
  box-shadow: 0 6px 0 var(--ink), 0 14px 26px rgba(0, 0, 0, 0.35);
  transform: rotate(-3deg);
}
.title-card canvas {
  display: block;
  width: clamp(116px, min(44vw, 24dvh), 230px);
  aspect-ratio: 8 / 9;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
}
.title-card-tag {
  position: absolute;
  right: -12px; bottom: -12px;
  padding: 3px 12px;
  font-size: 13px;
  font-weight: 900;
  color: var(--ink);
  background: var(--gold);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
  transform: rotate(6deg);
}

.title-stats { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.stat {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 14px;
  font-size: 15px;
  font-weight: 900;
  color: var(--paper);
  background: rgba(255, 246, 227, 0.12);
  border: 2px solid rgba(255, 246, 227, 0.4);
  border-radius: 999px;
}
.stat b { font-size: 18px; font-variant-numeric: tabular-nums; }
.stat .icon { fill: var(--gold); }
.stat-label { font-size: 13px; opacity: 0.85; }

.title-menu { display: flex; flex-direction: column; gap: 14px; width: min(100%, 340px); }
.btn--xl { min-height: 62px; font-size: 26px; letter-spacing: 0.1em; border-radius: 20px; }
.btn--xl .icon { width: 1em; height: 1em; }
.title-menu-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.btn--menu {
  flex-direction: column;
  gap: 2px;
  min-height: 64px;
  padding: 8px 4px;
  font-size: 14px;
  white-space: nowrap;
}
.btn--menu .icon { width: 22px; height: 22px; }

.portal-link {
  align-self: center;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  margin-top: 6px;
  padding: 0 14px;
  font-size: 14px;
  color: var(--paper);
  text-decoration: none;
  opacity: 0.85;
}
.portal-link:hover { opacity: 1; text-decoration: underline; }

/* Landscape and desktop: logo and menu on the left, demo card on the right. */
@media (orientation: landscape) and (min-width: 640px) {
  .screen--title { max-width: 980px; }
  .title-layout { flex-direction: row; justify-content: center; gap: clamp(24px, 6vw, 72px); }
  .title-main { display: flex; flex-direction: column; align-items: center; gap: clamp(8px, 2.6vh, 22px); }
  .title-art { order: 0; }
  .logo-text { font-size: clamp(38px, 13vh, 96px); }
  .title-card canvas { width: min(300px, 40vh); }
}
@media (orientation: landscape) and (max-height: 559px) {
  .logo-sub { margin-top: 12px; }
  .btn--xl { min-height: 52px; font-size: 22px; }
  .btn--menu { min-height: 54px; padding: 4px; }
  .portal-link { min-height: 36px; margin-top: 0; }
}

/* ---- 6. Stage select and zukan ---- */
.screen--select,
.screen--zukan { padding-top: 0; padding-bottom: 0; }

.sticky-top {
  position: sticky;
  top: 0;
  z-index: 5;
  margin: 0 calc(var(--sar) * -1 - 16px) 0 calc(var(--sal) * -1 - 16px);
  padding: calc(var(--sat) + 10px) calc(var(--sar) + 16px) 10px calc(var(--sal) + 16px);
  background: linear-gradient(180deg, rgba(27, 26, 58, 0.96) 78%, rgba(27, 26, 58, 0));
}
.page-head { display: flex; align-items: center; gap: 12px; }
.page-title { flex: 1; font-size: 24px; font-weight: 900; text-align: center; letter-spacing: 0.06em; text-shadow: 0 3px 0 var(--ink); }
.page-head-space { width: 46px; flex: none; }
.count-pill {
  flex: none;
  min-width: 46px;
  padding: 7px 12px;
  font-size: 16px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--gold);
  border: var(--border);
  border-radius: 999px;
  box-shadow: 0 3px 0 var(--ink);
}

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  min-height: 56px;
  padding: 6px 4px 8px;
  color: var(--ink);
  background: var(--tab);
  border: var(--border);
  border-radius: 14px 14px 10px 10px;
  box-shadow: 0 4px 0 var(--ink);
  cursor: pointer;
  opacity: 0.78;
  transition: transform 0.1s, opacity 0.15s;
}
.tab.is-selected { opacity: 1; transform: translateY(-3px); box-shadow: 0 7px 0 var(--ink), 0 0 0 3px var(--gold); }
.tab.is-locked { background: #8A86A8; opacity: 0.7; }
.tab.is-locked.is-selected { opacity: 0.95; }
.tab-name { display: inline-flex; align-items: center; gap: 4px; font-size: 16px; font-weight: 900; }
.tab-name .icon { width: 15px; height: 15px; }
.tab-stars { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; font-weight: 900; font-variant-numeric: tabular-nums; }
.tab-stars .icon { width: 12px; height: 12px; fill: var(--paper); stroke: var(--ink); stroke-width: 2; }

.stage-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 12px; padding: 14px 0 20px; }

.stage-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  min-width: 0;
  min-height: 156px;
  padding: 0 8px 9px;
  overflow: hidden;
  color: var(--ink);
  text-align: center;
  background: var(--paper);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s, box-shadow 0.12s;
}
.stage-card:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
.stage-card.is-selected { transform: translateY(-3px); box-shadow: 0 7px 0 var(--ink), 0 0 0 4px var(--gold); }
.stage-card.is-locked { background: #D6D0C2; }

.card-band { align-self: stretch; margin: 0 -8px; padding: 3px 10px; text-align: left; background: var(--area); border-bottom: var(--border); }
.card-no { font-size: 15px; font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: 0.06em; }

.card-thumb {
  position: relative;
  display: grid;
  place-items: center;
  width: min(84px, 100%);
  aspect-ratio: 1;
  margin-top: 2px;
  background: radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.7), transparent 70%), var(--area-light);
  border: 2px solid var(--ink);
  border-radius: 16px;
}
.card-thumb img { width: 90%; height: 90%; object-fit: contain; }
.stage-card.is-locked .card-thumb { background: #B7B1A2; }
img.is-silhouette { filter: brightness(0); opacity: 0.38; }
.card-unknown {
  position: absolute;
  font-size: 28px;
  font-weight: 900;
  color: var(--paper);
  text-shadow: 0 2px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink);
}
.card-lock { font-size: 34px; color: var(--ink); --lock-hole: #B7B1A2; }
.card-lock .icon { width: 1em; height: 1em; }

.card-name {
  width: 100%;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.2;
  overflow-wrap: anywhere;
}
.card-stars { display: flex; gap: 3px; font-size: 18px; }

/* Bottom detail panel for the selected stage */
.detail { position: sticky; bottom: 0; z-index: 5; margin: auto calc(var(--sar) * -1 - 16px) 0 calc(var(--sal) * -1 - 16px); padding: 22px calc(var(--sar) + 16px) calc(var(--sab) + 12px) calc(var(--sal) + 16px); background: linear-gradient(0deg, rgba(27, 26, 58, 0.97) 76%, rgba(27, 26, 58, 0)); }
.detail-card { padding: 10px 12px; }
.detail-row { display: flex; align-items: center; gap: 10px; }
.detail-no {
  display: grid;
  place-items: center;
  flex: none;
  width: 44px; height: 44px;
  font-size: 20px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  background: var(--area);
  border: var(--border);
  border-radius: 50%;
  transform: rotate(-6deg);
}
.detail-text { display: flex; flex: 1; flex-direction: column; min-width: 0; gap: 1px; }
.detail-name { font-size: 17px; font-weight: 900; line-height: 1.2; overflow-wrap: anywhere; }
.detail-meta { font-size: 12px; opacity: 0.8; }
.detail-best { font-size: 12px; font-variant-numeric: tabular-nums; }
.btn--start { flex: none; min-width: 104px; min-height: 52px; font-size: 18px; letter-spacing: 0.04em; }
.detail-error {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--ink);
  background: #FFD7DD;
  border: 2px solid var(--ink);
  border-radius: 12px;
}

/* Zukan */
.zukan-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px 6px; padding: 14px 0 calc(var(--sab) + 20px); }
.zukan-tile {
  position: relative;
  display: block;
  aspect-ratio: 1;
  padding: 0;
  overflow: hidden;
  background: radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.7), transparent 72%), var(--area-light);
  border: 2px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 3px 0 var(--ink);
}
button.zukan-tile { cursor: pointer; transition: transform 0.08s, box-shadow 0.08s; touch-action: manipulation; }
button.zukan-tile:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.zukan-tile img { width: 86%; height: 86%; margin: 7% auto 0; object-fit: contain; }
.zukan-tile:not(.is-found) { background: #CFC9BB; }
.tile-no {
  position: absolute;
  left: 3px; top: 2px;
  font-size: 10px;
  font-weight: 900;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.tile-unknown {
  position: absolute;
  left: 0; right: 0; bottom: 2px;
  font-size: 10px;
  font-weight: 900;
  text-align: center;
  color: var(--ink);
}

/* ---- 7. Play ---- */
.screen--play {
  max-width: 560px;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "info" "board" "controls";
  gap: 8px;
  padding-top: calc(var(--sat) + 8px);
  padding-bottom: calc(var(--sab) + 10px);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

.play-info { grid-area: info; display: grid; gap: 8px; align-content: start; }

.hud-head { display: flex; align-items: center; gap: 8px; }
.stage-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.stage-no {
  align-self: flex-start;
  padding: 0 9px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  color: var(--ink);
  background: var(--area);
  border: 2px solid var(--ink);
  border-radius: 999px;
}
.stage-name { font-size: 18px; font-weight: 900; line-height: 1.15; overflow-wrap: anywhere; text-shadow: 0 2px 0 var(--ink); }
.hud-head .icon-btn { width: 44px; height: 44px; font-size: 20px; }

.hud-meter { padding: 6px 12px 8px; }
.meter-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 42px; }
.percent { display: flex; align-items: baseline; gap: 1px; font-weight: 900; line-height: 1; transform-origin: left center; }
.percent-value { font-size: 38px; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.percent-unit { font-size: 18px; }
.percent.is-bump { animation: bump 0.4s ease-out; }

.chips { flex: 1; display: flex; justify-content: center; gap: 6px; min-height: 34px; }
.chip {
  position: relative;
  display: grid;
  place-items: center;
  width: 38px; height: 38px;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 50%;
}
.chip--clock { color: #3AA9E8; }
.chip--shoes { color: #E8A100; }
.chip-ring { position: absolute; inset: -4px; width: calc(100% + 8px); height: calc(100% + 8px); transform: rotate(-90deg); }
.chip-ring-bg, .chip-ring-fg { fill: none; stroke-width: 3.2; }
.chip-ring-bg { stroke: rgba(36, 33, 63, 0.12); }
.chip-ring-fg { stroke: currentColor; stroke-linecap: round; }
.chip-icon { width: 18px; height: 18px; margin-top: -4px; }
.chip-icon path, .chip-icon circle { stroke-width: 2.6; }
.chip-sec {
  position: absolute;
  right: -5px; bottom: -6px;
  min-width: 17px;
  padding: 0 3px;
  font-size: 11px;
  line-height: 15px;
  text-align: center;
  color: var(--ink);
  background: var(--gold);
  border: 2px solid var(--ink);
  border-radius: 999px;
}
.chip.is-pop { animation: pop 0.45s cubic-bezier(0.2, 1.5, 0.4, 1); }

.hearts { display: flex; gap: 3px; margin-left: auto; }
.heart { position: relative; display: block; width: 28px; height: 28px; }
.heart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.heart-shape { fill: #FF4F6D; stroke: var(--ink); stroke-width: 1.8; stroke-linejoin: round; transition: fill 0.2s; }
.heart-crack { stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; opacity: 0; }
.heart.is-lost .heart-shape { fill: transparent; stroke: #9A96B5; stroke-dasharray: 3 2.4; }
.heart.is-breaking { animation: heartBreak 0.65s ease-out forwards; }
.heart.is-breaking .heart-crack { opacity: 1; }
.heart.is-healed { animation: pop 0.5s cubic-bezier(0.2, 1.5, 0.4, 1); }

/* Progress bar with ticks at 80% (clear) and 90% (second star) */
.bar { position: relative; padding-top: 16px; }
.bar-track { height: 14px; overflow: hidden; background: var(--paper-shade); border: 2px solid var(--ink); border-radius: 999px; }
.bar-fill {
  width: 100%; height: 100%;
  background: repeating-linear-gradient(135deg, var(--safe) 0 8px, #3FD9BB 8px 16px);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.18s linear;
}
.bar-mark { position: absolute; top: 0; bottom: 0; width: 0; }
.bar-mark::before {
  content: "";
  position: absolute;
  left: -1.5px; top: 14px; bottom: 0;
  width: 3px;
  background: var(--ink);
  border-radius: 2px;
}
.bar-mark::after {
  content: "";
  position: absolute;
  left: -8px; top: -1px;
  width: 16px; height: 16px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2.6l2.95 6.05 6.65.95-4.8 4.65 1.15 6.6L12 17.75l-5.95 3.1L7.2 14.25 2.4 9.6l6.65-.95z' fill='%23FFD45C' stroke='%2324213F' stroke-width='2.2' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
}
.bar-mark--clear { left: 80%; }
.bar-mark--star { left: 90%; }

.hint {
  min-height: 20px;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.4;
  text-align: center;
  text-shadow: 0 2px 0 rgba(36, 33, 63, 0.9);
}
.hint[data-tone="good"] { color: var(--safe); }
.hint[data-tone="bad"] { color: var(--danger); }
.hint[data-tone="gold"] { color: var(--gold); }

/* Board */
.board-area { grid-area: board; display: flex; align-items: center; justify-content: center; min-height: 0; min-width: 0; overflow: visible; }
.board-frame {
  position: relative;
  flex: none;
  padding: 6px;
  background: var(--area);
  border: var(--border);
  border-radius: 20px;
  box-shadow: 0 4px 0 var(--ink), 0 0 26px rgba(var(--area-rgb), 0.5);
  transition: box-shadow 0.2s;
}
.board-frame.is-frozen { box-shadow: 0 4px 0 var(--ink), 0 0 0 3px var(--ice), 0 0 30px rgba(154, 220, 255, 0.85); }
.board-frame.is-hit { animation: frameHit 0.45s ease-out; }
.board-inner { position: relative; width: 100%; height: 100%; overflow: hidden; background: var(--ink); border: var(--border); border-radius: 12px; }
#board { display: block; width: 100%; height: 100%; touch-action: none; }

.ready {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(34px, 11vw, 58px);
  font-weight: 900;
  letter-spacing: 0.06em;
  color: var(--paper);
  text-shadow: 3px 0 0 var(--ink), -3px 0 0 var(--ink), 0 3px 0 var(--ink), 0 -3px 0 var(--ink), 2px 2px 0 var(--ink), -2px 2px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink), 0 7px 0 var(--ink);
  pointer-events: none;
  opacity: 0;
}
.ready.is-on { opacity: 1; animation: readyPop 0.5s cubic-bezier(0.2, 1.5, 0.4, 1); }
.ready.is-go { color: var(--gold); }

/* Controls */
.controls { grid-area: controls; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.control-hint {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  font-size: 13px;
  font-weight: 900;
  line-height: 1.4;
  color: var(--paper);
  text-shadow: 0 2px 0 var(--ink);
}
.control-hint span { display: block; padding-left: 4px; }
.control-hint .icon { width: 1.1em; height: 1.1em; margin-right: 4px; fill: var(--gold); }
.control-hint span:first-child .icon { fill: var(--safe); }

.dpad {
  --key: clamp(50px, min(17vw, 9.2dvh), 70px);
  display: grid;
  grid-template-columns: repeat(3, var(--key));
  grid-template-rows: repeat(3, var(--key));
  gap: 6px;
  flex: none;
  touch-action: none;
}
.dkey {
  display: grid;
  place-items: center;
  padding: 0;
  font-size: calc(var(--key) * 0.5);
  color: var(--ink);
  background: var(--paper);
  border: var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: none;
  transition: transform 0.06s, box-shadow 0.06s, background 0.1s;
}
.dkey .icon { width: 1em; height: 1em; }
.dkey.is-pressed { background: var(--gold); transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.dkey--up { grid-area: 1 / 2; }
.dkey--left { grid-area: 2 / 1; }
.dkey--right { grid-area: 2 / 3; }
.dkey--down { grid-area: 3 / 2; }
.dpad-center { grid-area: 2 / 2; align-self: center; justify-self: center; width: 34%; height: 34%; background: rgba(255, 246, 227, 0.16); border-radius: 50%; }

/* Landscape phones: left info column, centre board, right d-pad */
@media (orientation: landscape) and (max-height: 539px) {
  .screen--play {
    max-width: none;
    grid-template-columns: minmax(210px, 30vw) minmax(0, 1fr) auto;
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas: "info board controls";
    gap: 12px;
    padding: calc(var(--sat) + 8px) calc(var(--sar) + 16px) calc(var(--sab) + 8px) calc(var(--sal) + 16px);
  }
  .play-info { align-content: center; gap: 6px; }
  .stage-name { font-size: 16px; }
  .hud-meter { padding: 5px 10px 7px; }
  .percent-value { font-size: 32px; }
  .meter-row { min-height: 0; }
  .chips { flex-basis: 100%; order: 3; justify-content: flex-start; min-height: 0; }
  .hearts { margin-left: auto; }
  .heart { width: 24px; height: 24px; }
  .controls { flex-direction: column; justify-content: center; }
  .control-hint { display: none; }
  .dpad { --key: clamp(46px, 22dvh, 64px); }
}

/* Short portrait phones */
@media (max-height: 700px) and (orientation: portrait) {
  .play-info { gap: 6px; }
  .hud-meter { padding: 4px 12px 6px; }
  .meter-row { min-height: 38px; }
  .percent-value { font-size: 32px; }
  .stage-name { font-size: 16px; }
  .hint { min-height: 18px; font-size: 12px; }
  .control-hint { font-size: 12px; gap: 4px; }
}

/* Short portrait phones: hint moves beside the d-pad so the board gets the height */
@media (max-height: 700px) and (orientation: portrait) {
  .screen--play {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "head head" "meter meter" "board board" "hint dpad";
    gap: 6px 10px;
  }
  .play-info, .controls { display: contents; }
  .hud-head { grid-area: head; }
  .hud-meter { grid-area: meter; }
  .hint { grid-area: hint; align-self: center; text-align: left; font-size: 13px; }
  .board-area { grid-area: board; }
  .dpad { grid-area: dpad; --key: clamp(46px, 8.2dvh, 60px); }
  .control-hint { display: none; }
}

/* Narrow phones: tighter stage detail panel */
@media (max-width: 400px) {
  .detail-row { gap: 8px; }
  .detail-no { width: 38px; height: 38px; font-size: 17px; }
  .detail-name { font-size: 16px; }
  .btn--start { min-width: 92px; font-size: 16px; padding-left: 10px; padding-right: 10px; }
}

/* ---- 8. Dialogs ---- */
.dialog-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: calc(var(--sat) + 12px) calc(var(--sar) + 12px) calc(var(--sab) + 12px) calc(var(--sal) + 12px);
  background: rgba(14, 12, 38, 0.62);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: fadeIn 0.2s ease-out;
}
.dialog {
  position: relative;
  width: min(100%, 380px);
  max-height: 100%;
  padding: 18px 18px 18px;
  overflow-x: hidden;
  overflow-y: auto;
  color: var(--ink);
  background: var(--paper);
  border: var(--border);
  border-radius: 24px;
  box-shadow: 0 6px 0 var(--ink), 0 22px 40px rgba(0, 0, 0, 0.4);
  animation: pop 0.34s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.dialog:focus { outline: none; }
.dialog--small { width: min(100%, 340px); }
.dialog--tutorial { width: min(100%, 400px); }

.dialog-title { margin-bottom: 10px; font-size: 24px; font-weight: 900; line-height: 1.2; text-align: center; }
.dialog-text { font-size: 15px; line-height: 1.6; text-align: center; text-wrap: balance; }
.dialog-head { display: flex; justify-content: center; gap: 8px; margin-bottom: 8px; }
.dialog-actions { display: grid; gap: 10px; margin-top: 16px; }
.dialog-actions--row { grid-template-columns: 1fr 1fr; }
.dialog-actions--stack { grid-template-columns: 1fr; }
.dialog-actions--result { grid-template-columns: 1fr 1fr; }
.dialog-actions--result .btn--wide { grid-column: 1 / -1; }
.dialog > .btn--wide { margin-top: 12px; }

/* Sound switch */
.switch-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 52px;
  margin-top: 14px;
  padding: 8px 14px;
  font-size: 17px;
  font-weight: 900;
  color: var(--ink);
  background: var(--paper-shade);
  border: var(--border);
  border-radius: 16px;
  cursor: pointer;
  text-align: left;
}
.switch-label { display: inline-flex; align-items: center; gap: 8px; flex: 1; }
.switch { position: relative; flex: none; width: 58px; height: 32px; background: var(--grey); border: var(--border); border-radius: 999px; transition: background 0.15s; }
.switch-knob { position: absolute; left: 2px; top: 2px; width: 22px; height: 22px; background: #fff; border: 2px solid var(--ink); border-radius: 50%; transition: transform 0.18s cubic-bezier(0.3, 1.4, 0.5, 1); }
.switch-row[aria-checked="true"] .switch { background: var(--safe); }
.switch-row[aria-checked="true"] .switch-knob { transform: translateX(26px); }
.switch-state { width: 2.6em; font-size: 14px; font-variant-numeric: tabular-nums; text-align: right; }

/* Result */
.result-title { font-size: 30px; letter-spacing: 0.06em; color: var(--ink); text-shadow: 0 3px 0 var(--gold); }
.dialog--fail .result-title { text-shadow: 0 3px 0 var(--danger); }
.result-monster {
  position: relative;
  display: grid;
  place-items: center;
  width: clamp(88px, 19dvh, 150px);
  aspect-ratio: 1;
  margin: 6px auto 10px;
  background: radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.8), transparent 72%), var(--area-light);
  border: var(--border);
  border-radius: 22px;
  box-shadow: 0 4px 0 var(--ink);
  transform: rotate(-2deg);
}
.result-monster img { width: 88%; height: 88%; object-fit: contain; }
.result-monster.is-bump { animation: pop 0.6s cubic-bezier(0.2, 1.6, 0.4, 1); }
.result-name { margin-bottom: 4px; font-size: 18px; font-weight: 900; text-align: center; overflow-wrap: anywhere; }
.result-stars { display: flex; justify-content: center; gap: 8px; margin: 4px 0 8px; font-size: 44px; }
.result-stars .star.is-lit { animation: starBounce 0.55s cubic-bezier(0.2, 1.6, 0.4, 1); }
.result-stars .star.is-lit .icon { filter: drop-shadow(0 0 6px rgba(255, 212, 92, 0.9)); }
.result-stars.is-static .star.is-lit { animation: none; }
.result-stars.is-static { font-size: 36px; }
.result-stars .star.is-new::after { content: none; }

.stats { display: grid; gap: 6px; margin-top: 4px; }
.stats > div { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 12px; background: var(--paper-shade); border: 2px solid var(--ink); border-radius: 12px; }
.stats dt { font-size: 14px; }
.stats dd { display: inline-flex; align-items: center; gap: 6px; font-size: 18px; font-weight: 900; font-variant-numeric: tabular-nums; }
.stats--big dd { font-size: 24px; }
.new-badge { padding: 0 6px; font-size: 10px; line-height: 16px; letter-spacing: 0.06em; color: var(--ink); background: var(--danger); border: 2px solid var(--ink); border-radius: 999px; transform: rotate(-6deg); animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1) 0.2s both; }
.mini-hearts { gap: 2px; }
.mini-heart { display: inline-block; font-size: 20px; color: #FF4F6D; line-height: 0; }
.mini-heart .icon { width: 1em; height: 1em; stroke: var(--ink); stroke-width: 1.6; }
.mini-heart.is-lost { color: transparent; }
.mini-heart.is-lost .icon { stroke: #9A96B5; stroke-dasharray: 3 2.4; }

.note { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 8px; font-size: 14px; font-weight: 900; text-align: center; }
.note--gold { color: var(--ink); }
.note--gold .icon { fill: var(--gold); stroke: var(--ink); stroke-width: 1.4; paint-order: stroke; }
.note .icon { width: 1.2em; height: 1.2em; }

/* Tutorial */
.tutorial-view { overflow: hidden; touch-action: pan-y; margin: 0 -4px; }
.tutorial-track { display: flex; transition: transform 0.35s cubic-bezier(0.3, 0.9, 0.4, 1); }
.tutorial-page { flex: 0 0 100%; padding: 0 4px; }
.tutorial-art { padding: 4px; background: var(--night-2); border: var(--border); border-radius: 16px; }
.tutorial-svg { display: block; width: 100%; height: auto; }
.tutorial-title { margin: 10px 0 4px; font-size: 20px; font-weight: 900; text-align: center; }
.tutorial-page .dialog-text { min-height: 4.8em; font-size: 14px; }
.dots { display: flex; justify-content: center; }
.dot { position: relative; width: 40px; height: 44px; padding: 0; background: none; border: 0; cursor: pointer; }
.dot::before { content: ""; position: absolute; left: 50%; top: 50%; width: 11px; height: 11px; background: var(--grey); border: 2px solid var(--ink); border-radius: 50%; transform: translate(-50%, -50%); transition: transform 0.2s, background 0.2s; }
.dot.is-on::before { background: var(--gold); transform: translate(-50%, -50%) scale(1.4); }

/* Celebration */
.dialog--celebrate { overflow: hidden; }
.confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti i { position: absolute; top: -16px; left: var(--x); width: 8px; height: 14px; background: var(--c); border-radius: 2px; transform: rotate(var(--r)); animation: confettiFall 2.8s linear var(--d) infinite; }
.celebrate-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; margin: 10px 0; }
.celebrate-grid img { width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--paper-shade); border: 2px solid var(--ink); border-radius: 8px; }
.dialog--celebrate > :not(.confetti) { position: relative; }

/* ---- 9. Motion ---- */
@keyframes twinkle { from { opacity: 0.25; } to { opacity: 1; } }
@keyframes drift { from { transform: translate(0, 0) scale(1); } to { transform: translate(4vmax, 3vmax) scale(1.08); } }
@keyframes screenIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { 0% { opacity: 0; transform: scale(0.8); } 100% { opacity: 1; transform: scale(1); } }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.3); } 100% { transform: scale(1); } }
@keyframes readyPop { 0% { opacity: 0; transform: scale(0.5); } 100% { opacity: 1; transform: scale(1); } }
@keyframes starBounce { 0% { transform: scale(0.3) rotate(-30deg); } 60% { transform: scale(1.35) rotate(8deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes frameHit {
  0% { box-shadow: 0 4px 0 var(--ink), 0 0 0 4px var(--danger), 0 0 36px rgba(255, 107, 129, 0.95); }
  100% { box-shadow: 0 4px 0 var(--ink), 0 0 26px rgba(var(--area-rgb), 0.5); }
}
@keyframes heartBreak {
  0% { transform: scale(1); }
  20% { transform: scale(1.3) rotate(-8deg); }
  40% { transform: scale(1.2) rotate(8deg); }
  70% { transform: scale(0.9) rotate(-4deg); opacity: 1; }
  100% { transform: scale(0.85); opacity: 0.9; }
}
@keyframes confettiFall {
  0% { transform: translateY(0) rotate(var(--r)); opacity: 1; }
  100% { transform: translateY(520px) rotate(calc(var(--r) + 540deg)); opacity: 0.8; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    animation-delay: 0s !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .stars, .sky-blob { animation: none !important; }
  .confetti { display: none; }
}
