:root {
  --bg1: #f7f1d5;
  --bg2: #b9e3f2;
  --ink: #1f2a35;
  --accent: #ff7a18;
  --good: #1d9f5f;
  --bad: #cf3b2d;
  --card: rgba(255, 255, 255, 0.85);
  --soft-border: #c2d8eb;
  --shadow: 0 10px 24px rgba(33, 53, 71, 0.12);
  --radius: 20px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Verdana", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 0% 0%, #fff7cc 10%, transparent 70%),
    radial-gradient(1000px 500px at 100% 100%, #b3e9ff 10%, transparent 70%),
    linear-gradient(180deg, var(--bg1), var(--bg2));
  min-height: 100vh;
}

.app {
  max-width: 1000px;
  margin: 0 auto;
  padding: 12px;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  overflow: hidden;
}

.topbar-main {
  width: 100%;
  min-width: 0;
}

.hero-brand {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 70px;
  width: 100%;
  margin-bottom: 6px;
}

.brand-logo {
  display: block;
  width: 230px;
  height: auto;
  max-height: 114px;
  max-width: 100%;
  object-fit: contain;
  object-position: left center;
}

.controls,
.panel,
.game-wrap {
  background: var(--card);
  border-radius: 14px;
  padding: 10px;
  margin-bottom: 10px;
}

.hero-card {
  background: #ffffffee;
  border: 1px solid #eef4fa;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.hero-card::after {
  content: "";
  position: absolute;
  right: -24px;
  top: -24px;
  width: 110px;
  height: 110px;
  border-radius: 999px;
  background: radial-gradient(circle, #ffffff66 0%, #ffffff00 70%);
  pointer-events: none;
}

.hero-card::before {
  content: "";
  position: absolute;
  left: -16px;
  bottom: -22px;
  width: 120px;
  height: 80px;
  background: radial-gradient(circle, #ffe59a 0%, #ffe59a00 70%);
}

h1, h2 {
  margin: 0 0 8px;
}

.stats {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-weight: 700;
  position: relative;
  z-index: 1;
}

.controls,
.row,
.answer-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.ops-picker {
  display: flex;
  gap: 10px;
  align-items: center;
  background: #f2f8fc;
  border-radius: 10px;
  padding: 8px 10px;
}

.ops-picker label {
  display: flex;
  align-items: center;
  gap: 4px;
}

button,
input,
select {
  font: inherit;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #98a8b8;
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0;
  padding: 0;
  border: 1px solid #8fb3cf;
  border-radius: 6px;
  accent-color: #2a8fd2;
  flex: 0 0 auto;
}

button {
  background: #fff;
  cursor: pointer;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#gameCanvas {
  width: min(100%, 960px);
  height: auto;
  border-radius: 10px;
  border: 2px solid #7ea0ba;
  background: linear-gradient(180deg, #daf6ff, #e8f6d6);
  touch-action: manipulation;
  display: block;
  margin: 0 auto;
}

.canvas-shell {
  display: flex;
  align-items: center;
  justify-content: center;
}

.answer-display {
  min-width: 150px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #98a8b8;
  background: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.keypad {
  margin-top: 8px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.keypad button {
  min-height: 56px;
  font-size: 1.15rem;
  font-weight: 700;
}

.keypad .action {
  background: #f3f5f7;
}

.keypad .submit {
  background: var(--accent);
  color: #fff;
  border-color: #d8640f;
}

.keypad .wide {
  grid-column: span 2;
}

.message {
  min-height: 20px;
  margin: 8px 0 0;
  font-weight: 700;
}

.result-card {
  margin-top: 10px;
  border-radius: 14px;
  border: 2px solid #7ea0ba;
  background:
    radial-gradient(500px 200px at 10% 0%, #fff2c2 0%, transparent 75%),
    radial-gradient(400px 160px at 100% 100%, #d5f5ff 0%, transparent 75%),
    #fff;
  padding: 14px;
}

.result-card h2 {
  margin-bottom: 6px;
}

.result-card p {
  margin: 0 0 10px;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.result-grid div {
  border-radius: 10px;
  border: 1px solid #b2c5d6;
  background: #f8fcff;
  padding: 8px 10px;
}

.result-grid span {
  display: block;
  font-size: 0.86rem;
  opacity: 0.8;
}

.result-grid strong {
  font-size: 1.1rem;
}

.result-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.result-actions input {
  min-width: 220px;
  flex: 1;
}

#saveSnapshotBtn {
  background: var(--accent);
  border-color: #d8640f;
  color: #fff;
  width: auto;
}

#stopBtnTop {
  position: relative;
  z-index: 1;
  border: 2px solid var(--soft-border);
}

.message.good {
  color: var(--good);
}

.message.bad {
  color: var(--bad);
}

#leaderboard {
  margin: 8px 0 0;
  padding-left: 24px;
}

.footer {
  text-align: center;
  padding: 12px;
}

.footer p {
  margin: 4px 0;
}

body.is-playing {
  overflow: hidden;
}

body.is-playing .app {
  max-width: none;
  padding: 8px;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: max(8px, env(safe-area-inset-top));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

body.is-playing .hide-when-playing {
  display: none;
}

body.is-playing .topbar {
  margin-bottom: 0;
  padding: 8px 10px;
}

body.is-playing .hero-brand {
  display: none;
}

body.is-playing .topbar-main {
  display: flex;
  align-items: center;
}

body.is-playing .stats {
  width: 100%;
  gap: 10px;
  font-size: 0.98rem;
}

body.is-playing #playScreen {
  margin-bottom: 0;
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

body.is-playing .canvas-shell {
  flex: 1;
  min-height: 0;
}

body.is-playing #gameCanvas {
  width: auto;
  max-width: 100%;
  max-height: 100%;
}

body.is-playing .answer-bar {
  margin-top: 4px;
}

body.is-playing .answer-display {
  font-size: 1.05rem;
  padding: 8px 10px;
}

body.is-playing .keypad {
  margin-top: 6px;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
}

body.is-playing .keypad button {
  min-height: 48px;
  padding: 8px 10px;
  font-size: 1rem;
}

@media (max-width: 640px) {
  .app {
    padding: 8px;
  }

  button,
  input,
  select {
    width: 100%;
  }

  .row,
  .controls,
  .answer-bar {
    display: block;
  }

  .ops-picker {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .ops-picker label {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 8px;
    background: #fff;
  }

  .topbar {
    display: block;
  }

  .brand-logo {
    width: 190px;
    height: auto;
    max-height: 94px;
    max-width: 100%;
  }

  .topbar #stopBtnTop {
    margin-top: 8px;
    width: 100%;
  }

  body.is-playing .topbar #stopBtnTop {
    margin-top: 0;
    width: auto;
    min-width: 110px;
  }

  .keypad {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .result-grid {
    grid-template-columns: 1fr;
  }

  #saveSnapshotBtn {
    width: 100%;
  }
}
