/* たのしい都道府県つみき — iPhone-first game stage.
   Palette (CMF): indigo dawn sky, vermilion torii, urushi lacquer blocks. */

body.tsumiki {
  --stage-h: min(78svh, 720px);
}

.app-shell {
  max-width: 720px;
  margin: 0 auto;
}

.stage {
  position: relative;
  width: 100%;
  height: var(--stage-h);
  min-height: 480px;
  border-radius: 1.2rem;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #101528;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

@media (max-width: 640px) {
  body.tsumiki {
    --stage-h: calc(100svh - 9.5rem);
  }
  .stage {
    border-radius: 0.9rem;
    min-height: 420px;
  }
}

/* During play the stage takes the whole viewport: the hero, requirements
   banner and chrome are informational and would push the stage's bottom
   (the drop zone) below the fold on phones. */
body.tsumiki.in-game {
  overflow: hidden;
}

body.tsumiki.in-game .site-header,
body.tsumiki.in-game .app-hero,
body.tsumiki.in-game #requirements,
body.tsumiki.in-game .site-footer {
  display: none;
}

body.tsumiki.in-game .app-shell {
  max-width: none;
}

body.tsumiki.in-game .stage {
  height: 100svh;
  height: 100dvh;
  min-height: 0;
  border-radius: 0;
  border: 0;
}

#gpu-canvas,
#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#game-canvas {
  z-index: 1;
  touch-action: none;
}

#gpu-canvas {
  z-index: 0;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s;
}
#hud.visible {
  opacity: 1;
}

.hud-top {
  position: absolute;
  top: max(0.5rem, env(safe-area-inset-top));
  left: max(0.5rem, env(safe-area-inset-left));
  right: max(0.5rem, env(safe-area-inset-right));
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}

.hud-cell {
  background: rgb(8 12 28 / 0.55);
  backdrop-filter: blur(8px);
  border: 1px solid rgb(255 255 255 / 0.12);
  border-radius: 0.8rem;
  padding: 0.3rem 0.65rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 3.4rem;
  color: #eef2ff;
  text-shadow: 0 1px 4px rgb(0 0 0 / 0.5);
}

.hud-k {
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  color: #b9c6ee;
}

.hud-cell strong {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.combo {
  color: #ffcf6e;
  font-weight: 700;
  font-size: 0.8rem;
  min-height: 1em;
}

.hearts {
  color: #ff7d92;
  font-size: 1.05rem;
  letter-spacing: 0.1em;
}

.hud-next {
  margin-left: auto;
}
#next-canvas {
  width: 40px;
  height: 40px;
}
#next-label {
  font-size: 0.62rem;
  max-width: 4.5rem;
  text-align: center;
  color: #b9c6ee;
}

.hud-side {
  position: absolute;
  right: max(0.5rem, env(safe-area-inset-right));
  top: 30%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
}
.height-meter {
  width: 8px;
  height: 120px;
  border-radius: 4px;
  background: rgb(255 255 255 / 0.12);
  overflow: hidden;
  display: flex;
  align-items: flex-end;
}
#height-fill {
  width: 100%;
  background: linear-gradient(#ffd97a, #ff8d5c);
  transition: height 0.3s;
}

#wind-ind {
  position: absolute;
  top: 18%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 1.5rem;
  font-weight: 700;
  color: #cfe6ff;
  text-shadow: 0 0 12px rgb(120 190 255 / 0.9);
}

.hud-actions {
  position: absolute;
  bottom: max(0.6rem, env(safe-area-inset-bottom));
  right: max(0.6rem, env(safe-area-inset-right));
  display: flex;
  gap: 0.45rem;
  pointer-events: auto;
}
.icon-btn {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 50%;
  background: rgb(8 12 28 / 0.55);
  border: 1px solid rgb(255 255 255 / 0.16);
  color: #fff;
  font-size: 1.05rem;
  backdrop-filter: blur(8px);
}

/* ---------- toast ---------- */
#toast {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translate(-50%, -8px) scale(0.92);
  z-index: 3;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition:
    opacity 0.18s,
    transform 0.18s;
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0) scale(1);
}
.toast-main {
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 2px 18px rgb(0 0 0 / 0.55);
}
.toast-sub {
  font-size: 0.95rem;
  color: #ffe9b8;
  text-shadow: 0 1px 10px rgb(0 0 0 / 0.6);
}

#save-warning,
#boot-error {
  position: absolute;
  top: 0.6rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
  background: rgb(120 30 30 / 0.85);
  color: #fff;
  font-size: 0.78rem;
  padding: 0.4rem 0.8rem;
  border-radius: 0.6rem;
  max-width: 92%;
}

/* ---------- screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgb(6 8 20 / 0.42);
  backdrop-filter: blur(4px);
  padding: 1rem;
}
.screen.visible {
  display: flex;
}

.screen .panel {
  background: linear-gradient(160deg, rgb(18 24 48 / 0.92), rgb(10 14 32 / 0.94));
  border: 1px solid rgb(255 255 255 / 0.14);
  border-radius: 1.2rem;
  padding: 1.4rem 1.6rem;
  text-align: center;
  color: #eef1ff;
  max-width: 24rem;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  box-shadow: 0 24px 80px rgb(0 0 0 / 0.5);
}
.panel-wide {
  max-width: 34rem;
  max-height: 92%;
  display: flex;
  flex-direction: column;
}

.panel h2 {
  margin: 0;
  font-size: 1.3rem;
}
.panel .lead {
  font-size: 0.92rem;
  line-height: 1.5;
  opacity: 0.85;
  margin: 0;
}
.panel-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 2rem;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(150deg, #e2483d, #8e1f2d);
  box-shadow: 0 8px 30px rgb(226 72 61 / 0.45);
}

button.primary {
  background: linear-gradient(150deg, #ff9a5c, #e2483d);
  border: none;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  min-height: 48px;
  border-radius: 0.9rem;
  box-shadow: 0 6px 24px rgb(226 72 61 / 0.4);
}
.screen .panel button:not(.primary) {
  background: rgb(255 255 255 / 0.08);
  border-color: rgb(255 255 255 / 0.18);
  color: #eef1ff;
  min-height: 44px;
}
.row {
  display: flex;
  gap: 0.6rem;
}
.row button {
  flex: 1;
}

.vol-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.85rem;
}
.vol-row input {
  flex: 1;
  accent-color: #ff9a5c;
}

#oobe-dots {
  display: flex;
  gap: 0.4rem;
  justify-content: center;
}
#oobe-dots .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgb(255 255 255 / 0.25);
}
#oobe-dots .dot.on {
  background: #ffcf6e;
}

.newbest {
  font-weight: 800;
  color: #ffd97a;
  letter-spacing: 0.1em;
  animation: pulse 1s infinite alternate;
}
@keyframes pulse {
  from {
    opacity: 0.7;
    transform: scale(1);
  }
  to {
    opacity: 1;
    transform: scale(1.06);
  }
}

.result-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 1rem;
  margin: 0;
  font-size: 0.95rem;
}
.result-grid dt {
  text-align: left;
  opacity: 0.75;
}
.result-grid dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

/* ---------- collection ---------- */
.collection-map {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 30svh;
  margin: 0 auto;
}

#collection-grid {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.collection-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
  gap: 0.4rem;
}
.collection-list .cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  background: rgb(255 255 255 / 0.05);
  border: 1px solid rgb(255 255 255 / 0.1);
  border-radius: 0.7rem;
  padding: 0.35rem 0.2rem;
  color: #cdd4ee;
  font-size: 0.62rem;
  min-height: 0;
}
.collection-list .cell.has {
  border-color: rgb(255 207 110 / 0.5);
  color: #fff;
}
.collection-list .cell canvas {
  width: 40px;
  height: 40px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01s !important;
    transition-duration: 0.01s !important;
  }
}

/* Achievement chips inside the collection screen */
.achievements {
  margin-top: 1.1rem;
}

.ach-h {
  font-size: 0.78rem;
  color: #b9c6ee;
  margin: 0.7rem 0 0.35rem;
  letter-spacing: 0.06em;
}

.ach-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.ach-chip {
  padding: 0.28rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  background: rgb(255 255 255 / 0.06);
  border: 1px solid rgb(255 255 255 / 0.12);
  color: #b9c6ee;
  font-variant-numeric: tabular-nums;
}

.ach-chip.done {
  background: linear-gradient(135deg, #ffb45c, #ff7d5c);
  border-color: transparent;
  color: #2a1400;
  font-weight: 700;
}
