:root {
  color-scheme: light;
  --ink: #403833;
  --muted: #756a60;
  --panel: rgba(250, 246, 236, 0.94);
  --paper: #fffaf0;
  --line: #cdbfaa;
  --pink: #a65363;
  --mint: #628f83;
  --sky: #587f9d;
  --lemon: #c19a4b;
  --lavender: #74649a;
  --shadow: rgba(64, 56, 51, 0.14);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: ui-rounded, "SF Pro Rounded", "Noto Sans TC", "PingFang TC", system-ui, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(60, 44, 63, 0.055) 1px, transparent 1px) 0 0 / 34px 34px,
    linear-gradient(0deg, rgba(60, 44, 63, 0.045) 1px, transparent 1px) 0 0 / 34px 34px,
    linear-gradient(180deg, #f5eedf 0%, #fbf7ed 58%, #eee4d5 100%);
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(250, 246, 236, 0.94);
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(71, 51, 77, 0.08);
  transition:
    transform 140ms ease,
    border-color 140ms ease,
    box-shadow 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: rgba(98, 143, 131, 0.85);
  box-shadow: 0 5px 0 rgba(71, 51, 77, 0.1);
}

button:active {
  transform: translateY(1px);
  box-shadow: 0 1px 0 rgba(71, 51, 77, 0.1);
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.game-panel {
  display: grid;
  gap: 14px;
}

.top-bar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.6rem, 4vw, 2.35rem);
  line-height: 1.05;
  letter-spacing: 0;
  text-shadow:
    2px 2px 0 rgba(250, 246, 236, 0.95),
    0 8px 22px rgba(64, 56, 51, 0.12);
}

.top-bar p {
  margin-top: 6px;
  color: var(--muted);
}

.score-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(98px, 1fr));
  gap: 8px;
  min-width: min(460px, 100%);
}

.score-strip span {
  display: grid;
  place-items: center;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(250, 246, 236, 0.86);
  font-weight: 800;
  white-space: nowrap;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 14px;
  align-items: start;
}

.stage-wrap {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
}

canvas {
  width: min(100%, 1120px);
  height: auto;
  aspect-ratio: 16 / 9;
  display: block;
  border: 2px solid rgba(68, 49, 72, 0.9);
  border-radius: 8px;
  background: #f5eedf;
  filter: none;
  box-shadow:
    0 20px 40px var(--shadow),
    0 0 0 8px rgba(250, 246, 236, 0.72);
  touch-action: none;
}

.side-panel {
  display: grid;
  gap: 12px;
}

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

.button-grid .primary-action {
  grid-column: span 2;
  background: rgba(166, 83, 99, 0.18);
  border-color: rgba(64, 56, 51, 0.35);
  color: var(--ink);
  font-weight: 900;
}

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

.mobile-controls button {
  min-height: 54px;
  font-size: 1.35rem;
  font-weight: 900;
}

.legend,
.leaderboard {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 24px rgba(64, 56, 51, 0.08);
}

.legend h2,
.leaderboard h2 {
  margin-bottom: 9px;
  font-size: 1rem;
}

.legend ul,
.leaderboard ol {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: grid;
  gap: 8px;
}

.legend li,
.leaderboard li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 32px;
  padding: 7px 8px;
  border-radius: 8px;
  background: rgba(250, 246, 236, 0.72);
}

.legend li {
  justify-content: flex-start;
}

.chip {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  flex: 0 0 auto;
  border: 2px solid rgba(250, 246, 236, 0.9);
  box-shadow: 0 2px 0 rgba(64, 56, 51, 0.12);
}

.chip.wide {
  background: var(--mint);
}

.chip.split {
  background: var(--lavender);
}

.chip.life {
  background: var(--pink);
}

.score-form {
  position: absolute;
  inset: auto auto 34px 50%;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 44px));
  padding: 16px;
  border: 2px solid rgba(64, 56, 51, 0.42);
  border-radius: 8px;
  background: rgba(250, 246, 236, 0.96);
  box-shadow: 0 18px 34px rgba(64, 56, 51, 0.16);
  z-index: 3;
}

.score-form h2 {
  font-size: 1.25rem;
}

.score-form p {
  margin-top: 5px;
  color: var(--muted);
}

.score-form label {
  display: block;
  margin: 12px 0 6px;
  color: var(--muted);
  font-weight: 800;
}

.name-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px;
  gap: 8px;
}

input {
  min-width: 0;
  min-height: 44px;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffaf0;
  outline: none;
}

input:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 3px rgba(98, 143, 131, 0.22);
}

.hidden {
  display: none;
}

@media (max-width: 980px) {
  .top-bar,
  .play-layout {
    grid-template-columns: 1fr;
  }

  .top-bar {
    display: grid;
    align-items: start;
  }

  .score-strip {
    min-width: 0;
  }

  .play-layout {
    display: grid;
  }

  canvas {
    width: 100%;
  }

  .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .button-grid,
  .mobile-controls {
    align-self: start;
  }
}

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

  .score-strip,
  .side-panel {
    grid-template-columns: 1fr;
  }

  .button-grid .primary-action {
    grid-column: span 1;
  }

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