:root {
  --bg: #111827;
  --panel: #1f2937;
  --ink: #f9fafb;
  --muted: #9ca3af;
  --you: #f59e0b;
  --foe: #38bdf8;
  --danger: #f43f5e;
  --ok: #34d399;
  --line: #374151;
  --safe: env(safe-area-inset-bottom, 0px);
  --card-w: clamp(72px, 22vmin, 104px);
  --card-h: clamp(100px, 30vmin, 142px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% -20%, #1e3a5f 0%, transparent 50%), var(--bg);
  color: var(--ink);
  font-family: "Zen Kaku Gothic New", system-ui, sans-serif;
  font-weight: 500;
}

#app {
  width: min(480px, 100%);
  height: 100%;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 12px calc(10px + var(--safe));
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto auto auto;
  gap: 6px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand {
  font-family: "Archivo Black", sans-serif;
  font-size: clamp(0.72rem, 3.2vw, 0.95rem);
  letter-spacing: 0.01em;
  line-height: 1.1;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-tabs {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 2px;
  background: #0b1220;
  border-radius: 999px;
  border: 1px solid var(--line);
  flex-shrink: 0;
}

.tab {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 7px 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}

.tab[aria-selected="true"] {
  background: var(--panel);
  color: var(--ink);
}

.stage-bar {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr) minmax(0, auto);
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.stage-bar span {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-bar strong {
  font-family: "Archivo Black", sans-serif;
  font-size: clamp(0.9rem, 3.8vw, 1.15rem);
  color: #fde68a;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.stage {
  min-height: 0;
  display: flex;
}

.arena {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: radial-gradient(circle at 50% 40%, #243247, #111827 70%);
  overflow: hidden;
  touch-action: none;
}

.arena.listening {
  box-shadow: inset 0 0 0 2px rgba(245, 158, 11, 0.55);
}

/* Side-by-side so cards never stack on top of each other in short frames */
.card {
  position: absolute;
  top: 50%;
  width: var(--card-w);
  height: var(--card-h);
  margin-top: calc(var(--card-h) / -2);
  transform-style: preserve-3d;
  transition: transform 0.45s cubic-bezier(0.2, 0.9, 0.2, 1);
}

.card.you {
  left: 18%;
  transform: translateX(-10%) rotate(-8deg);
}

.card.foe {
  right: 18%;
  left: auto;
  transform: translateX(10%) rotate(8deg);
}

.face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: 12px;
  border: 3px solid #0b1220;
  display: grid;
  place-items: center;
  font-family: "Archivo Black", sans-serif;
  font-size: clamp(1.25rem, 5vmin, 1.85rem);
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.35);
}

.you .front {
  background: linear-gradient(160deg, #fbbf24, #d97706);
  color: #111;
}

.foe .front {
  background: linear-gradient(160deg, #7dd3fc, #0284c7);
  color: #082f49;
}

.back {
  background: repeating-linear-gradient(
    -30deg,
    #e5e7eb 0 8px,
    #d1d5db 8px 16px
  );
  color: #374151;
  transform: rotateY(180deg);
}

.card.you.flipped {
  transform: translateX(-10%) rotate(-8deg) rotateY(180deg);
}

.card.foe.flipped {
  transform: translateX(10%) rotate(8deg) rotateY(180deg);
}

.card.you.slam {
  animation: slamYou 0.35s ease;
}

.card.foe.hit {
  animation: hitFoe 0.5s ease;
}

.rock {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(120px, 34vmin);
  height: min(100px, 28vmin);
  transform: translate(-50%, -50%);
  border-radius: 42% 48% 40% 55% / 48% 40% 55% 45%;
  background:
    radial-gradient(circle at 30% 28%, #9ca3af, transparent 40%),
    linear-gradient(160deg, #6b7280, #374151 55%, #1f2937);
  border: 3px solid #0b1220;
  display: grid;
  place-items: center;
  font-family: "Archivo Black", sans-serif;
  font-size: 1.4rem;
  color: #e5e7eb;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.4);
  z-index: 2;
}

.card.hidden,
.rock.hidden {
  display: none;
}

.rock.shake {
  animation: hitFoe 0.45s ease;
}

.rock.cracked {
  filter: brightness(1.15) saturate(0.7);
  outline: 2px dashed #fbbf24;
}

.rock.flipped {
  transform: translate(-50%, -50%) rotateX(165deg) scale(1.08);
  filter: brightness(1.35) saturate(1.1);
  outline: 2px solid #fbbf24;
  box-shadow: 0 18px 36px rgba(245, 158, 11, 0.35);
}

.power-readout {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #0b1220;
  border: 1px solid var(--line);
  font-family: "Archivo Black", sans-serif;
  font-size: 1.35rem;
  color: var(--you);
}

.power-readout.hidden {
  display: none;
}

.foe.boss .front {
  background: linear-gradient(160deg, #f9a8d4, #db2777);
  color: #4a044e;
}

.foe.mid .front {
  background: linear-gradient(160deg, #a7f3d0, #059669);
  color: #064e3b;
}

@keyframes slamYou {
  0% { transform: translateX(-10%) rotate(-8deg) scale(1); }
  40% { transform: translateX(8%) rotate(-2deg) scale(1.06); }
  100% { transform: translateX(-10%) rotate(-8deg) scale(1); }
}

@keyframes hitFoe {
  0%, 100% { transform: translateX(10%) rotate(8deg); }
  30% { transform: translateX(18%) rotate(16deg); }
  60% { transform: translateX(4%) rotate(2deg); }
}

.hud {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.meter {
  height: 10px;
  border-radius: 999px;
  background: #0b1220;
  border: 1px solid var(--line);
  overflow: hidden;
}

.meter i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--you), var(--danger));
  transition: width 0.05s linear;
}

.hint {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 800;
  text-align: center;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subhint {
  margin: 0;
  font-size: 0.74rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.actions .btn {
  width: 100%;
  justify-content: center;
}

.panel .actions {
  margin-top: 14px;
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  color: var(--ink);
  background: var(--panel);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

/* display:flex on .btn would otherwise override the hidden attribute */
[hidden] {
  display: none !important;
}

.btn.primary {
  background: var(--you);
  color: #111;
  border-color: transparent;
}

.btn.ghost {
  background: transparent;
  color: #e5e7eb;
}

.foot-links {
  display: flex;
  justify-content: center;
  gap: 18px;
}

.foot-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.74rem;
  font-weight: 700;
}

.foot-links a:hover {
  color: var(--ink);
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  display: grid;
  place-items: end center;
  padding: 20px 16px calc(24px + var(--safe));
  z-index: 20;
}

.overlay.hidden {
  display: none;
}

.panel {
  width: min(100%, 420px);
  background: #111827;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--you);
  font-size: 0.78rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-weight: 800;
}

.panel h2 {
  margin: 0 0 8px;
  font-family: "Archivo Black", sans-serif;
  font-size: 1.7rem;
}

.panel p {
  color: #d1d5db;
  margin: 0;
}

/* Embedded / short frames: shrink chrome, keep cards apart */
@media (max-height: 700px) {
  #app {
    gap: 4px;
    padding-top: max(6px, env(safe-area-inset-top));
  }
  .brand { font-size: 0.72rem; }
  .tab { padding: 6px 8px; font-size: 0.68rem; }
  .hint { font-size: 0.82rem; }
  .btn { padding: 10px 12px; }
  .foot-links { display: none; }
}

@media (max-height: 560px) {
  :root {
    --card-w: clamp(64px, 20vmin, 88px);
    --card-h: clamp(88px, 28vmin, 120px);
  }
  .subhint { display: none; }
}

@media (min-width: 900px) and (pointer: fine) {
  #app {
    max-height: min(100vh, 860px);
    margin-top: max(0px, calc((100vh - min(100vh, 860px)) / 2));
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}
