:root {
  color-scheme: light;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background: #281711;
  color: #251b16;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% 0%, rgba(242, 198, 92, 0.36), transparent 24rem),
    radial-gradient(circle at 16% 18%, rgba(69, 148, 122, 0.28), transparent 22rem),
    radial-gradient(circle at 84% 22%, rgba(145, 47, 36, 0.24), transparent 24rem),
    linear-gradient(160deg, #20110d 0%, #5f301f 46%, #c88743 100%);
}

.game-shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 14px 0 24px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 18px;
  margin-bottom: 12px;
  text-align: center;
  color: #fff0c4;
}

.eyebrow {
  margin: 0 0 3px;
  color: #f8d77c;
  font-size: 13px;
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  line-height: 1;
  color: #ffeab4;
  text-shadow:
    0 3px 0 rgba(74, 34, 18, 0.7),
    0 0 18px rgba(255, 211, 102, 0.32);
}

.stage-wrap {
  position: relative;
  overflow: hidden;
  border: 5px solid #1c0e0a;
  border-radius: 8px;
  background: #f6dfac;
  box-shadow:
    0 26px 58px rgba(18, 8, 5, 0.52),
    0 0 0 2px rgba(222, 170, 72, 0.42),
    0 0 0 6px rgba(64, 35, 20, 0.55),
    inset 0 0 0 2px rgba(255, 241, 176, 0.35);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  cursor: grab;
}

canvas:active {
  cursor: grabbing;
}

.time-badge {
  position: absolute;
  right: clamp(8px, 1.6vw, 18px);
  bottom: clamp(8px, 1.8vw, 16px);
  z-index: 2;
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  align-items: end;
  min-width: 94px;
  padding: 8px 10px 9px;
  border: 3px solid #23120d;
  border-radius: 8px;
  background:
    radial-gradient(circle at 28% 22%, rgba(255, 249, 196, 0.98), transparent 42%),
    linear-gradient(180deg, rgba(236, 184, 88, 0.98), rgba(139, 55, 31, 0.98)),
    #d88d3d;
  box-shadow:
    0 10px 24px rgba(44, 24, 13, 0.28),
    inset 0 2px 0 rgba(255, 255, 255, 0.72),
    inset 0 -4px 0 rgba(111, 54, 27, 0.22);
  color: #2b1710;
  pointer-events: auto;
  user-select: none;
  cursor: pointer;
}

.time-badge::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 1px solid rgba(92, 44, 20, 0.34);
  border-radius: 5px;
}

.time-label {
  grid-column: 1 / -1;
  position: relative;
  z-index: 1;
  color: #743020;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
}

.time-badge strong {
  position: relative;
  z-index: 1;
  margin-top: -2px;
  font-size: clamp(30px, 5vw, 42px);
  line-height: 0.95;
  font-weight: 1000;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 3px 0 rgba(255, 238, 172, 0.58);
}

.time-unit {
  position: relative;
  z-index: 1;
  padding: 0 0 3px 4px;
  color: #5b2c1d;
  font-size: 18px;
  font-weight: 1000;
}

.time-badge.is-warning {
  background:
    linear-gradient(180deg, rgba(255, 220, 159, 0.99), rgba(217, 57, 47, 0.98)),
    #e94c3d;
  color: #fff7d1;
  animation: time-pulse 0.7s ease-in-out infinite alternate;
}

.time-badge.is-warning .time-label,
.time-badge.is-warning .time-unit {
  color: #fff0bc;
}

.time-badge.is-warning strong {
  text-shadow: 0 3px 0 rgba(79, 18, 13, 0.55);
}

.time-badge.is-frozen {
  animation: none;
}

@keyframes time-pulse {
  from {
    transform: scale(1);
    box-shadow:
      0 10px 24px rgba(44, 24, 13, 0.28),
      inset 0 2px 0 rgba(255, 255, 255, 0.72),
      inset 0 -4px 0 rgba(111, 54, 27, 0.22);
  }
  to {
    transform: scale(1.045);
    box-shadow:
      0 12px 30px rgba(152, 33, 24, 0.42),
      0 0 0 5px rgba(255, 220, 112, 0.2),
      inset 0 2px 0 rgba(255, 255, 255, 0.72),
      inset 0 -4px 0 rgba(111, 54, 27, 0.22);
  }
}

.result-panel {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(360px, calc(100% - 36px));
  transform: translate(-50%, -50%);
  border: 4px solid #25140f;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 246, 205, 0.98), rgba(218, 145, 62, 0.98));
  padding: 18px;
  text-align: center;
  box-shadow:
    0 22px 54px rgba(22, 11, 7, 0.42),
    inset 0 2px 0 rgba(255, 255, 255, 0.48);
}

.result-panel strong {
  display: block;
  font-size: 30px;
}

.result-panel p {
  margin: 8px 0 16px;
  color: #5a3828;
  font-weight: 700;
}

.intro-panel,
.leaderboard-panel {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  width: 100vw;
  height: 100vh;
  padding: clamp(16px, 4vw, 42px);
  background:
    radial-gradient(circle at 50% 22%, rgba(255, 224, 136, 0.3), transparent 18rem),
    linear-gradient(180deg, rgba(28, 12, 8, 0.72), rgba(30, 12, 7, 0.84));
}

.intro-panel[hidden],
.leaderboard-panel[hidden] {
  display: none;
}

.intro-card,
.leaderboard-card {
  width: min(500px, 100%);
  border: 4px solid #25140f;
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(95, 38, 25, 0.08), transparent 16%, transparent 84%, rgba(95, 38, 25, 0.08)),
    linear-gradient(180deg, #fff0bd 0%, #e5b867 54%, #b96935 100%);
  padding: clamp(18px, 4vw, 28px);
  text-align: center;
  box-shadow:
    0 28px 70px rgba(13, 5, 3, 0.55),
    0 0 0 6px rgba(92, 47, 23, 0.32),
    inset 0 2px 0 rgba(255, 255, 255, 0.6),
    inset 0 -7px 0 rgba(93, 43, 24, 0.18);
}

.intro-kicker {
  margin: 0 0 6px;
  color: #8a3224;
  font-size: 13px;
  font-weight: 1000;
}

.intro-card h2,
.leaderboard-card h2 {
  margin: 0 0 12px;
  color: #2b1710;
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.15;
  text-shadow: 0 2px 0 rgba(255, 238, 174, 0.65);
}

.intro-card p {
  margin: 8px auto;
  max-width: 420px;
  color: #4d281b;
  font-size: 16px;
  line-height: 1.65;
  font-weight: 800;
}

.intro-card button {
  min-width: 118px;
  margin-top: 14px;
}

.leaderboard-card {
  width: min(540px, 100%);
}

.final-score {
  margin: 8px 0 14px;
  color: #4d281b;
  font-size: 17px;
  font-weight: 900;
}

.final-score strong {
  color: #8a2d20;
  font-size: 28px;
}

.leaderboard-form {
  margin: 14px 0;
}

.leaderboard-form label {
  display: block;
  margin-bottom: 6px;
  color: #5d2c1d;
  font-size: 13px;
  font-weight: 1000;
}

.leaderboard-entry {
  display: flex;
  gap: 8px;
}

.leaderboard-entry input {
  min-width: 0;
  flex: 1;
  border: 2px solid #2a140e;
  border-radius: 8px;
  background: rgba(255, 247, 209, 0.92);
  color: #2b1710;
  min-height: 40px;
  padding: 0 12px;
  font: inherit;
  font-weight: 900;
  outline: none;
  box-shadow: inset 0 2px 4px rgba(76, 33, 18, 0.18);
}

.leaderboard-list {
  display: grid;
  gap: 6px;
  max-height: 220px;
  margin: 12px 0 16px;
  padding: 0;
  list-style: none;
}

.leaderboard-list li {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(63, 29, 18, 0.34);
  border-radius: 8px;
  background: rgba(255, 244, 203, 0.46);
  padding: 7px 9px;
  color: #321d14;
  font-weight: 900;
}

.leaderboard-list .rank-score {
  color: #8a2d20;
  font-variant-numeric: tabular-nums;
}

.leaderboard-list .empty-score {
  grid-column: 1 / -1;
  color: #6a3926;
  text-align: center;
}

button {
  border: 2px solid #2a140e;
  border-radius: 8px;
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 245, 180, 0.78), transparent 34%),
    linear-gradient(180deg, #efc260 0%, #c9782f 56%, #82391f 100%);
  color: #241711;
  min-height: 40px;
  padding: 0 16px;
  font: inherit;
  font-weight: 900;
  box-shadow:
    0 4px 0 #4f2417,
    0 10px 18px rgba(35, 15, 8, 0.24),
    inset 0 1px 0 rgba(255, 245, 190, 0.58);
  cursor: pointer;
}

button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #8b5630;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

.hint {
  min-height: 42px;
  border: 2px solid rgba(46, 24, 15, 0.7);
  border-radius: 8px;
  background:
    linear-gradient(90deg, rgba(40, 91, 75, 0.12), transparent 18%, transparent 82%, rgba(40, 91, 75, 0.12)),
    linear-gradient(180deg, rgba(255, 243, 199, 0.96), rgba(218, 149, 73, 0.92));
  padding: 10px 12px;
  color: #4d281b;
  font-size: 15px;
  font-weight: 800;
  box-shadow:
    0 8px 18px rgba(31, 15, 9, 0.24),
    inset 0 1px 0 rgba(255, 250, 217, 0.68);
}

.buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: end;
}

.admin-controls[hidden] {
  display: none;
}

@media (max-width: 820px) {
  .topbar,
  .controls {
    align-items: stretch;
    flex-direction: column;
  }

  .time-badge {
    min-width: 86px;
    padding: 7px 9px 8px;
  }
}
