:root {
  color-scheme: dark light;
  font-family: Inter, "Microsoft YaHei", system-ui, sans-serif;
  background: #0b0d0e;
  color: #e4ebe8;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
button, input { font: inherit; }
button { border: 0; letter-spacing: 0; cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid #d94b4b; outline-offset: 2px; }

.app {
  --surface: #131615;
  --surface-raised: #1b1e1c;
  --text: #f1f1ed;
  --muted: rgba(241,241,237,.52);
  --faint: rgba(241,241,237,.16);
  --overlay: rgba(0,0,0,.52);
  --selected-bg: #292c29;
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #0f1110;
  color: var(--text);
}
.app.theme-day {
  --surface: #ffffff;
  --surface-raised: #f1f1ed;
  --text: #181a19;
  --muted: rgba(24,26,25,.54);
  --faint: rgba(24,26,25,.16);
  --overlay: rgba(24,26,25,.24);
  --selected-bg: #e7e7e2;
  background: #f1f1ee;
}
#maze { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.app.wall { background: #241516; }
.app.wall::after {
  content: "";
  position: absolute;
  z-index: 5;
  inset: 0;
  background:
    linear-gradient(to bottom, rgba(217,75,75,.88), rgba(217,75,75,.2) 38%, transparent) top / 100% 42px no-repeat,
    linear-gradient(to top, rgba(217,75,75,.88), rgba(217,75,75,.2) 38%, transparent) bottom / 100% 42px no-repeat,
    linear-gradient(to right, rgba(217,75,75,.88), rgba(217,75,75,.2) 38%, transparent) left / 42px 100% no-repeat,
    linear-gradient(to left, rgba(217,75,75,.88), rgba(217,75,75,.2) 38%, transparent) right / 42px 100% no-repeat;
  box-shadow: inset 0 0 30px rgba(217,75,75,.22);
  pointer-events: none;
  animation: wall-flash .32s ease-out;
}

.topbar { position: absolute; z-index: 3; top: 18px; left: 18px; right: 18px; display: flex; align-items: center; justify-content: space-between; pointer-events: none; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.icon-button, .level-chip { border: 1px solid var(--faint); background: color-mix(in srgb, var(--surface) 86%, transparent); color: var(--text); backdrop-filter: blur(8px); }
.icon-button { display: grid; place-items: center; width: 40px; height: 40px; padding: 0; border-radius: 6px; font-size: 20px; line-height: 1; pointer-events: auto; }
.hint-button { width: 36px; height: 36px; border-radius: 50%; font-size: 16px; }
.hint-button.revealed { border-color: var(--muted); color: var(--text); }
.level-chip { padding: 9px 12px; border-radius: 6px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.statusbar { position: absolute; z-index: 2; left: 22px; bottom: 18px; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; pointer-events: none; }

.overlay { position: absolute; z-index: 10; inset: 0; background: var(--overlay); }
.overlay[hidden] { display: none; }
.drawer { position: absolute; top: 0; bottom: 0; left: 0; width: min(360px, 82vw); padding: 34px 28px; background: var(--surface); box-shadow: 18px 0 60px rgba(0,0,0,.24); }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-head h1, .panel-head h2 { margin: 0; letter-spacing: 0; font-weight: 600; }
.panel-head h1 { font-size: 26px; }
.panel-head h2 { font-size: 20px; }
.close-button { width: 34px; height: 34px; font-size: 22px; }
.level-summary { display: flex; flex-direction: column; gap: 8px; margin: 48px 0 20px; padding: 18px 0; border-block: 1px solid rgba(228,235,232,.1); }
.level-summary span, .level-summary small, .setting-row small { color: var(--muted); font-size: 12px; }
.level-summary strong { font-size: 18px; font-weight: 500; }
.menu-action { display: flex; align-items: center; justify-content: space-between; width: 100%; height: 58px; padding: 0; border-bottom: 1px solid var(--faint); border-radius: 0; background: transparent; color: var(--text); text-align: left; }
.menu-action span { color: var(--muted); font-size: 24px; }

.sheet-overlay { display: flex; align-items: flex-end; }
.sheet { width: 100%; max-height: 78vh; padding: 24px 28px 30px; border-radius: 8px 8px 0 0; overflow: auto; background: var(--surface); box-shadow: 0 -18px 60px rgba(0,0,0,.24); }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); gap: 8px; margin-top: 22px; }
.level-tile { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 58px; border: 1px solid var(--faint); border-radius: 4px; background: var(--surface-raised); color: var(--text); }
.level-tile small { margin-top: 4px; color: var(--muted); font-size: 10px; }
.level-tile.selected { border-color: var(--text); color: var(--text); background: var(--selected-bg); }
.level-tile.locked { color: var(--faint); cursor: default; }
.level-tile.locked small { color: var(--faint); }
.settings-sheet { max-width: 720px; margin-inline: auto; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; min-height: 72px; border-bottom: 1px solid var(--faint); }
.setting-row span { display: flex; flex-direction: column; gap: 5px; }
.setting-row input { width: 38px; height: 20px; accent-color: #777a75; }
.secondary-button { height: 34px; padding: 0 12px; border: 1px solid var(--faint); border-radius: 4px; background: transparent; color: var(--text); font-size: 12px; }
.segmented { display: flex; flex: 0 0 auto; border: 1px solid var(--faint); border-radius: 4px; overflow: hidden; }
.segment { width: 58px; height: 34px; padding: 0; border-radius: 0; background: transparent; color: var(--muted); font-size: 12px; }
.segment.active { background: var(--text); color: var(--surface); }

.dialog-overlay { display: grid; place-items: center; }
.dialog { width: min(360px, calc(100vw - 40px)); padding: 30px 28px 24px; border: 1px solid var(--faint); border-radius: 6px; background: var(--surface); box-shadow: 0 20px 70px rgba(0,0,0,.3); text-align: center; }
.kicker { color: var(--muted); font-size: 11px; }
.dialog h2 { margin: 12px 0 0; font-size: 22px; font-weight: 600; }
.dialog p, .complete-stats { margin: 14px 0 0; color: var(--muted); font-size: 13px; line-height: 1.55; }
.primary-button, .text-button { width: 100%; height: 44px; margin-top: 22px; border-radius: 4px; }
.primary-button { background: var(--text); color: var(--surface); }
.text-button { margin-top: 6px; background: transparent; color: var(--muted); }

@keyframes wall-flash { from { opacity: 1; } to { opacity: 0; } }

@media (max-width: 560px) {
  .topbar { top: max(14px, env(safe-area-inset-top)); left: 14px; right: 14px; }
  .sheet { padding-inline: 18px; }
  .level-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; }
}
