:root {
  color-scheme: light;
  --bg: #fff;
  --surface: #fff;
  --soft: #f6f6f5;
  --border: #dadad7;
  --text: #181818;
  --muted: #494947;
  --dim: #60605c;
  --green: #246642;
  --red: #b62330;
  --focus: #265c9c;
  --page-width: calc(100% - clamp(24px, 2vw, 48px));
  font-family: "Segoe UI", "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; color: var(--text); background: var(--bg); min-height: 100vh; }
[hidden] { display: none !important; }
button { color: inherit; font: inherit; cursor: pointer; }
button:disabled { opacity: .43; cursor: default; }
button, a, canvas { -webkit-tap-highlight-color: transparent; }
button:focus-visible, canvas:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
button:not(:disabled):active { transform: translateY(1px); }
button svg { width: 17px; height: 17px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round; }
.symbols { position: absolute; width: 0; height: 0; overflow: hidden; }

.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top-inner { width: var(--page-width); margin: auto; height: 68px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.brand { display: flex; gap: 11px; align-items: center; }
.brand img { display: block; border-radius: 12px; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 20px; font-weight: 750; letter-spacing: .09em; line-height: 1.15; }
.brand span { font-size: 9px; margin-top: 5px; color: var(--dim); letter-spacing: .19em; font-weight: 700; }
.modes { display: flex; gap: 4px; padding: 4px; background: var(--soft); border: 1px solid var(--border); border-radius: 12px; }
.modes button, .rules-button { display: flex; justify-content: center; align-items: center; gap: 8px; font-size: 13px; font-weight: 650; border: 1px solid transparent; border-radius: 8px; background: transparent; color: var(--muted); white-space: nowrap; }
.modes button { min-height: 37px; padding: 0 14px; }
.modes button[aria-pressed="true"] { color: #fff; border-color: var(--text); background: var(--text); }
.modes button:hover:not([aria-pressed="true"]), .rules-button:hover { color: var(--text); background: #ebebe9; }
.rules-button { justify-self: end; min-height: 40px; padding: 0 12px; border-color: var(--border); }

main { width: var(--page-width); margin: 0 auto; padding: 14px 0 10px; }
.intro { display: flex; justify-content: space-between; align-items: end; gap: 18px; margin-bottom: 12px; }
.level-label { color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .075em; display: flex; align-items: center; gap: 9px; }
.label-dot { width: 4px; height: 4px; border-radius: 50%; background: #81817d; }
h1 { font-size: clamp(31px, 3.5vw, 45px); margin: 6px 0 5px; line-height: 1.2; letter-spacing: .055em; font-weight: 750; }
.intro p { margin: 0; color: var(--muted); line-height: 1.6; font-size: 14px; }
.timer { display: flex; align-items: center; gap: 12px; flex: none; padding: 9px 10px 9px 13px; background: var(--surface); border: 1px solid var(--border); border-radius: 13px; }
.timer > svg { width: 20px; height: 20px; fill: none; stroke: var(--text); stroke-width: 1.6; stroke-linecap: round; }
.timer span, .timer strong { display: block; }
.timer span { color: var(--muted); font-size: 11px; }
.timer strong { margin-top: 2px; font: 650 24px/1 "Cascadia Mono", Consolas, monospace; }
.timer-actions { display: flex; gap: 6px; }
.timer button { min-width: 50px; min-height: 36px; border: 1px solid var(--border); border-radius: 8px; background: var(--soft); font-size: 12px; }
.timer button:hover { background: #ebebe9; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 290px; gap: 14px; align-items: start; }
.board-card, .panel { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; }
.board-card { overflow: hidden; }
.board-view {
  position: relative;
  isolation: isolate;
  background: #fff;
}
#board { position: absolute; inset: 0; display: block; width: 100%; height: 100%; outline-offset: -3px; cursor: grab; touch-action: none; }
#board.dragging { cursor: grabbing !important; }
.board-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 5px 12px; border-bottom: 1px solid var(--border); background: var(--soft); }
.board-length { margin-inline: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.board-length strong { margin-inline-start: 4px; color: var(--text); font-variant-numeric: tabular-nums; }
.view-tools { display: flex; gap: 2px; }
.board-actions { display: flex; gap: 4px; }
.view-tools button { display: grid; place-items: center; width: 38px; min-height: 38px; border-radius: 7px; border: 0; background: transparent; }
.fullscreen-toggle { display: inline-flex; justify-content: center; align-items: center; gap: 6px; min-height: 38px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: 12px; font-weight: 650; white-space: nowrap; }
.view-tools button:hover:not(:disabled), .fullscreen-toggle:hover, .game-fullscreen .fullscreen-toggle { background: #ebebe9; }
.compact-control { display: none; }
.board-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 9px 16px; border-top: 1px solid var(--border); padding: 9px 17px; color: var(--dim); background: var(--soft); font-size: 11px; line-height: 1.2; }
.legend { display: flex; align-items: center; gap: 17px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.legend i { display: inline-block; width: 22px; }
.legend .clear-line { border-top: 2px solid #111; }
.legend .cross-line { height: 1.5px; background: repeating-linear-gradient(90deg, #696966 0 4px, transparent 4px 8px); }
.legend .anchor-mark { width: 14px; height: 13px; background: #4a4a49; color: white; text-align: center; line-height: 12px; border-radius: 3px; font-size: 12px; font-style: normal; }

.sidebar { display: grid; gap: 16px; }
.panel { padding: 18px; }
.panel h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .04em; }
.stats { display: grid; grid-template-columns: repeat(2, 1fr); margin: 14px 0; gap: 8px; }
.stats > div { min-width: 0; background: var(--soft); border: 1px solid var(--border); border-radius: 11px; text-align: center; padding: 11px 2px 10px; }
.stats strong { display: block; font-family: "Cascadia Mono", "Consolas", monospace; font-size: clamp(19px, 2vw, 26px); font-weight: 650; line-height: 1.12; }
.stats > div:first-child strong { color: var(--red); }
.stats > div:first-child strong.good { color: var(--green); }
.stats span { display: block; color: var(--muted); font-size: 11px; margin-top: 7px; }
.actions, .quiet { display: grid; gap: 8px; }
.quiet { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; margin-top: 8px; }
.actions button, .quiet button { display: flex; justify-content: center; align-items: center; gap: 8px; font-size: 13px; font-weight: 650; border-radius: 10px; min-height: 43px; }
.primary { border: 1px solid var(--text); color: #fff; background: var(--text); }
.primary:hover:not(:disabled) { background: #373736; }
.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.secondary:hover:not(:disabled) { background: var(--soft); }
.quiet button { min-height: 38px; gap: 4px; padding-inline: 2px; font-size: 12px; border: 1px solid transparent; background: transparent; color: var(--muted); }
.quiet button svg { width: 15px; height: 15px; }
.quiet button:hover:not(:disabled) { border-color: var(--border); background: var(--soft); color: var(--text); }
.status { min-height: 1.5em; line-height: 1.5; margin: 8px 0 0; color: var(--dim); font-size: 11px; overflow-wrap: anywhere; }
.panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.panel-heading > span { color: var(--muted); font-size: 11px; white-space: nowrap; }
.rank, .edit-tools { display: grid; gap: 5px; padding: 0; border: 0; margin: 13px 0; }
.rank { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.rank legend, .settings label { color: var(--muted); font-size: 12px; }
.rank legend { margin-bottom: 7px; padding: 0; }
.rank label { position: relative; }
.rank input { position: absolute; opacity: 0; }
.rank span, .edit-tools button { display: grid; place-items: center; min-height: 38px; border: 1px solid var(--border); color: var(--muted); background: var(--surface); border-radius: 8px; font-size: 12px; cursor: pointer; }
.rank input:checked + span, .edit-tools [aria-pressed="true"] { background: #ededeb; border-color: #5e5e59; color: var(--text); font-weight: 700; }
.rank input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 2px; }
.settings { display: grid; grid-template-columns: minmax(0, .85fr) minmax(0, 1.15fr); gap: 8px; }
.settings input, .settings select { display: block; width: 100%; min-height: 38px; margin-top: 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); padding: 0 8px; font: inherit; }
.settings input::placeholder { color: var(--dim); }
.settings input:focus-visible, .settings select:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.length-settings { grid-template-columns: minmax(0, 1fr); margin-bottom: 12px; }
.length-goal { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.5; }
.length-goal.good { color: var(--green); }
.generate { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 13px; width: 100%; min-height: 41px; border-radius: 9px; font-size: 13px; font-weight: 650; }
.edit-tools { grid-template-columns: repeat(5, minmax(0, 1fr)); margin-bottom: 8px; }
.mechanism-editor { grid-template-columns: minmax(0, 1fr) auto; align-items: end; margin-bottom: 10px; }
#apply-mechanism { min-height: 38px; border-radius: 8px; padding: 0 11px; font-size: 12px; }
#edit-quiet { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#editing-return { margin-top: 12px; }
.editor-tip { margin: 0 0 13px; min-height: 32px; color: var(--muted); font-size: 12px; line-height: 1.55; }
#editor-status:not(:empty), #generator-status:not(:empty) { color: var(--text); }

dialog { width: min(520px, calc(100% - 28px)); max-height: calc(100% - 28px); padding: 23px; background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 16px; box-shadow: 0 20px 80px #24242040; }
dialog::backdrop { background: #22222265; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; }
.dialog-heading h2 { margin: 0; font-size: 21px; }
.dialog-heading button { width: 38px; height: 38px; display: grid; place-items: center; background: var(--soft); border: 1px solid var(--border); border-radius: 8px; }
dialog p, dialog dd { color: var(--muted); font-size: 13px; line-height: 1.65; }
.mechanics { margin: 15px 0; }
.mechanics > div { display: grid; grid-template-columns: 100px 1fr; padding: 8px 0; border-top: 1px solid var(--border); }
.mechanics dt { color: var(--text); font-size: 13px; font-weight: 650; }
.mechanics dd { margin: 0; }

@media (min-width: 731px) {
  main { display: grid; grid-template-rows: auto 1fr; min-height: calc(100dvh - 69px); }
  .layout { align-items: stretch; }
  .board-card { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
  .board-view { min-height: 375px; }
  .sidebar { align-content: start; }
}

@media (max-width: 960px) {
  .top-inner, main { width: calc(100% - 24px); }
  .layout { grid-template-columns: minmax(0, 1fr) 263px; gap: 15px; }
  .panel { padding: 15px; }
}
@media (max-width: 730px) {
  .top-inner, main { width: calc(100% - 28px); }
  main { width: calc(100% - 12px); }
  .top-inner { height: 62px; gap: 8px; }
  .brand { gap: 7px; }
  .brand img { width: 34px; height: 34px; border-radius: 9px; }
  .brand strong { font-size: 16px; white-space: nowrap; }
  .brand span { display: none; }
  .modes button { padding: 0 8px; gap: 5px; font-size: 12px; }
  .modes button svg { width: 14px; height: 14px; }
  .rules-button { padding: 0; width: 38px; min-height: 38px; }
  .rules-button span { position: absolute; clip-path: inset(50%); }
  main { padding-top: 20px; }
  .intro { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 15px; align-items: end; }
  .intro h1 { font-size: clamp(26px, 8vw, 36px); }
  .intro p { font-size: 12px; }
  .timer { gap: 6px; padding: 6px 7px; }
  .timer > svg { display: none; }
  .timer span { font-size: 10px; }
  .timer strong { font-size: 17px; }
  .timer-actions { gap: 4px; }
  .timer button { min-width: 40px; min-height: 35px; }
  .layout { grid-template-columns: minmax(0, 1fr); gap: 13px; }
  .board-view { height: clamp(305px, 50dvh, 490px); }
  .board-toolbar { padding-inline: 8px; }
  .board-footer { padding: 10px 12px; gap: 7px; }
  #board-help { display: none; }
  .sidebar { gap: 13px; }
  .stats { margin: 12px 0; }
  .actions { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 370px) {
  .top-inner { grid-template-columns: auto 1fr auto; }
  .modes { justify-self: center; }
  .modes button svg { display: none; }
  .board-toolbar { gap: 6px; }
  .view-tools button, .compact-fullscreen .view-tools button { width: 28px; }
  .board-length { font-size: 11px; }
}

.game-fullscreen { overflow: hidden; background: #fff; }
.game-fullscreen body { height: 100dvh; min-height: 0; display: flex; flex-direction: column; }
.game-fullscreen .top-inner { width: calc(100% - 16px); height: 54px; }
.game-fullscreen main { width: calc(100% - 16px); flex: 1; min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr); padding: 8px 0 10px; }
.game-fullscreen .intro { margin-bottom: 8px; }
.game-fullscreen .intro p { display: none; }
.game-fullscreen h1 { margin: 4px 0; font-size: clamp(23px, 3vw, 34px); }
.game-fullscreen .layout { min-height: 0; align-items: stretch; gap: 12px; }
.game-fullscreen .board-card { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
.game-fullscreen .board-toolbar { padding-block: 3px; }
.game-fullscreen .board-footer { padding-block: 7px; }
.game-fullscreen .board-view { height: auto; min-height: 0; }
.game-fullscreen .sidebar { min-height: 0; overflow: auto; align-content: start; }
.game-fullscreen .session { order: -1; }

.compact-fullscreen .top,
.compact-fullscreen .intro,
.compact-fullscreen .board-footer { display: none; }
.compact-fullscreen main { display: block; width: 100%; padding: 0; }
.compact-fullscreen .layout { display: block; position: relative; height: 100%; }
.compact-fullscreen .board-card { height: 100%; border: 0; border-radius: 0; grid-template-rows: auto minmax(0, 1fr); }
.compact-fullscreen .board-toolbar { padding: 2px 6px; }
.compact-fullscreen .view-tools button { width: 36px; min-height: 40px; }
.compact-fullscreen .fullscreen-toggle { min-height: 40px; padding-inline: 8px; }
.compact-fullscreen .compact-control { display: inline-flex; }
.compact-fullscreen .sidebar {
  display: none;
  position: absolute;
  z-index: 2;
  top: 51px;
  right: 6px;
  bottom: 6px;
  width: min(290px, calc(100% - 12px));
  padding: 8px;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--soft);
  box-shadow: 0 5px 24px #0002;
  overscroll-behavior: contain;
}
.compact-fullscreen.fullscreen-menu-open .sidebar { display: grid; }
.compact-fullscreen.fullscreen-menu-open #compact-solve { display: none; }
.compact-fullscreen .timer { order: -2; justify-content: space-between; }

@media (max-width: 420px) {
  .compact-fullscreen:not(.fullscreen-menu-open) .board-toolbar:has(#compact-solve:not([hidden])) { flex-wrap: wrap; }
  .compact-fullscreen:not(.fullscreen-menu-open) .board-toolbar:has(#compact-solve:not([hidden])) .board-length {
    order: 1;
    width: 100%;
    text-align: center;
    padding-bottom: 3px;
  }
}

@media (max-height: 510px) and (orientation: landscape) {
  .compact-fullscreen .sidebar { width: min(270px, 46%); }
  :root:not(.game-fullscreen) .top-inner { height: 48px; }
  :root:not(.game-fullscreen) main { display: grid; grid-template-rows: auto minmax(0, 1fr); height: calc(100dvh - 49px); min-height: 0; padding: 6px 0 4px; }
  :root:not(.game-fullscreen) .intro { margin-bottom: 6px; }
  :root:not(.game-fullscreen) .intro h1 { font-size: 23px; }
  :root:not(.game-fullscreen) .intro p { display: none; }
  :root:not(.game-fullscreen) .layout { min-height: 0; align-items: stretch; grid-template-columns: minmax(0, 1fr) min(220px, 35vw); gap: 8px; }
  :root:not(.game-fullscreen) .board-card { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; }
  :root:not(.game-fullscreen) .board-view { height: auto; min-height: 0; }
  :root:not(.game-fullscreen) .sidebar { min-height: 0; overflow: auto; align-content: start; }
}

@media (prefers-reduced-motion: reduce) {
  button:not(:disabled):active { transform: none; }
}
