:root {
  color-scheme: light;
  --paper: #f8f4eb;
  --surface: #fffdf7;
  --ink: #21384a;
  --muted: #596b73;
  --line: #dcded4;
  --accent: #b9432e;
  --accent-soft: #fff0df;
  --mint: #dcebe0;
  --shadow: 0 14px 38px rgb(35 49 53 / 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; color: var(--ink); background: var(--paper); line-height: 1.65; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { min-height: 44px; border: 1px solid #cbd2cb; border-radius: 12px; padding: 9px 14px; color: var(--ink); background: var(--surface); font-weight: 650; line-height: 1.4; cursor: pointer; transition: background .15s ease, border-color .15s ease, transform .15s ease; }
button:hover { background: #f1f4ed; border-color: #7e938f; }
button:active { transform: translateY(1px); }
button:disabled { cursor: default; opacity: .55; }
button:disabled:active { transform: none; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid #246e85; outline-offset: 4px; }
a { color: var(--ink); text-underline-offset: 4px; }
.page-shell { max-width: 1256px; margin: 0 auto; padding: 0 36px; }
.topbar { min-height: 86px; display: flex; justify-content: space-between; align-items: center; gap: 16px; border-bottom: 1px solid var(--line); }
.home-link { display: inline-flex; min-height: 44px; align-items: center; gap: 8px; font-size: 14px; font-weight: 650; text-decoration: none; }
.home-link:hover { text-decoration: underline; }
.brand { font-family: Georgia, "Songti SC", serif; font-size: 21px; font-weight: 700; letter-spacing: .03em; }
.topbar-tag { max-width: 54%; color: var(--muted); font-size: 12px; text-align: right; line-height: 1.6; }
.hero { padding: 50px 0 38px; max-width: 790px; }
.eyebrow { margin: 0 0 12px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .16em; }
h1 { font-family: Georgia, "Songti SC", "STSong", serif; margin: 0 0 16px; font-size: clamp(36px, 4.5vw, 56px); line-height: 1.15; letter-spacing: -.025em; font-weight: 700; }
h1 span { color: var(--accent); }
.intro { font-size: 17px; margin: 0; max-width: 630px; color: #415966; }
.hero-note { display: inline-block; font-size: 13px; color: var(--muted); margin: 16px 0 0; padding-left: 12px; border-left: 3px solid #d5ad83; }
.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 302px; gap: 24px; align-items: start; }
.play-panel { background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 26px; box-shadow: var(--shadow); min-width: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; padding-bottom: 22px; border-bottom: 1px solid #e7e6dc; }
.mode-switch { display: inline-flex; max-width: 100%; background: #eeeee4; border: 1px solid #dddfd3; border-radius: 14px; padding: 4px; gap: 3px; }
.mode-switch button { min-width: 0; flex: 1 1 0; border-color: transparent; background: transparent; box-shadow: none; padding: 8px 13px; border-radius: 10px; font-size: 14px; }
.mode-switch button[aria-pressed="true"] { color: #fffdf8; background: var(--ink); box-shadow: 0 3px 8px rgb(32 56 74 / 12%); }
.toolbar-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.toolbar-actions button { font-size: 13px; min-height: 44px; padding: 8px 11px; }
.board-meta { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 14px; margin: 22px 0 18px; }
.board-title { font-size: 18px; margin: 0; font-weight: 750; }
#boardLabel { margin: 0; }
.board-title h2 { font-size: 20px; line-height: 1.5; }
#boardSeed { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 14px; }
.stat { padding: 12px 8px; text-align: center; background: #f3f4eb; border-radius: 14px; }
.stat strong { display: block; font-size: 26px; font-weight: 750; letter-spacing: -.04em; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { display: block; margin-top: 5px; font-size: 12px; color: var(--muted); }
.game-status { color: #425d66; font-size: 13px; line-height: 1.7; min-height: 44px; margin: 0 0 12px; }
.board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.card { display: flex; position: relative; width: 100%; min-width: 0; min-height: 90px; aspect-ratio: 1.05; align-items: center; justify-content: center; padding: 7px; border: 1px solid #324f60; border-radius: 15px; background: #294858; color: #fffaf0; box-shadow: 0 3px 0 #1d3948; overflow: hidden; }
.card:hover { background: #345969; border-color: #345969; transform: translateY(-2px); }
.card:active { transform: translateY(1px); box-shadow: 0 1px 0 #1d3948; }
.card-back { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; width: 100%; }
.card-back::before { content: "✦"; display: block; color: #d1bd96; font-size: clamp(23px, 3vw, 38px); font-weight: 400; line-height: 1.25; }
.card-number { font-size: 11px; font-weight: 500; color: #e3ded1; letter-spacing: .07em; line-height: 1.3; font-variant-numeric: tabular-nums; }
.card-front { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; width: 100%; }
.card-icon { display: block; width: 43%; height: auto; max-width: 58px; min-width: 25px; aspect-ratio: 1; }
.card-icon svg { display: block; width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.card-name { font-size: 13px; line-height: 1.35; white-space: nowrap; }
.card-state { font-size: 10px; line-height: 1.2; color: #3a6251; font-weight: 700; }
.card.is-open { background: #fff3dc; color: #81482d; border-color: #d8a36a; box-shadow: 0 3px 0 #dcbd95; }
.card.is-open:hover { background: #fff3dc; }
.card.is-matched { background: #e4ede2; color: #245044; border-color: #a7bca9; box-shadow: 0 2px 0 #a6bca7; }
.card.is-matched:hover { background: #e4ede2; transform: none; }
.card.is-matched:active { box-shadow: 0 2px 0 #a6bca7; }
.mismatch-tools { margin-top: 14px; padding: 12px 14px; border: 1px solid #e6cfb3; border-radius: 12px; background: #fff6e8; }
.mismatch-tools:has(button[hidden]) { display: none; }
.mismatch-tools button { width: 100%; background: #fffdf7; border-color: #caa984; font-size: 14px; }
.completion { border: 1px solid #c3d7c4; background: #eff5e9; border-radius: 16px; padding: 20px; margin-top: 18px; }
.completion h2 { margin: 0 0 7px; font-size: 21px; }
.completion p { margin: 5px 0; color: #3e5b4d; font-size: 14px; }
.side-panel { display: grid; gap: 18px; min-width: 0; }
.side-panel > section { background: rgb(255 253 247 / 72%); border: 1px solid var(--line); border-radius: 20px; padding: 22px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin: 0 0 14px; font-size: 16px; line-height: 1.5; }
.section-title h2 { margin: 0; font-size: 16px; }
.section-title small { font-size: 11px; color: var(--muted); font-weight: 500; }
.side-panel h2 { margin: 0 0 12px; font-size: 16px; line-height: 1.5; }
.rule-list { padding-left: 19px; margin: 0; color: #4d6269; font-size: 13px; }
.rule-list li + li { margin-top: 9px; }
.rule-list strong { color: var(--ink); }
.share-tools { display: grid; gap: 10px; }
.share-tools button { background: var(--accent); color: #fffaf4; border-color: var(--accent); width: 100%; }
.share-tools button:hover { background: #a83b29; border-color: #a83b29; }
.share-fallback { margin-top: 10px; }
.share-fallback label { display: block; font-size: 12px; font-weight: 650; margin-bottom: 5px; }
.share-fallback input { display: block; width: 100%; min-width: 0; border: 1px solid #acb9b2; border-radius: 9px; padding: 10px; background: #fffef9; color: var(--ink); font-size: 12px; min-height: 44px; }
.small-note { font-size: 12px; color: var(--muted); line-height: 1.75; margin: 10px 0 0; }
.notice, .storage-note { background: var(--accent-soft); border-left: 3px solid #bf7c46; border-radius: 6px; padding: 10px 12px; color: #754529; font-size: 12px; line-height: 1.7; overflow-wrap: anywhere; }
.notice { margin: 0 0 16px; }
.storage-note { margin: 12px 0 0; }
.records-list { display: grid; list-style: none; padding: 0; margin: 0; gap: 10px; }
.records-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.records-heading > div { min-width: 0; }
.records-heading .eyebrow { margin-bottom: 8px; }
.records-heading .section-title { margin-bottom: 0; }
.records-heading #clearButton { flex: 0 0 auto; margin: 0; }
.record-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid #e5e5da; }
.record-item:last-child { border-bottom: 0; }
.record-name { display: block; font-size: 12px; font-weight: 650; line-height: 1.7; overflow-wrap: anywhere; }
.record-name small { display: block; font-size: 11px; color: var(--muted); font-weight: 400; }
.record-score { font-size: 14px; font-weight: 750; color: #9b412e; white-space: nowrap; }
.empty-note { margin: 0; padding: 8px 0; color: var(--muted); font-size: 13px; }
button.danger, #clearRecords { background: transparent; color: #95412e; border-color: #d1bbb0; font-size: 12px; margin-top: 16px; }
button.danger:hover, #clearRecords:hover { background: #fff0e5; }
.footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; color: var(--muted); font-size: 12px; padding: 36px 0 30px; }
.footer a { min-height: 44px; display: inline-flex; align-items: center; }
.footer p { margin: 0; align-self: center; }
.confirm-dialog { width: min(440px, calc(100% - 32px)); max-width: none; max-height: calc(100dvh - 48px); overflow: auto; margin: auto; border: 1px solid #cbd0c4; border-radius: 22px; padding: 26px; color: var(--ink); background: var(--surface); box-shadow: 0 22px 90px rgb(20 35 45 / 22%); }
.confirm-dialog::backdrop { background: rgb(24 41 50 / 48%); backdrop-filter: blur(3px); }
.confirm-dialog h2 { margin: 0 0 12px; font-size: 22px; line-height: 1.4; }
.confirm-dialog p { color: #4d6269; margin: 0 0 23px; 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: 14px; }
.dialog-actions button.danger { color: #fffaf4; background: var(--accent); border-color: var(--accent); }
.dialog-actions button.danger:hover { background: #a83b29; border-color: #a83b29; }

@media (max-width: 1000px) {
  .page-shell { padding: 0 26px; }
  .game-layout { grid-template-columns: minmax(0, 1fr) 256px; gap: 18px; }
  .play-panel { padding: 20px; }
  .side-panel > section { padding: 18px; }
  .card { min-height: 77px; }
  .card-name { font-size: 12px; }
}

@media (max-width: 760px) {
  .page-shell { max-width: 650px; padding: 0 22px; }
  .topbar { min-height: 72px; }
  .brand { font-size: 19px; }
  .hero { padding: 36px 0 28px; }
  h1 { font-size: 40px; }
  .intro { font-size: 15px; }
  .game-layout { grid-template-columns: minmax(0, 1fr); }
  .play-panel { border-radius: 21px; padding: 20px; }
  .side-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .side-panel > section:last-child { grid-column: 1 / -1; }
  .card { min-height: 73px; }
  .board { gap: 9px; }
  .card-back::before { font-size: 32px; }
  .card-name { font-size: 13px; }
  .card-icon { width: 43%; max-width: 51px; }
}

@media (max-width: 440px) {
  .page-shell { padding: 0 16px; }
  .home-link { font-size: 12px; }
  .brand { font-size: 18px; }
  .topbar-tag { max-width: 45%; font-size: 10px; }
  .hero { padding: 28px 0 24px; }
  h1 { font-size: 36px; }
  .hero-note { font-size: 12px; margin-top: 13px; }
  .play-panel { padding: 15px; border-radius: 18px; }
  .toolbar { gap: 12px; padding-bottom: 17px; }
  .mode-switch { width: 100%; }
  .mode-switch button { font-size: 12px; padding: 8px; }
  .toolbar-actions { gap: 7px; }
  .toolbar-actions button { font-size: 12px; padding: 8px 10px; }
  .board-meta { margin-top: 18px; margin-bottom: 14px; }
  .board-title { font-size: 16px; }
  #boardSeed { font-size: 11px; }
  .stats-grid { gap: 6px; }
  .stat { padding: 10px 4px; border-radius: 11px; }
  .stat strong { font-size: 23px; }
  .stat span { font-size: 11px; }
  .game-status { font-size: 12px; min-height: 42px; }
  .board { gap: 7px; }
  .card { min-height: 78px; padding: 5px 3px; border-radius: 11px; }
  .card-back::before { font-size: 27px; }
  .card-number { font-size: 10px; }
  .card-icon { width: 44%; min-width: 25px; }
  .card-name { font-size: 11px; }
  .card-state { font-size: 9px; }
  .card-front { gap: 2px; }
  .side-panel { grid-template-columns: minmax(0, 1fr); gap: 14px; }
  .side-panel > section { padding: 19px; border-radius: 17px; }
  .side-panel > section:last-child { grid-column: auto; }
  .completion { padding: 15px; }
  .confirm-dialog { padding: 21px; border-radius: 18px; }
  .dialog-actions { flex-direction: column; }
  .dialog-actions button { width: 100%; }
  .footer { padding-top: 24px; gap: 0; }
}

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