:root {
  color-scheme: dark;
  --bg: #06172f;
  --bg-soft: #0a2343;
  --panel: rgba(255, 255, 255, 0.08);
  --panel-strong: rgba(255, 255, 255, 0.14);
  --line: rgba(255, 255, 255, 0.14);
  --text: #f5fbff;
  --muted: #b6cae0;
  --accent: #22d3c5;
  --accent-dark: #109d98;
  --problem: #ffffff;
  --question: #c9fbff;
  --help: #ffb443;
  --help-dark: #8b4d00;
  --danger: #ff6b7a;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.34);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow-x: hidden;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 10%, rgba(34, 211, 197, 0.18), transparent 28%),
    linear-gradient(160deg, #06172f 0%, #071d39 46%, #041126 100%);
}

button {
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
  touch-action: manipulation;
}

.app {
  width: min(100vw, 520px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  display: grid;
}

.screen {
  display: none;
  min-height: calc(100dvh - 36px);
  align-content: center;
}

.screen-active {
  display: grid;
}

#game-screen {
  align-content: stretch;
  grid-template-rows: auto 1fr auto auto;
  gap: 12px;
}

.brand-mark {
  width: 86px;
  height: 86px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #06223d;
  background: linear-gradient(145deg, #d7fbff, var(--accent));
  box-shadow: 0 16px 42px rgba(34, 211, 197, 0.34);
  font-size: 48px;
  font-weight: 900;
}

.brand-mark.small {
  width: 62px;
  height: 62px;
  margin-bottom: 14px;
  font-size: 34px;
}

.eyebrow,
.best-line,
.hud-label,
.falling-label {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 8px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 12px;
  font-weight: 800;
}

h1,
h2 {
  margin: 0;
  text-align: center;
  line-height: 1.04;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(40px, 14vw, 66px);
}

h2 {
  font-size: clamp(30px, 9vw, 46px);
}

.subtitle {
  margin: 16px auto 0;
  max-width: 360px;
  text-align: center;
  color: #d9f8ff;
  font-size: 18px;
  line-height: 1.45;
}

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 54px;
  margin-top: 28px;
  border-radius: 14px;
  font-weight: 900;
  box-shadow: var(--shadow);
}

.primary-button {
  background: linear-gradient(135deg, var(--accent), #4ce3a4);
  color: #05223b;
}

.secondary-button {
  margin-top: 10px;
  color: #dffcff;
  background: var(--panel-strong);
  border: 1px solid var(--line);
}

.secondary-button.compact {
  min-height: 48px;
  margin-top: 12px;
  box-shadow: none;
}

.best-line {
  margin: 18px 0 0;
  text-align: center;
}

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

.hud > div {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.hud-label {
  display: block;
  margin-bottom: 3px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.hud strong {
  display: block;
  font-size: 24px;
  line-height: 1;
}

.board-shell {
  min-height: 0;
  padding: 12px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.board-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  font-weight: 900;
}

.falling-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
}

.board {
  --cols: 7;
  --rows: 12;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  gap: 5px;
  height: min(62dvh, 660px);
  min-height: 390px;
  padding: 7px;
  border-radius: 16px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    rgba(3, 14, 33, 0.68);
  background-size: calc(100% / var(--cols)) calc(100% / var(--rows));
  border: 1px solid rgba(255, 255, 255, 0.11);
}

.cell {
  min-width: 0;
  min-height: 0;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.025);
}

.card {
  position: relative;
  display: grid;
  place-items: center;
  padding: 4px;
  border-radius: 9px;
  color: #0c233b;
  font-size: clamp(9px, 2.4vw, 12px);
  font-weight: 900;
  line-height: 1.05;
  text-align: center;
  overflow-wrap: anywhere;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.18);
  animation: pop 140ms ease-out;
}

.card.problem {
  background: var(--problem);
}

.card.question {
  background: var(--question);
  color: #05324c;
  font-size: clamp(18px, 6vw, 30px);
}

.card.help {
  background: linear-gradient(145deg, #ffd36d, var(--help));
  color: var(--help-dark);
}

.card.active {
  outline: 3px solid rgba(34, 211, 197, 0.74);
  outline-offset: -2px;
}

.card.clear {
  animation: clear 220ms ease-in forwards;
}

.hint {
  min-height: 48px;
  margin: 0;
  padding: 12px 14px;
  border-radius: 14px;
  color: #eafcff;
  background: rgba(34, 211, 197, 0.12);
  border: 1px solid rgba(34, 211, 197, 0.24);
  line-height: 1.25;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.control-button {
  min-height: 58px;
  border-radius: 16px;
  color: #06223d;
  background: #e8fdff;
  font-size: 30px;
  font-weight: 900;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.22);
}

.control-down {
  background: var(--accent);
}

.end-actions {
  margin-top: 8px;
}

.help-panel {
  margin-top: 18px;
  padding: 14px;
  border-radius: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
}

.help-panel p {
  margin: 0 0 12px;
  color: #e7faff;
  line-height: 1.35;
}

.help-grid {
  display: grid;
  gap: 8px;
}

.help-grid button {
  min-height: 44px;
  border-radius: 12px;
  color: #05223b;
  background: #ffffff;
  font-weight: 900;
}

@keyframes pop {
  from {
    transform: scale(0.88);
    opacity: 0.45;
  }
}

@keyframes clear {
  to {
    transform: scale(0.72);
    opacity: 0;
  }
}

@media (max-height: 700px) {
  .app {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .board {
    height: 56dvh;
    min-height: 330px;
  }

  .hint {
    min-height: 40px;
    padding-block: 9px;
  }

  .control-button {
    min-height: 48px;
  }
}
