:root {
  color-scheme: light;
  --paper: #f6f1e8;
  --surface: #fffdf8;
  --ink: #213b4c;
  --muted: #566d76;
  --line: #d8ded8;
  --coral: #a94331;
  --coral-soft: #ffe6d9;
  --sky: #e4eff1;
  --green: #3a6554;
  --shadow: 0 14px 36px rgb(35 56 60 / 6%);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--paper); color: var(--ink); line-height: 1.7; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { min-height: 44px; border: 1px solid #bcc9c4; border-radius: 11px; padding: 10px 14px; color: var(--ink); background: var(--surface); font-size: 13px; font-weight: 650; line-height: 1.5; cursor: pointer; transition: background .15s ease, border-color .15s ease; }
button:hover { background: #eef2eb; border-color: #78978d; }
button:disabled { opacity: .48; cursor: default; }
button.primary { color: #fffcf8; background: var(--coral); border-color: var(--coral); }
button.primary:hover { background: #923a2c; border-color: #923a2c; }
button.danger { color: #963e2d; border-color: #d0b4a8; }
button:focus-visible, a:focus-visible, input:focus-visible, [tabindex="-1"]:focus-visible { outline: 3px solid #206e85; outline-offset: 4px; }
a { color: var(--ink); text-underline-offset: 4px; }
.page-shell { max-width: 1232px; padding: 0 36px; margin: 0 auto; }
.topbar { min-height: 85px; display: flex; align-items: center; justify-content: space-between; gap: 18px; border-bottom: 1px solid var(--line); }
.home-link { min-height: 44px; display: inline-flex; align-items: center; font-family: Georgia, "Songti SC", serif; font-size: 19px; font-weight: 700; text-decoration: none; }
.home-link:hover { text-decoration: underline; }
.topbar > span { max-width: 52%; color: var(--muted); font-size: 12px; text-align: right; line-height: 1.6; }
.hero { max-width: 810px; padding: 47px 0 34px; }
.eyebrow { margin: 0 0 11px; font-size: 11px; color: var(--coral); font-weight: 800; letter-spacing: .15em; line-height: 1.5; overflow-wrap: anywhere; }
h1 { margin: 0 0 17px; font-family: Georgia, "Songti SC", "STSong", serif; font-size: clamp(38px, 4.8vw, 56px); line-height: 1.2; letter-spacing: -.03em; font-weight: 700; }
h1 span { color: var(--coral); }
.intro { margin: 0; max-width: 640px; color: #425f6a; font-size: 17px; }
.hero-note { display: inline-block; margin: 15px 0 0; padding-left: 12px; border-left: 3px solid #b2c6c6; color: var(--muted); font-size: 12px; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 302px; gap: 24px; align-items: start; }
.game-panel { min-width: 0; padding: 26px; background: var(--surface); border: 1px solid var(--line); border-radius: 23px; box-shadow: var(--shadow); }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 13px; margin-bottom: 23px; padding-bottom: 20px; border-bottom: 1px solid #e2e5da; }
.mode-switch { display: inline-flex; max-width: 100%; padding: 4px; gap: 3px; border: 1px solid #d6ded5; border-radius: 13px; background: #edf0e7; }
.mode-switch button { flex: 1 1 0; min-width: 0; padding: 8px 13px; font-size: 13px; border-color: transparent; border-radius: 9px; background: transparent; }
.mode-switch button[aria-pressed="true"] { color: #fffcf7; background: var(--ink); box-shadow: 0 3px 8px rgb(24 49 65 / 10%); }
.route-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.route-actions button { padding: 8px 10px; font-size: 12px; }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px; margin-bottom: 18px; }
.stat { min-width: 0; padding: 13px 9px; border-radius: 13px; text-align: center; background: #f0f3eb; }
.stat strong { display: block; font-size: 27px; line-height: 1.3; font-weight: 750; letter-spacing: -.035em; font-variant-numeric: tabular-nums; }
.stat span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; line-height: 1.6; }
.stage { position: relative; isolation: isolate; overflow: hidden; background: #e8f0f0; border: 1px solid #c3d7d9; border-radius: 17px; padding: 18px 20px 14px; }
.stage-sky { position: absolute; inset: 0; z-index: -1; background: linear-gradient(180deg, #dcebed 0%, #edf3ed 75%, #f3f1e4 100%); }
.stage-sky::before { content: ""; position: absolute; top: 83px; right: -40px; width: 165px; height: 29px; border-radius: 50%; background: rgb(255 255 250 / 50%); box-shadow: -53px 17px 0 3px rgb(255 255 250 / 30%); }
.stage-sky::after { content: ""; position: absolute; top: 173px; left: -45px; width: 135px; height: 21px; border-radius: 50%; background: rgb(255 255 250 / 45%); box-shadow: 30px 14px 0 rgb(255 255 250 / 25%); }
.stage-heading { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px 12px; position: relative; z-index: 1; min-height: 30px; margin-bottom: 12px; font-size: 11px; }
#modeLabel { color: #405f68; font-weight: 700; }
#phaseLabel { max-width: 100%; color: #704c35; background: rgb(255 251 238 / 80%); border: 1px solid #d6ccb2; border-radius: 999px; padding: 3px 10px; font-weight: 650; overflow-wrap: anywhere; }
.tower-frame { position: relative; width: 100%; height: 280px; padding: 0 2px; border-bottom: 1px solid #9fb6af; }
.tower { position: relative; width: 100%; height: 100%; }
.tower-layer { position: absolute; display: flex; align-items: center; justify-content: center; height: 10%; padding: 0; border: 0; border-radius: 12px 12px 9px 9px; background: linear-gradient(180deg, #fffefa, #d7e7e7); box-shadow: inset 0 -3px 0 rgb(127 167 173 / 20%); outline: 1px solid #7f9fa4; outline-offset: -1px; overflow: hidden; }
.tower-layer::before { content: ""; position: absolute; inset: 2px 4px auto; height: 2px; border-radius: 50%; background: rgb(255 255 255 / 75%); }
.layer-label { display: block; max-width: 100%; padding: 0 3px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: #3a5a65; font-size: 10px; font-weight: 650; line-height: 1.3; font-variant-numeric: tabular-nums; }
.active-layer { background: linear-gradient(180deg, #ffe9da, #f7c8b3); outline-color: #b86b4e; box-shadow: inset 0 -3px 0 rgb(171 91 58 / 15%); }
.active-layer .layer-label { color: #793b27; }
.coordinate-note { position: relative; margin: 12px 0 0; min-height: 22px; color: #49636b; font-size: 11px; line-height: 1.8; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.main-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; margin-top: 17px; }
#actionButton { min-height: 51px; font-size: 16px; }
#pauseButton { min-width: 88px; }
.practice-tools { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 12px; margin-top: 13px; padding: 12px; border: 1px solid #d8dfd4; border-radius: 12px; background: #f5f6ee; }
.practice-tools button { min-width: 78px; background: var(--surface); }
.practice-tools > span { font-size: 11px; color: var(--muted); }
.game-status { margin: 16px 0 0; min-height: 44px; color: #405e67; font-size: 13px; line-height: 1.8; }
.notice { background: #fff0df; border: 1px solid #e2c5a4; border-radius: 9px; padding: 11px 13px; color: #7c4930; font-size: 12px; overflow-wrap: anywhere; }
.finished-panel { margin-top: 18px; border: 1px solid #c2d5c3; background: #eff5e9; border-radius: 14px; padding: 19px; }
.finished-panel h2 { margin: 0 0 8px; font-size: 21px; line-height: 1.5; }
.finished-panel p { margin: 5px 0; color: #425e50; font-size: 13px; line-height: 1.85; }
.side-panel { display: grid; gap: 18px; min-width: 0; }
.side-panel > section { padding: 22px; border: 1px solid var(--line); border-radius: 17px; background: rgb(255 253 248 / 74%); }
.side-panel h2 { margin: 0 0 12px; color: var(--ink); font-size: 16px; line-height: 1.5; }
.side-panel p { margin: 9px 0 0; color: #516870; font-size: 12px; line-height: 1.85; }
.side-panel .eyebrow { margin: 0 0 9px; color: var(--coral); font-size: 10px; line-height: 1.5; }
.side-panel ul, .side-panel ol { padding-left: 18px; margin: 0; color: #516870; font-size: 12px; line-height: 1.85; }
.side-panel li + li { margin-top: 8px; }
.side-panel button { margin-top: 14px; }
.best-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; margin: 15px 0 0; }
.best-item { min-width: 0; padding: 14px 7px; text-align: center; border: 1px solid #d3ddd1; border-radius: 11px; background: #f0f4e9; }
.best-item strong { display: block; color: var(--green); font-size: 27px; line-height: 1.3; font-weight: 750; font-variant-numeric: tabular-nums; }
.best-item span { display: block; color: #5a6c63; font-size: 10px; margin-top: 4px; }
.side-panel .storage-status, .storage-status { padding: 9px 11px; border-left: 3px solid #afc4ad; border-radius: 4px; background: #eff3e8; color: #4b6253; font-size: 11px; line-height: 1.8; }
.side-panel .storage-status.is-error, .storage-status.is-error { border-color: #bd815a; background: #fff0df; color: #7d4a31; }
.share-fallback { margin-top: 13px; }
.share-fallback label { display: block; color: #77523b; font-size: 11px; margin-bottom: 6px; }
.share-fallback input { display: block; min-width: 0; width: 100%; min-height: 44px; padding: 10px; border: 1px solid #acbbb5; border-radius: 7px; background: #fffdf7; color: var(--ink); font-size: 11px; }
footer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px 20px; padding: 34px 0 28px; color: var(--muted); font-size: 11px; }
footer p { margin: 0; }
footer a { min-height: 44px; display: inline-flex; align-items: center; }
dialog { width: min(446px, calc(100% - 32px)); max-width: none; max-height: calc(100dvh - 48px); overflow: auto; margin: auto; padding: 27px; border: 1px solid #bdc9c1; border-radius: 18px; background: var(--surface); color: var(--ink); box-shadow: 0 25px 90px rgb(24 40 49 / 24%); }
dialog::backdrop { background: rgb(23 42 53 / 48%); backdrop-filter: blur(3px); }
dialog h2 { margin: 0 0 12px; font-size: 22px; line-height: 1.4; }
dialog p { margin: 0 0 23px; color: #4f6670; font-size: 14px; overflow-wrap: anywhere; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.dialog-actions button { margin: 0; font-size: 13px; }
.dialog-actions button:last-child { background: var(--coral); border-color: var(--coral); color: #fffaf4; }
.dialog-actions button:last-child:hover { background: #923a2c; border-color: #923a2c; }

@media (max-width: 1030px) {
  .page-shell { padding: 0 26px; }
  .layout { grid-template-columns: minmax(0, 1fr) 263px; gap: 18px; }
  .game-panel { padding: 21px; }
  .side-panel > section { padding: 19px; }
  .stage { padding: 15px 16px 12px; }
}

@media (max-width: 820px) {
  .page-shell { max-width: 724px; }
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .side-panel > section:last-child { grid-column: 1 / -1; }
  .hero { padding: 36px 0 28px; }
  .hero h1 { font-size: 44px; }
  .tower-frame { height: 280px; }
}

@media (max-width: 480px) {
  .page-shell { padding: 0 16px; }
  .topbar { min-height: 72px; gap: 12px; }
  .home-link { font-size: 17px; }
  .topbar > span { max-width: 45%; font-size: 10px; }
  .hero { padding: 28px 0 24px; }
  .hero h1 { font-size: 38px; }
  .intro { font-size: 15px; }
  .hero-note { font-size: 11px; }
  .game-panel { padding: 16px; border-radius: 18px; }
  .toolbar { gap: 12px; margin-bottom: 18px; padding-bottom: 16px; }
  .mode-switch { width: 100%; }
  .mode-switch button { padding: 8px; font-size: 12px; }
  .route-actions { width: 100%; gap: 7px; }
  .route-actions button { flex: 1 1 0; padding: 8px; font-size: 11px; }
  .stats-grid { gap: 6px; margin-bottom: 15px; }
  .stat { padding: 11px 4px; border-radius: 10px; }
  .stat strong { font-size: 23px; }
  .stat span { font-size: 10px; }
  .stage { padding: 13px 12px 11px; border-radius: 13px; }
  .stage-heading { gap: 6px 9px; font-size: 10px; }
  .tower-frame { height: 270px; }
  .layer-label { font-size: 9px; }
  .coordinate-note { font-size: 10px; }
  .main-controls { gap: 8px; margin-top: 15px; }
  #actionButton { min-height: 49px; font-size: 15px; }
  #pauseButton { min-width: 72px; padding-inline: 10px; font-size: 12px; }
  .practice-tools { gap: 8px; padding: 10px 8px; }
  .practice-tools button { min-width: 67px; padding: 9px; }
  .practice-tools > span { font-size: 10px; }
  .game-status { font-size: 12px; }
  .finished-panel { padding: 16px; }
  .side-panel { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .side-panel > section:last-child { grid-column: auto; }
  .side-panel > section { padding: 20px; border-radius: 15px; }
  footer { gap: 3px; padding: 24px 0; }
  dialog { padding: 22px; border-radius: 15px; }
  .dialog-actions { flex-direction: column; }
  .dialog-actions button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
