:root {
  --bg: #eef3fb;
  --bg-top: #f8fbff;
  --card: rgba(255, 255, 255, 0.86);
  --card-solid: #ffffff;
  --line: #d4deec;
  --line-strong: #bdd0e6;
  --text: #102541;
  --muted: #59708f;
  --accent: #2b61d6;
  --accent-strong: #214db0;
  --good: #1f975e;
  --bad: #c53b48;
  --shadow-soft: 0 10px 26px rgba(16, 37, 65, 0.08);
  --shadow-strong: 0 16px 32px rgba(16, 37, 65, 0.12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'IBM Plex Sans', sans-serif;
  color: var(--text);
  background:
    radial-gradient(560px 320px at 12% -12%, rgba(43, 97, 214, 0.14), transparent 72%),
    radial-gradient(540px 300px at 96% 10%, rgba(95, 145, 232, 0.14), transparent 70%),
    linear-gradient(180deg, var(--bg-top), var(--bg));
}

.app {
  max-width: 820px;
  margin: 0 auto;
  padding: 30px 18px 42px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

h1,
h2 {
  margin: 0;
  font-family: 'IBM Plex Mono', monospace;
}

h1 {
  font-size: clamp(2.1rem, 4vw, 3rem);
  letter-spacing: 0.01em;
}

h2 { font-size: 1.08rem; }

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 1.04rem;
  padding: 8px 10px;
  border-radius: 10px;
  transition: background 140ms ease, color 140ms ease;
}

.back-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.48);
}

.panel,
.hud > div {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(4px);
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.hud > div {
  padding: 12px;
  text-align: center;
}

.hud span {
  color: var(--muted);
  letter-spacing: 0.12em;
  font-size: 0.78rem;
  font-weight: 600;
}

.hud strong {
  display: block;
  margin-top: 6px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 2rem;
  line-height: 1;
}

.panel {
  padding: 16px;
  margin-bottom: 12px;
}

.play {
  padding-top: 18px;
  padding-bottom: 14px;
}

.problem {
  min-height: 112px;
  display: grid;
  place-items: center;
  font-family: 'IBM Plex Mono', monospace;
  font-size: clamp(2.6rem, 9vw, 4.2rem);
  letter-spacing: 0.01em;
}

#answerForm {
  display: none;
}

input,
button {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: var(--card-solid);
  color: var(--text);
  padding: 12px 14px;
  font-size: 1.08rem;
}

input {
  font-weight: 500;
}

input:focus,
button:focus {
  outline: none;
  border-color: #7fa4df;
  box-shadow: 0 0 0 3px rgba(43, 97, 214, 0.14);
}

button {
  cursor: pointer;
  font-weight: 700;
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  color: #fff;
  transition: transform 120ms ease, box-shadow 120ms ease;
}

button:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(33, 77, 176, 0.28);
}

button.ghost {
  background: #f4f8ff;
  color: #2e4b74;
  border-color: #c6d7ef;
}

button.small {
  width: auto;
  padding: 8px 12px;
  font-size: 0.9rem;
}

.feedback {
  margin: 10px 0 0;
  min-height: 1.3rem;
  color: var(--muted);
  font-size: 1rem;
}

.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }

.controls {
  box-shadow: var(--shadow-strong);
}

.inputs {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 12px;
}

.inputs label {
  color: var(--muted);
  font-size: 0.98rem;
  display: grid;
  gap: 6px;
}

.ops {
  display: grid;
  grid-template-columns: repeat(4, minmax(62px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.op-chip {
  position: relative;
  display: block;
}

.op-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.op-chip span {
  display: block;
  text-align: center;
  padding: 11px 0;
  border-radius: 14px;
  border: 1px solid #b8ccea;
  color: #3a567d;
  font-weight: 700;
  font-size: 1.35rem;
  user-select: none;
  background: #f9fbff;
  transition: border-color 140ms ease, color 140ms ease, background 140ms ease, box-shadow 140ms ease;
}

.op-chip input:checked + span {
  background: linear-gradient(180deg, #eaf2ff, #dce9ff);
  border-color: #88abe1;
  color: #173f78;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.8);
}

.actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}

#startBtn {
  min-height: 56px;
  font-size: 1.1rem;
}

.leaderboard-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.leaderboard-list {
  margin: 0;
  padding-left: 24px;
}

.leaderboard-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 7px 0;
  font-size: 1rem;
}

.leaderboard-list li strong {
  font-family: 'IBM Plex Mono', monospace;
}

.leaderboard-list .empty {
  list-style: none;
  margin-left: -24px;
  color: var(--muted);
}

.submit-row {
  margin-top: 12px;
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr auto;
}

.submit-row button {
  width: auto;
  min-width: 132px;
}

@media (max-width: 680px) {
  .app {
    padding: 20px 12px 28px;
  }

  .top {
    align-items: flex-start;
  }

  .inputs,
  .submit-row {
    grid-template-columns: 1fr;
  }

  .submit-row button {
    width: 100%;
  }
}

body.playing-mode .top,
body.playing-mode .controls,
body.playing-mode .leaderboard {
  display: none;
}

body.playing-mode .app {
  max-width: 860px;
  min-height: 100vh;
  display: grid;
  align-content: center;
  gap: 16px;
}

body.playing-mode .hud {
  max-width: 460px;
  margin: 0 auto;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
}

body.playing-mode .hud > div:nth-child(3) {
  display: none;
}

body.playing-mode .hud strong {
  font-size: 2.2rem;
}

body.playing-mode .play {
  max-width: 700px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 18px 16px;
}

body.playing-mode #answerForm {
  display: block;
}

body.playing-mode .problem {
  min-height: 132px;
  font-size: clamp(3rem, 12vw, 5.2rem);
}

body.playing-mode #answerInput {
  font-size: 1.65rem;
  text-align: center;
  font-family: 'IBM Plex Mono', monospace;
  padding-top: 14px;
  padding-bottom: 14px;
}
