@font-face {
  font-family: "Fredoka";
  src: url("../assets/fonts/fredoka-latin-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Nunito";
  src: url("../assets/fonts/nunito-latin-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Nunito";
  src: url("../assets/fonts/nunito-latin-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #241c16;
  --paper: #f4efe6;
  --paper-2: #e7e0d1;
  --cream: #f7f1e4;
  --gold: #f0c14a;
  --gold-2: #e2ad2e;
  --sea: #8ee0d6;
  --good: #1f8a5b;
  --warn: #c4492c;
  --shell: #12171f;
  --shell-2: #1b2330;
  --line: #2c3544;
  --muted: #b7ad9e;
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  background:
    radial-gradient(900px 420px at 50% -10%, #243044, transparent 60%),
    #090c11;
  color: var(--cream);
  font-family: "Nunito", "Segoe UI", "Trebuchet MS", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

button, a { -webkit-tap-highlight-color: transparent; }

button {
  font: inherit;
  cursor: pointer;
}

img { display: block; max-width: 100%; }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  z-index: 40;
  background: var(--paper);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 8px;
}

.skip:focus { top: 12px; }

#app {
  width: min(1440px, 100%);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--shell);
  position: relative;
  overflow: hidden;
}

#shell {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#content {
  order: 1;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.tabs { order: 2; }

#app.no-tabs .tabs { display: none; }

.screen {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

#app[data-shard="0"] { --accent: #1f8a5b; }
#app[data-shard="1"] { --accent: #d86a1e; }
#app[data-shard="2"] { --accent: #1d7fa3; }
#app[data-shard="3"] { --accent: #7a3ea8; }
#app[data-shard="4"] { --accent: #e4548c; }

.topbar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: #0e131b;
  border-bottom: 2px solid var(--line);
  box-shadow: inset 0 -3px 0 var(--accent, #1f8a5b);
}

.pouch, .top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pouch {
  background: #241c16;
  color: var(--gold);
  border-radius: 999px;
  padding: 4px 10px 4px 6px;
  min-height: 36px;
}

.pouch strong {
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  font-size: 18px;
  font-weight: 600;
}

#place-label {
  margin: 0;
  text-align: center;
  color: var(--cream);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: var(--shell-2);
  display: grid;
  place-items: center;
  padding: 0;
}

.icon-btn img { width: 26px; height: 26px; }

.text-btn {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 14px;
  border: 2px solid var(--line);
  background: transparent;
  color: var(--cream);
}

.banner {
  margin: 8px 12px 0;
  padding: 10px 12px;
  border-radius: 12px;
  background: #3a2a22;
  color: #ffd7c8;
  border: 2px solid #c4492c;
}

#screen-title {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 8px;
  padding: 18px 20px 28px;
  overflow: auto;
}

.title-kitten {
  width: min(220px, 34vh);
  height: auto;
  filter: drop-shadow(0 12px 0 rgba(0, 0, 0, 0.18));
}

.wordmark {
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  font-size: clamp(42px, 8vw, 84px);
  line-height: 0.9;
  margin: 4px 0 0;
  letter-spacing: -0.03em;
  color: var(--cream);
}

.tagline {
  margin: 0;
  color: #ddd4c6;
  font-size: 18px;
}

.studio {
  margin: 4px 0 0;
  display: inline-flex;
  align-items: center;
  border: 2px solid var(--cream);
  border-radius: 999px;
  padding: 4px 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 700;
}

.fine {
  margin: 0;
  max-width: 36ch;
  color: var(--muted);
  font-size: 13px;
}

.title-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 8px;
}

.title-pouch {
  margin: 0;
  color: var(--gold);
  font-weight: 700;
}

.btn {
  min-height: 48px;
  padding: 0 18px;
  border-radius: 14px;
  border: 2px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--ink);
  font-weight: 700;
}

.btn:active {
  transform: translateY(4px);
  box-shadow: 0 0 0 var(--ink);
}

.btn-primary { background: var(--gold); }

.btn-primary:active { background: var(--gold-2); }

.btn-ghost {
  background: transparent;
  color: var(--cream);
  border-color: var(--cream);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35);
}

.btn-ghost.dark {
  color: var(--ink);
  border-color: var(--ink);
  box-shadow: 0 4px 0 var(--ink);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
  transform: none;
}

.btn.is-poor { opacity: 0.72; }

.btn.is-shake { animation: shake 0.28s linear; }

@keyframes shake {
  25% { transform: translateX(-3px); }
  50% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
}

.btn:focus-visible,
.icon-btn:focus-visible,
.text-btn:focus-visible,
.tabs button:focus-visible,
#btn-mine:focus-visible {
  outline: 3px solid var(--sea);
  outline-offset: 2px;
}

#screen-mine { overflow: hidden; }

.pit-frame {
  position: relative;
  flex: 1;
  min-height: 180px;
  margin: 12px 12px 0;
  border-radius: 28px;
  overflow: hidden;
  border: 3px solid var(--ink);
  box-shadow: 0 8px 0 rgba(0, 0, 0, 0.28);
  background: #8fcfaa;
}

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

#btn-mine {
  position: absolute;
  inset: 0;
  z-index: 2;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
  border-radius: 0;
}

#btn-mine span {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.hint, .hpbar {
  position: absolute;
  z-index: 3;
  pointer-events: none;
}

.hint {
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  max-width: calc(100% - 24px);
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 6px 12px;
  font-weight: 700;
  text-align: center;
}

.hpbar {
  left: 16px;
  right: 16px;
  bottom: 12px;
  height: 22px;
  border-radius: 999px;
  background: rgba(20, 16, 14, 0.35);
  border: 2px solid var(--ink);
  overflow: hidden;
}

#hp-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #1f8a5b, #d6f5c8);
}

#hp-text {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: white;
  font-size: 12px;
  font-weight: 700;
  text-shadow: 0 1px 0 #241c16;
}

.readout {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px 0;
  margin: 0;
}

.readout p, .rig-note {
  margin: 0;
  font-size: 14px;
}

.rig-note {
  padding: 4px 16px 8px;
  color: var(--muted);
  min-height: 2.6em;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: #0e131b;
  border-top: 2px solid var(--line);
}

.tabs button {
  flex: 1;
  min-height: 52px;
  border-radius: 14px;
  border: 2px solid transparent;
  background: transparent;
  color: #ddd4c6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 12px;
  font-weight: 700;
}

.tabs button img { width: 22px; height: 22px; }

.tabs button[aria-current="page"] {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--ink);
}

.panel {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel h2, .sheet h2, .credits h2 {
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  font-weight: 600;
  margin: 0;
}

.lede {
  margin: 0;
  color: #ddd4c6;
  max-width: 62ch;
}

.upgrade, .shard, .challenge-card, .modal-card, .credits-card {
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 18px;
  box-shadow: 0 4px 0 var(--ink);
}

.upgrade {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 8px 12px;
  padding: 12px;
  align-items: center;
}

.upgrade img { width: 56px; height: 56px; }

.upgrade h3, .shard h3, .challenge-card h3 {
  margin: 0;
  font-size: 18px;
}

.upgrade p, .shard p, .challenge-card p { margin: 2px 0 0; }

.effect {
  color: #3d4a3a;
  font-weight: 700;
  font-size: 14px;
}

.upgrade .buy { grid-column: 1 / -1; }

.shard-list, .challenge-list {
  display: grid;
  gap: 12px;
}

.shard, .challenge-card { padding: 14px; }

.shard { display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 4px 12px; }
.shard img { grid-row: 1 / span 4; width: 72px; height: 72px; align-self: center; }
.shard .place { font-weight: 700; color: var(--shard, var(--good)); }
.shard button, .challenge-card .btn { margin-top: 8px; grid-column: 1 / -1; }
.challenge-card img { width: 56px; height: 56px; }
#upgrade-list { display: grid; gap: 12px; align-content: start; }
.shard.is-current { outline: 3px solid var(--gold); }
.shard.is-locked { background: #e7e0d1; }

.sheet { padding: 16px; overflow: auto; gap: 12px; }

.credits { overflow: auto; padding: 16px; align-items: center; }
.credits-card {
  width: min(640px, 100%);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.credits-card p { margin: 0; }
.credits-card a { color: #0f6e62; font-weight: 700; }
.stats { padding-left: 18px; margin: 4px 0; }
.version { color: #6d6458; font-size: 13px; }

.play-hud {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
}

.play-hud strong { font-family: "Fredoka", "Trebuchet MS", sans-serif; }

#play-lives {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-weight: 700;
}

#play-lives img { width: 18px; height: 18px; }

#play-lives img.is-lost { opacity: 0.35; filter: grayscale(1); }

.timer {
  min-width: 44px;
  text-align: center;
  background: var(--paper);
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 700;
}

.timer.is-low { background: var(--warn); color: white; }

.play-stage { position: relative; flex: 1; min-height: 0; margin: 0 12px 12px; border-radius: 24px; overflow: hidden; border: 3px solid var(--ink); }

.play-controls {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.play-controls .btn { pointer-events: auto; min-width: 96px; }

.modal-back {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(8, 10, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
}

.modal-card {
  width: min(440px, 100%);
  padding: 20px;
}

.modal-card h2 {
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  margin: 0 0 8px;
}

.modal-card p { margin: 0 0 16px; }

.modal-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (min-width: 720px) {
  .upgrade { grid-template-columns: 56px minmax(0, 1fr) auto; }
  .upgrade .buy { grid-column: auto; white-space: nowrap; }
  .shard-list, .challenge-list { grid-template-columns: 1fr 1fr; }
  }

@media (orientation: landscape) and (min-width: 800px) {
  #app:not(.no-tabs) #shell {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    min-height: 0;
  }

  #app:not(.no-tabs) .tabs {
    order: 0;
    grid-column: 1;
    grid-row: 1;
    flex-direction: column;
    border-top: 0;
    border-right: 2px solid var(--line);
    padding: 10px 8px;
  }

  #app:not(.no-tabs) #content {
    order: 0;
    grid-column: 2;
    grid-row: 1;
  }

  #app:not(.no-tabs) .tabs button { flex: 0 0 auto; min-height: 72px; }
}

@media (max-height: 520px) {
  .title-kitten { width: 96px; }
  .wordmark { font-size: 36px; }
  .tabs button span { display: none; }
  .rig-note { display: none; }
  .pit-frame { min-height: 120px; margin: 6px 8px 0; }
  .readout { padding-top: 6px; }
}

@media (prefers-reduced-motion: no-preference) {
  .title-kitten { animation: bob 2.6s ease-in-out infinite; }
}

@keyframes bob {
  50% { transform: translateY(-6px); }
}

.count-pip {
  display: inline-grid;
  place-items: center;
  min-width: 1.3em;
  height: 1.3em;
  margin-left: 6px;
  padding: 0 4px;
  border-radius: 99px;
  background: var(--gold);
  color: var(--ink);
  font-size: 12px;
}

#btn-open-box { align-self: flex-start; }

.odds-panel {
  background: #1b2330;
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 12px 14px;
  color: var(--cream);
}

.odds-panel p { margin: 0 0 8px; }

.odds-panel ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 4px;
}

.odds-panel li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0 2px 10px;
  border-left: 4px solid transparent;
}

.odds-panel li.is-rarity {
  margin-top: 8px;
  font-weight: 700;
  border-left-color: var(--rarity, var(--gold));
}

#kit-list { display: grid; gap: 10px; }

.kit-row {
  display: grid;
  grid-template-columns: 14px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  background: var(--paper);
  color: var(--ink);
  border: 2px solid var(--ink);
  border-radius: 16px;
  padding: 12px;
}

.kit-row h3 { margin: 0; font-size: 18px; }

.kit-row p { margin: 2px 0 0; }

.kit-rarity {
  color: var(--rarity, #8a8175);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rarity-pip {
  width: 14px;
  height: 14px;
  margin-top: 4px;
  border-radius: 99px;
  background: var(--rarity, #8a8175);
  border: 2px solid var(--ink);
}

.serial-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.serial-row code {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 15px;
  background: #efe8da;
  border-radius: 8px;
  padding: 4px 8px;
  user-select: text;
  -webkit-user-select: text;
}

.chip-btn {
  min-height: 40px;
  padding: 0 10px;
  color: var(--ink);
  border-color: var(--ink);
  background: #efe8da;
}

#kit-summary { color: var(--gold); }

.reveal {
  position: fixed;
  inset: 0;
  z-index: 32;
  background: rgba(8, 10, 14, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.reveal-card {
  width: min(420px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  background: var(--paper);
  color: var(--ink);
  border: 3px solid var(--ink);
  border-radius: 22px;
  box-shadow: 0 8px 0 var(--ink);
  padding: 16px 16px 18px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.reveal-card h2 {
  font-family: "Fredoka", "Trebuchet MS", sans-serif;
  margin: 0;
}

.reveal-card p { margin: 0; }

#reveal-kitten {
  width: min(140px, 22vh);
  height: auto;
}

.reveal-reel {
  min-height: 1.2em;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 13px;
  color: var(--rarity, #8a8175);
}

.reveal-card[data-rarity="common"] { --rarity: #8a8175; }
.reveal-card[data-rarity="uncommon"] { --rarity: #1f8a5b; }
.reveal-card[data-rarity="rare"] { --rarity: #1d7fa3; }
.reveal-card[data-rarity="epic"] { --rarity: #7a3ea8; }
.reveal-card[data-rarity="legendary"] { --rarity: #9a6b12; }

.blind-box {
  width: 92px;
  height: 84px;
  border-radius: 16px;
  border: 3px solid var(--ink);
  background: var(--gold);
  position: relative;
  box-shadow: 0 6px 0 var(--ink);
  overflow: hidden;
}

.blind-box::before,
.blind-box::after {
  content: "";
  position: absolute;
  background: var(--rarity, #c4492c);
}

.blind-box::before {
  left: 50%;
  top: 0;
  bottom: 0;
  width: 16px;
  transform: translateX(-50%);
}

.blind-box::after {
  top: 42%;
  left: 0;
  right: 0;
  height: 16px;
}

.blind-box.is-shaking { animation: box-shake 0.32s linear infinite; }

.blind-box.is-open { animation: box-pop 0.35s ease; }

@keyframes box-shake {
  25% { transform: rotate(-4deg) translateY(1px); }
  50% { transform: rotate(4deg); }
  75% { transform: rotate(-2deg) translateY(-2px); }
}

@keyframes box-pop {
  40% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
