:root {
  color-scheme: light;
  --ink: #1e2630;
  --muted: #69727c;
  --paper: #fffdf7;
  --paper-2: #f4f8f5;
  --line: #d8dfd9;
  --sky: #78d6e8;
  --blue: #2f5f83;
  --green: #21865d;
  --green-dark: #156146;
  --gold: #f1bd42;
  --coral: #e76645;
  --red: #c84239;
  --focus: #245cff;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(160deg, rgba(120, 214, 232, 0.32), rgba(241, 189, 66, 0.2)),
    linear-gradient(180deg, #fffdf7 0%, #e9f3ee 100%);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

button:focus-visible,
input:focus-visible,
canvas:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}

.app {
  width: min(1120px, calc(100vw - 28px));
  min-height: 100svh;
  margin: 0 auto;
  padding: 22px 0;
  display: grid;
  grid-template-columns: minmax(320px, 560px) minmax(260px, 330px);
  gap: 18px;
  align-items: start;
  justify-content: center;
}

.game-panel,
.leader-panel {
  overflow: hidden;
  border: 1px solid rgba(30, 38, 48, 0.12);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.9);
  box-shadow: 0 18px 48px rgba(47, 95, 131, 0.16);
}

.topbar,
.leader-head {
  min-width: 0;
  padding: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.mark {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 8px;
  border: 2px solid rgba(30, 38, 48, 0.18);
  background:
    radial-gradient(circle at 68% 36%, #1e2630 0 3px, transparent 4px),
    radial-gradient(ellipse at 42% 60%, var(--gold) 0 13px, transparent 14px),
    linear-gradient(140deg, var(--coral), #f5ce5a);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.08rem;
  line-height: 1.12;
  letter-spacing: 0;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.toolbar,
.actions,
.form-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-button,
.primary,
.secondary,
.text-button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 850;
  letter-spacing: 0;
}

.tool-button {
  padding: 0 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  color: #ffffff;
  background: var(--blue);
}

.tool-button[aria-pressed="true"] {
  background: var(--red);
}

.stage {
  position: relative;
  width: min(100%, 560px);
  margin: 0 auto;
  aspect-ratio: 432 / 640;
  border-top: 1px solid rgba(30, 38, 48, 0.12);
  background: var(--sky);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

.score-box {
  position: absolute;
  top: 13px;
  left: 13px;
  min-width: 82px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.38);
  border-radius: 8px;
  color: #ffffff;
  background: rgba(30, 38, 48, 0.58);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(12px);
}

.score-box span {
  display: block;
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.68rem;
  font-weight: 900;
  line-height: 1;
  text-transform: uppercase;
}

.score-box strong {
  display: block;
  margin-top: 4px;
  font-size: 2rem;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(30, 38, 48, 0.22);
}

.overlay[hidden] {
  display: none;
}

.dialog {
  width: min(100%, 336px);
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.56);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.94);
  box-shadow: 0 18px 44px rgba(30, 38, 48, 0.24);
  backdrop-filter: blur(14px);
}

.eyebrow {
  color: var(--green-dark);
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.dialog h2,
.leader-head h2 {
  margin-top: 4px;
  font-size: 1.55rem;
  line-height: 1.04;
  letter-spacing: 0;
}

#overlayText {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.96rem;
  line-height: 1.45;
}

.score-form {
  margin-top: 16px;
}

.score-form label {
  display: block;
  margin-bottom: 7px;
  color: var(--ink);
  font-weight: 850;
}

input {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #ffffff;
  font-weight: 750;
}

.actions {
  margin-top: 16px;
  flex-wrap: wrap;
}

.primary,
.secondary,
.text-button {
  padding: 0 14px;
}

.primary {
  color: #ffffff;
  background: var(--green);
}

.secondary {
  color: var(--green-dark);
  border-color: rgba(33, 134, 93, 0.28);
  background: rgba(33, 134, 93, 0.1);
}

.text-button {
  color: var(--red);
  border-color: rgba(200, 66, 57, 0.2);
  background: rgba(200, 66, 57, 0.08);
}

.leader-panel {
  padding-bottom: 12px;
}

.leaderboard {
  min-height: 420px;
  margin: 0;
  padding: 0 14px 2px 44px;
}

.leaderboard li {
  margin: 0 0 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper-2);
}

.leader-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 850;
}

.leader-name {
  overflow-wrap: anywhere;
}

.leader-score {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
}

.empty {
  margin: 0 14px;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.56);
}

@media (max-width: 820px) {
  .app {
    grid-template-columns: minmax(0, 560px);
    padding: 14px 0;
  }

  .leaderboard {
    min-height: 0;
  }
}

@media (max-width: 520px) {
  .app {
    width: 100%;
    padding: 0;
    gap: 0;
  }

  .game-panel,
  .leader-panel {
    border-width: 0 0 1px;
    border-radius: 0;
    box-shadow: none;
  }

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

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .tool-button {
    min-width: 92px;
  }

  .stage {
    width: 100%;
  }
}
