:root {
  --ink: #17202a;
  --muted: #667085;
  --line: #d9dee8;
  --soft: #f5f7fb;
  --accent: #1f7a5c;
  --accent-soft: #ddf4ea;
  --bad: #c23b3b;
  --bad-soft: #ffe8e8;
  --focus: #2f66d0;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: #ffffff;
  font-family:
    "Noto Sans SC",
    "PingFang SC",
    "Microsoft YaHei",
    Arial,
    sans-serif;
}

body.panel-hidden .app-shell {
  grid-template-columns: minmax(0, 1fr);
}

body.panel-hidden .control-panel,
body.immersive .control-panel {
  display: none;
}

body.panel-hidden .sheet {
  width: min(100%, 1180px);
}

body.immersive {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.floating-controls {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 40;
  display: none;
  gap: 8px;
}

body.panel-hidden .floating-controls,
body.immersive .floating-controls {
  display: flex;
}

.floating-controls button {
  min-height: 40px;
  border: 1px solid #b7c0ce;
  border-radius: 999px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.94);
  color: #223044;
  font-size: 14px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 10px 24px rgba(17, 24, 39, 0.08);
}

.floating-controls button:hover {
  border-color: #7c899c;
}

.victory-layer {
  position: fixed;
  inset: 0;
  z-index: 60;
  pointer-events: none;
  display: grid;
  place-items: center;
}

.victory-layer[hidden] {
  display: none;
}

#confettiCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.victory-message {
  position: relative;
  display: grid;
  gap: 8px;
  min-width: min(86vw, 420px);
  padding: 24px 30px;
  border: 2px solid #77bd9d;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  color: #0f5138;
  text-align: center;
  box-shadow: 0 18px 45px rgba(17, 24, 39, 0.16);
  animation: celebration-pop 420ms ease-out both;
  pointer-events: auto;
}

.victory-message strong {
  font-size: clamp(32px, 5vw, 54px);
  line-height: 1.08;
  font-weight: 900;
}

.victory-message span {
  color: #344054;
  font-size: clamp(18px, 3vw, 26px);
  font-weight: 900;
}

.audio-replay-button {
  justify-self: center;
  min-height: 44px;
  border: 1px solid #1f7a5c;
  border-radius: 999px;
  padding: 0 18px;
  background: #1f7a5c;
  color: #fff;
  font-size: 16px;
  font-weight: 900;
  cursor: pointer;
}

.audio-replay-button:hover {
  background: #176348;
}

@keyframes celebration-pop {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.92);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 28px;
  padding: 28px;
  background: #fff;
}

body.immersive .app-shell {
  min-height: 100dvh;
  height: 100dvh;
  display: block;
  padding: clamp(8px, 2vmin, 18px);
}

.maze-stage {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

body.immersive .maze-stage {
  height: 100%;
  align-items: center;
}

.sheet {
  width: min(100%, 980px);
  background: #fff;
  padding: clamp(18px, 3vw, 38px);
  border: 1px solid var(--line);
  border-radius: 8px;
}

body.immersive .sheet {
  width: min(100%, 1180px);
  max-height: calc(100dvh - 18px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 0;
  padding: clamp(8px, 2vmin, 18px);
}

.sheet-header {
  text-align: center;
  margin-bottom: clamp(16px, 2.5vw, 28px);
}

body.immersive .sheet-header {
  margin-bottom: clamp(8px, 2vmin, 16px);
}

.kicker {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
}

h1 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1.16;
  font-weight: 900;
  letter-spacing: 0;
}

body.immersive h1 {
  font-size: clamp(24px, 4.3vmin, 42px);
}

.maze-wrap {
  --grid-size: 8;
  --grid-gap: clamp(8px, 1vw, 12px);
  position: relative;
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 26px;
}

body.immersive .maze-wrap {
  width: min(100%, calc(100dvh - 136px));
  padding: clamp(12px, 2vmin, 22px);
}

.maze-grid {
  display: grid;
  grid-template-columns: repeat(var(--grid-size), minmax(0, 1fr));
  gap: var(--grid-gap);
  width: 100%;
  touch-action: none;
  user-select: none;
}

.cell {
  appearance: none;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 2px solid #aeb8c7;
  border-radius: 50%;
  background: #fff;
  color: #111827;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(24px, 4vw, 44px);
  font-weight: 900;
  line-height: 1;
  cursor: pointer;
  transition:
    background 120ms ease,
    border-color 120ms ease,
    transform 120ms ease,
    color 120ms ease;
}

.cell:focus-visible {
  outline: 4px solid rgba(47, 102, 208, 0.28);
  outline-offset: 3px;
}

.cell.selected {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #0f5138;
  transform: scale(1.04);
}

.cell.design-empty {
  color: transparent;
}

.cell.design-path {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #0f5138;
}

.cell.design-head {
  box-shadow: 0 0 0 4px rgba(31, 122, 92, 0.18);
  transform: scale(1.04);
}

.cell.design-end {
  border-color: #17202a;
}

.cell.mistake {
  background: var(--bad-soft);
  border-color: var(--bad);
  color: var(--bad);
}

.cell.next-target {
  box-shadow: 0 0 0 4px rgba(31, 122, 92, 0.14);
}

.corner-label {
  position: absolute;
  z-index: 1;
  color: #344054;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
}

.start-label {
  left: 0;
  top: 0;
}

.exit-label {
  right: 0;
  bottom: 0;
}

.maze-wrap.scheme-b .start-label {
  top: auto;
  bottom: 0;
}

.maze-wrap.scheme-b .exit-label {
  top: 0;
  bottom: auto;
}

.control-panel {
  align-self: start;
  display: grid;
  gap: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  position: sticky;
  top: 20px;
}

.control-group {
  display: grid;
  gap: 9px;
}

.control-group label,
.control-label {
  color: #344054;
  font-size: 14px;
  font-weight: 800;
}

.digit-picker input {
  width: 100%;
  height: 46px;
  border: 1px solid #b7c0ce;
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  font-size: 22px;
  font-weight: 900;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  border: 1px solid #c9d2df;
  border-radius: 8px;
  background: #fff;
}

.segment {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #344054;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
}

.segment.active {
  background: #17202a;
  color: #fff;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.actions button {
  min-height: 44px;
  border: 1px solid #b7c0ce;
  border-radius: 8px;
  background: #fff;
  color: #223044;
  font-weight: 800;
  cursor: pointer;
}

.actions button:hover {
  border-color: #7c899c;
}

.actions button:disabled {
  cursor: not-allowed;
  opacity: 0.46;
}

.actions .primary-action {
  grid-column: 1 / -1;
  background: #17202a;
  border-color: #17202a;
  color: #fff;
}

.status {
  min-height: 50px;
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid #c9d2df;
  border-radius: 8px;
  background: #fff;
  color: #223044;
  font-weight: 800;
  line-height: 1.35;
}

.status.success {
  border-color: #74b99d;
  background: var(--accent-soft);
  color: #0f5138;
}

.status.error {
  border-color: #e19a9a;
  background: var(--bad-soft);
  color: #8f2525;
}

.check-panel {
  border-top: 1px solid var(--line);
  padding-top: 16px;
}

.check-panel h2 {
  margin: 0 0 10px;
  font-size: 16px;
  line-height: 1.25;
}

.check-panel ul {
  list-style: none;
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 0;
}

.check-panel li {
  display: grid;
  grid-template-columns: 18px 1fr;
  align-items: start;
  gap: 8px;
  color: #344054;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.check-panel li::before {
  content: "";
  width: 13px;
  height: 13px;
  margin-top: 2px;
  border-radius: 50%;
  background: #1f7a5c;
}

.check-panel li.failed::before {
  background: var(--bad);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
    padding: 16px;
    gap: 18px;
  }

  .control-panel {
    position: static;
    order: -1;
  }

  .maze-wrap {
    padding: 20px;
  }

  body.immersive .maze-wrap {
    width: min(100%, calc(100dvh - 118px));
  }
}

@media (max-width: 620px) {
  .floating-controls {
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    justify-content: flex-end;
  }

  .floating-controls button {
    min-height: 36px;
    padding: 0 10px;
    font-size: 12px;
  }

  .sheet {
    padding: 16px 10px 18px;
    border: 0;
  }

  .maze-wrap {
    --grid-gap: 6px;
    padding: 18px 8px;
  }

  .maze-grid {
    gap: 6px;
  }

  .cell {
    border-width: 1.5px;
    font-size: clamp(20px, 6vw, 32px);
  }

  .corner-label {
    font-size: 12px;
    padding: 3px 8px;
  }

  .victory-message {
    padding: 20px;
  }
}

@media print {
  @page {
    size: auto;
    margin: 10mm;
  }

  body {
    background: #fff;
  }

  .app-shell {
    display: block;
    min-height: auto;
    padding: 0;
  }

  .control-panel {
    display: none;
  }

  .floating-controls,
  .victory-layer {
    display: none;
  }

  .sheet {
    width: 100%;
    max-width: none;
    border: 0;
    padding: 0;
  }

  .maze-wrap {
    --grid-gap: 10px;
  }

  .cell,
  .cell.selected,
  .cell.design-path,
  .cell.design-head,
  .cell.design-end,
  .cell.next-target,
  .cell.mistake {
    background: #fff;
    border-color: #8f98a6;
    color: #111827;
    box-shadow: none;
    transform: none;
  }
}
