:root {
  color-scheme: dark;
  --bg: #07080d;
  --elev: #141722;
  --text: #f5f7fb;
  --muted: #9aa3b8;
  --line: rgba(255, 255, 255, 0.08);
  --accent: #6d5efc;
  --accent-2: #8d7bff;
  --danger: #ff4d6a;
  --amber: #ffc14d;
  --hex-w: 64px;
  --hex-h: calc(var(--hex-w) * 1.1547005);
  --gap: 4px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background:
    radial-gradient(900px 480px at 50% -10%, rgba(109, 94, 252, 0.35), transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
}

body {
  min-height: 100dvh;
}

button, input { font: inherit; color: inherit; }

button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.app {
  position: relative;
  min-height: 100dvh;
  height: 100dvh;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.screen {
  height: 100%;
  overflow: auto;
}

.screen[hidden] { display: none !important; }

.screen-home,
.screen-play {
  display: flex;
  flex-direction: column;
}

.screen-home {
  padding:
    calc(18px + env(safe-area-inset-top))
    20px
    calc(18px + env(safe-area-inset-bottom));
}

.profile {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px 8px 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 22px;
}

.profile-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.avatar {
  width: 44px;
  height: 44px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  font-weight: 800;
}

.profile-text { display: flex; flex-direction: column; min-width: 0; }

.profile-kicker,
.best-label,
.hud-kicker,
.signal-kicker,
.sheet-kicker {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.name-input {
  width: 9.5rem;
  max-width: 42vw;
  margin-top: 1px;
  padding: 0 0 2px;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: 16px;
  font-weight: 700;
  user-select: text;
  -webkit-user-select: text;
}

.name-input:focus {
  outline: none;
  box-shadow: inset 0 -1px 0 var(--accent-2);
}

.best-chip { text-align: right; }

.best-value {
  display: block;
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.best-sub {
  display: block;
  margin-top: 2px;
  color: var(--amber);
  font-size: 12px;
  font-weight: 700;
}

.hero {
  margin: auto 0;
  text-align: center;
}

.logo {
  margin: 14px 0 0;
  font-size: clamp(4.6rem, 18vw, 5.6rem);
  line-height: 0.85;
  letter-spacing: 0.12em;
  font-weight: 800;
  text-indent: 0.12em;
  background: linear-gradient(180deg, #ffffff 10%, #d9d4ff 45%, #8d7bff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.lede {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.logo-hive {
  --hex-w: 34px;
  --hex-h: calc(var(--hex-w) * 1.1547005);
  --gap: 3px;
  display: grid;
  justify-content: center;
}

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

.records { margin-top: 14px; }

.records-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.records-head h2 {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.records-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.records-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  max-height: 168px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.03);
}

.records-list.is-compact { max-height: 148px; }

.record {
  display: grid;
  grid-template-columns: 2rem minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 9px 12px;
}

.record + .record { box-shadow: inset 0 1px 0 var(--line); }

.record.is-you { background: rgba(109, 94, 252, 0.18); }

.record-rank,
.record-score {
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.record-rank { color: var(--amber); }

.record-name {
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-empty {
  padding: 14px 12px;
  color: var(--muted);
}

.place-line {
  margin: 0 0 8px;
  font-weight: 800;
}

.btn {
  width: 100%;
  border: 0;
  border-radius: 18px;
  height: 52px;
  font-weight: 700;
}

.btn-primary {
  height: 56px;
  color: white;
  background: linear-gradient(180deg, #9a89ff, #6d5efc);
  box-shadow: 0 12px 30px rgba(109, 94, 252, 0.35);
}

.btn-primary:active { transform: scale(0.985); }

.btn-ghost {
  background: transparent;
  color: #c9cedc;
}

.btn:focus-visible,
.hex:focus-visible,
.text-btn:focus-visible,
.name-input:focus-visible {
  outline: 2px solid #ffffff;
  outline-offset: 3px;
}

.hud {
  padding: calc(8px + env(safe-area-inset-top)) 16px 0;
}

.hud-top {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
}

.text-btn {
  border: 0;
  background: transparent;
  color: #c9cedc;
  padding: 8px 0;
  text-align: left;
  font-weight: 600;
}

.score-block { margin: 0; text-align: center; }

.score-value {
  display: block;
  font-size: 34px;
  font-weight: 800;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.hud-meta {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 10px;
  min-height: 1.2em;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.combo { color: var(--amber); font-weight: 800; }

.lives {
  display: flex;
  justify-content: flex-end;
  gap: 5px;
}

.pip {
  width: 13px;
  height: 15px;
  background: rgba(255, 255, 255, 0.16);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}

.pip.is-on { background: var(--danger); }

.timer {
  height: 6px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
}

.timer-bar {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  background: linear-gradient(90deg, var(--accent), #4be1ff);
}

.timer-bar.is-low {
  background: var(--danger);
  animation: timer-panic 480ms ease-in-out infinite;
}

.stage {
  position: relative;
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 8px 12px;
  container-type: inline-size;
}

.screen-play { --glow: var(--accent); }

.stage::before {
  content: "";
  position: absolute;
  inset: 10% 8%;
  background: radial-gradient(circle, color-mix(in srgb, var(--glow) 34%, transparent), transparent 68%);
  pointer-events: none;
}

.screen-play.is-fever .stage::before {
  background: radial-gradient(circle, color-mix(in srgb, var(--glow) 62%, transparent), transparent 70%);
  animation: fever-glow 680ms ease-in-out infinite alternate;
}

.screen-play.is-blaze .hex:not(:disabled) {
  filter: drop-shadow(0 0 12px var(--c));
}

.board {
  --hex-w: clamp(46px, 18cqw, 64px);
  --hex-h: calc(var(--hex-w) * 1.1547005);
  position: relative;
  z-index: 1;
  width: min(100%, 420px);
}

.hex-row {
  display: flex;
  justify-content: center;
  gap: var(--gap);
}

.hex-row + .hex-row {
  margin-top: calc(var(--hex-h) * -0.25 + var(--gap));
}

.hex,
.signal {
  padding: 0;
  border: 0;
  background-color: var(--c, #6d5efc);
  background-image:
    linear-gradient(180deg, rgba(255, 255, 255, 0.38), rgba(255, 255, 255, 0) 46%),
    var(--pattern);
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
}

.hex {
  width: var(--hex-w);
  height: var(--hex-h);
  filter: drop-shadow(0 8px 8px rgba(0, 0, 0, 0.35));
  transition: transform 90ms ease;
}

.hex:active:not(:disabled) { transform: scale(0.94); }

.hex.is-cleared,
.hex:disabled {
  background: #1a1d27;
  background-image: none;
  filter: none;
}

.hex.is-shake { animation: shake 180ms linear; }
.hex.is-burst { animation: hex-burst 280ms ease-out; }

.combo.is-pop { animation: combo-pop 320ms ease-out; }

.app.is-joy { animation: joy 260ms ease-out; }
.app.is-joy-big { animation: joy-big 380ms ease-out; }

.fx {
  position: absolute;
  z-index: 3;
  width: 0;
  height: 0;
  pointer-events: none;
}

.fx-ring,
.fx-star,
.fx-spark {
  position: absolute;
  left: 0;
  top: 0;
  pointer-events: none;
}

.fx-ring {
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid var(--fx, #fff);
  border-radius: 50%;
  box-shadow: 0 0 12px var(--fx, #fff);
  animation: fx-ring 520ms ease-out forwards;
}

.fx-ring.is-big { animation: fx-ring-big 680ms ease-out forwards; }
.fx-ring.is-echo { animation-delay: 90ms; }

.fx-star {
  width: var(--size, 10px);
  height: var(--size, 10px);
  margin-left: calc(var(--size, 10px) / -2);
  margin-top: calc(var(--size, 10px) / -2);
  background: linear-gradient(180deg, #fff, var(--fx, #ffc14d));
  clip-path: polygon(
    50% 0,
    61% 35%,
    98% 35%,
    68% 57%,
    79% 91%,
    50% 70%,
    21% 91%,
    32% 57%,
    2% 35%,
    39% 35%
  );
  filter: drop-shadow(0 0 4px var(--fx, #fff));
  animation: fx-star 700ms cubic-bezier(0.16, 0.84, 0.32, 1) forwards;
  animation-delay: var(--delay, 0ms);
}

.fx-spark {
  width: 5px;
  height: 5px;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 0 8px var(--fx, #fff);
  animation: fx-spark 520ms ease-out forwards;
  animation-delay: var(--delay, 0ms);
}

[data-color="crimson"] { --pattern: repeating-linear-gradient(180deg, transparent 0 7px, rgba(0, 0, 0, 0.22) 7px 9px); }
[data-color="amber"] { --pattern: radial-gradient(circle, rgba(0, 0, 0, 0.28) 1.4px, transparent 1.7px) 0 0 / 9px 9px; }
[data-color="lime"] { --pattern: repeating-linear-gradient(135deg, transparent 0 6px, rgba(0, 0, 0, 0.2) 6px 8px); }
[data-color="cyan"] { --pattern: repeating-radial-gradient(circle at 50% 45%, transparent 0 4px, rgba(0, 0, 0, 0.2) 4px 6px); }
[data-color="violet"] {
  --pattern:
    repeating-linear-gradient(45deg, transparent 0 6px, rgba(0, 0, 0, 0.2) 6px 7px),
    repeating-linear-gradient(-45deg, transparent 0 6px, rgba(0, 0, 0, 0.2) 6px 7px);
}
[data-color="ivory"] { --pattern: repeating-linear-gradient(90deg, transparent 0 8px, rgba(70, 50, 20, 0.28) 8px 10px); }

.signal-dock {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 22px calc(16px + env(safe-area-inset-bottom));
}

.signal {
  width: 68px;
  height: calc(68px * 1.1547);
  flex: none;
  filter: drop-shadow(0 0 16px color-mix(in srgb, var(--glow) 70%, transparent));
  animation: pulse 1.8s ease-in-out infinite;
}

.signal-kicker,
.signal-name,
.signal-hint { margin: 0; }

.signal-name {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.05;
}

.signal-hint { margin-top: 2px; color: var(--muted); }

.banner {
  position: absolute;
  z-index: 4;
  top: 12%;
  left: 50%;
  width: max-content;
  max-width: 90%;
  transform: translateX(-50%);
  text-align: center;
  pointer-events: none;
  text-shadow: 0 8px 24px rgba(0, 0, 0, 0.65);
}

.banner[hidden] { display: none; }

.banner-title {
  margin: 0;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.04em;
}

.banner-sub {
  margin: 4px 0 0;
  color: #e7e9f2;
  font-weight: 700;
}

.floater {
  position: absolute;
  z-index: 2;
  font-size: 14px;
  font-weight: 800;
  color: white;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  animation: rise 680ms ease-out forwards;
}

.shout {
  position: absolute;
  z-index: 4;
  font-size: 28px;
  font-weight: 900;
  letter-spacing: -0.05em;
  color: white;
  text-shadow:
    0 0 16px var(--fx, #ffc14d),
    0 8px 18px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  animation: shout-jump 720ms cubic-bezier(0.16, 0.84, 0.32, 1) forwards;
}

.shout.is-huge { font-size: 40px; }

.overlay {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(5, 6, 10, 0.72);
}

.overlay[hidden] { display: none; }

.sheet {
  width: min(100%, 360px);
  max-height: calc(100dvh - 48px);
  overflow: auto;
  padding: 26px 22px 18px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: #151824;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  user-select: text;
  -webkit-user-select: text;
}

.sheet h2 {
  margin: 4px 0 0;
  font-size: 40px;
  line-height: 1;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
}

.sheet-kicker { margin: 0; }
.sheet-kicker.is-best { color: var(--amber); }

.sheet-body {
  margin-top: 12px;
  color: #d5d8e4;
  line-height: 1.45;
}

.sheet-body[hidden] { display: none; }

.steps {
  margin: 0;
  padding-left: 1.1rem;
}

.steps li + li { margin-top: 10px; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 18px;
}

.stats[hidden] { display: none; }

.stat {
  padding: 12px 6px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  text-align: center;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stat strong {
  display: block;
  margin-top: 4px;
  font-size: 18px;
  font-variant-numeric: tabular-nums;
}

.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 16px;
}

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

.screen-play.is-locked .hex:not(:disabled) { cursor: default; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

@keyframes rise {
  from { opacity: 1; transform: translate(-50%, 0); }
  to { opacity: 0; transform: translate(-50%, -26px); }
}

@keyframes shout-jump {
  0% { opacity: 0; transform: translate(-50%, 10px) scale(0.35) rotate(-8deg); }
  32% { opacity: 1; transform: translate(-50%, -34px) scale(1.18) rotate(5deg); }
  100% { opacity: 0; transform: translate(-50%, -86px) scale(0.96) rotate(0deg); }
}

@keyframes fever-glow {
  from { opacity: 0.55; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1.08); }
}

@keyframes timer-panic {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.7); }
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.045); }
}

@keyframes hex-burst {
  0% { transform: scale(0.86); }
  45% { transform: scale(1.14); }
  100% { transform: scale(1); }
}

@keyframes combo-pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.45); }
  100% { transform: scale(1); }
}

@keyframes joy {
  0%, 100% { transform: translate(0, 0); }
  30% { transform: translate(1px, -2px); }
  65% { transform: translate(-1px, 1px); }
}

@keyframes joy-big {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-3px, 2px); }
  45% { transform: translate(3px, -2px); }
  70% { transform: translate(-2px, -1px); }
}

@keyframes fx-ring {
  from { transform: scale(0.35); opacity: 0.95; }
  to { transform: scale(3.4); opacity: 0; }
}

@keyframes fx-ring-big {
  from { transform: scale(0.4); opacity: 1; }
  to { transform: scale(5.4); opacity: 0; }
}

@keyframes fx-star {
  0% { transform: translate(0, 0) scale(0.2) rotate(0deg); opacity: 1; }
  55% { opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) scale(1) rotate(var(--rot)); opacity: 0; }
}

@keyframes fx-spark {
  from { transform: translate(0, 0) scale(1); opacity: 1; }
  to { transform: translate(var(--dx), var(--dy)) scale(0.15); opacity: 0; }
}

@media (max-height: 740px) {
  .board { --hex-w: clamp(42px, 16cqw, 54px); --hex-h: calc(var(--hex-w) * 1.1547005); }
  .logo { font-size: 4rem; }
  .signal { width: 56px; height: calc(56px * 1.1547); }
  .signal-name { font-size: 24px; }
}

@media (min-width: 760px) {
  body {
    display: grid;
    place-items: center;
  }

  .app {
    width: min(420px, 100vw);
    height: min(844px, calc(100dvh - 32px));
    min-height: 0;
    border: 1px solid var(--line);
    border-radius: 36px;
    box-shadow: 0 30px 90px rgba(0, 0, 0, 0.45);
  }
}

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