:root {
  color-scheme: light;
  --bg: #f5f1e9;
  --ink: #23211d;
  --muted: #6f695f;
  --line: #d9d0c3;
  --panel: #fffaf1;
  --panel-strong: #fff4df;
  --accent: #c44b37;
  --accent-2: #197b6c;
  --accent-3: #2d5f9a;
  --shadow: 0 16px 38px rgba(60, 44, 24, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(25, 123, 108, 0.08), transparent 36%),
    linear-gradient(315deg, rgba(196, 75, 55, 0.08), transparent 34%),
    var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

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

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

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto minmax(170px, auto);
  gap: 16px;
  align-items: center;
  margin-bottom: 16px;
}

.brand,
.stats,
.timer-card,
.level-panel,
.play-area,
.board-card,
.admin-panel {
  border: 1px solid rgba(142, 113, 78, 0.24);
  background: rgba(255, 250, 241, 0.92);
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 12px 16px;
  border-radius: 8px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 24%, #fff7d6 0 12%, transparent 13%),
    conic-gradient(from 35deg, var(--accent), #e2ae54, var(--accent-2), var(--accent-3), var(--accent));
}

.brand h1,
.round-info h2,
.level-panel h2,
.message-dialog h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: clamp(24px, 3vw, 36px);
  line-height: 1;
}

.brand p,
.round-info p,
.stat span,
.timer-label,
.message-dialog p {
  margin: 0;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  gap: 1px;
  overflow: hidden;
  border-radius: 8px;
}

.stat {
  min-width: 96px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.48);
}

.stat span,
.timer-label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
}

.stat strong {
  font-size: 20px;
}

.timer-card {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 72px;
  padding: 12px 16px;
  border-radius: 8px;
}

#timeText {
  display: block;
  font-size: 24px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hourglass {
  position: relative;
  width: 32px;
  height: 46px;
  border: 3px solid var(--accent-3);
  border-top-width: 4px;
  border-bottom-width: 4px;
  border-radius: 4px;
  transform-origin: center;
  animation: flip 4s linear infinite;
}

.hourglass::before,
.hourglass::after {
  content: "";
  position: absolute;
  left: 4px;
  right: 4px;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
}

.hourglass::before {
  top: 4px;
  border-top: 15px solid #dca145;
}

.hourglass::after {
  bottom: 4px;
  border-bottom: 15px solid #dca145;
}

.hourglass span {
  position: absolute;
  left: 13px;
  top: 16px;
  width: 3px;
  height: 14px;
  background: #dca145;
  border-radius: 2px;
}

@keyframes flip {
  0%,
  45% {
    transform: rotate(0deg);
  }
  50%,
  95% {
    transform: rotate(180deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

.game-panel {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.level-panel,
.play-area {
  border-radius: 8px;
}

.level-panel {
  position: sticky;
  top: 16px;
  padding: 14px;
}

.panel-heading,
.round-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.level-panel h2 {
  font-size: 18px;
}

.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #efe2ce;
  font-size: 20px;
  line-height: 1;
}

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

.level-button {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #fff6e6;
  border: 1px solid var(--line);
  font-weight: 800;
}

.level-button.is-active {
  color: #fff;
  background: var(--accent-2);
  border-color: var(--accent-2);
}

.level-button.is-complete::after {
  content: "";
  position: absolute;
  right: 7px;
  top: 7px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.play-area {
  min-width: 0;
  padding: 14px;
}

.round-info {
  margin-bottom: 12px;
}

.round-info h2 {
  font-size: clamp(20px, 2.4vw, 30px);
}

.round-info p {
  margin-top: 4px;
}

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

.actions button,
.dialog-actions button {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.actions button:first-child {
  background: var(--accent-3);
}

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

.board-card {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
  background: #1d1a15;
}

.board-label {
  position: absolute;
  left: 10px;
  top: 10px;
  z-index: 2;
  padding: 5px 9px;
  border-radius: 999px;
  background: rgba(255, 250, 241, 0.92);
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

canvas {
  display: block;
  width: 100%;
  aspect-ratio: 5 / 6;
  background: #211c18;
  touch-action: manipulation;
}

.progress-shell {
  height: 10px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4d8c5;
}

.progress-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--accent-2), #dca145, var(--accent));
  transform-origin: left;
  transition: transform 0.18s linear;
}

.message-dialog {
  width: min(420px, calc(100vw - 36px));
  border: 0;
  border-radius: 8px;
  padding: 24px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
}

.message-dialog::backdrop {
  background: rgba(26, 22, 18, 0.48);
}

.message-dialog h2 {
  font-size: 28px;
}

.message-dialog p {
  margin-top: 8px;
  line-height: 1.6;
}

.admin-panel {
  display: none;
  width: min(760px, 100%);
  margin: 16px 0 0 auto;
  padding: 14px;
  border-radius: 8px;
}

body.admin-enabled .admin-panel {
  display: grid;
  grid-template-columns: minmax(170px, 1fr) 130px 130px minmax(160px, 220px);
  align-items: end;
  gap: 10px;
}

.admin-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.admin-heading h2,
.admin-heading p {
  margin: 0;
}

.admin-heading h2 {
  font-size: 18px;
}

.admin-heading p,
.admin-select span {
  color: var(--muted);
  font-size: 12px;
}

.admin-heading > span {
  padding: 4px 7px;
  border-radius: 999px;
  background: #efe2ce;
  color: #684f35;
  font-size: 11px;
  font-weight: 800;
}

.admin-panel button,
.admin-select select {
  width: 100%;
  min-height: 40px;
  border-radius: 8px;
  font-weight: 800;
}

.admin-panel button {
  background: var(--accent-3);
  color: #fff;
}

.admin-panel button.is-active {
  background: var(--accent);
}

.admin-select {
  display: grid;
  gap: 5px;
}

.admin-select select {
  border: 1px solid var(--line);
  background: #fff8ea;
  color: var(--ink);
  padding: 0 10px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 18px;
}

.wrong-flash {
  animation: wrong 0.24s ease;
}

@keyframes wrong {
  0%,
  100% {
    transform: translateX(0);
  }
  35% {
    transform: translateX(-6px);
  }
  70% {
    transform: translateX(6px);
  }
}

@media (max-width: 980px) {
  .topbar,
  .game-panel {
    grid-template-columns: 1fr;
  }

  .level-panel {
    position: static;
  }

  .level-grid {
    grid-template-columns: repeat(10, minmax(38px, 1fr));
  }

  body.admin-enabled .admin-panel {
    width: 100%;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100vw - 16px, 680px);
    padding-top: 8px;
  }

  .topbar,
  .game-panel,
  .boards {
    gap: 10px;
  }

  .brand,
  .timer-card,
  .play-area,
  .level-panel,
  .admin-panel {
    box-shadow: none;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
  }

  .stat {
    min-width: 0;
    padding: 10px;
  }

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

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

  .actions {
    justify-content: stretch;
  }

  .actions button {
    flex: 1;
  }
}
