:root {
  color-scheme: light;
  --ink: #202124;
  --muted: #707176;
  --line: #d9d7d1;
  --paper: #f3f2ed;
  --panel: #fffefa;
  --red: #861b20;
  --red-dark: #651217;
  --gold: #c6a969;
  --night: #17191c;
  --green: #637d68;
  font-family: "Segoe UI", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { background: var(--paper); }
body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(90deg, transparent 0 49.9%, #c8c4b91a 50%, transparent 50.1%),
    var(--paper);
}
button, input { font: inherit; }
button { color: inherit; }
a { color: inherit; }

.site-frame { min-height: 100vh; }
.site-header {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 0 clamp(18px, 4vw, 58px);
  color: #f7f6f1;
  background: var(--night);
  border-bottom: 3px solid var(--red);
}
.brand { display: inline-flex; align-items: center; gap: 11px; text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 45px;
  height: 30px;
  border: 1px solid #b88d52;
  color: #f9f6eb;
  font-family: Georgia, serif;
  font-size: 10px;
  letter-spacing: .06em;
  font-weight: 700;
}
.brand-copy { display: grid; gap: 2px; }
.brand-copy strong { font-family: Georgia, serif; font-size: 16px; letter-spacing: .18em; }
.brand-copy small { color: #bab9b2; font-size: 9px; letter-spacing: .15em; }
.site-nav { display: flex; align-items: center; gap: clamp(14px, 2.8vw, 34px); }
.site-nav a { color: #d9d8d2; font-size: 12px; text-decoration: none; transition: color .16s ease; }
.site-nav a:hover, .site-nav a:focus-visible { color: #fff; text-decoration: underline; text-underline-offset: 4px; }

main { width: min(1120px, calc(100% - 36px)); margin: 0 auto; }
.intro { padding: 38px 4px 24px; }
.eyebrow, .panel-index {
  color: var(--red);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
}
.eyebrow { display: flex; align-items: center; gap: 9px; }
.eyebrow-line { display: inline-block; width: 26px; height: 1px; background: var(--gold); }
.eyebrow span:not(.eyebrow-line) { color: #aaa69a; }
.intro-row { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-top: 12px; }
h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 7px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(40px, 6.4vw, 66px);
  line-height: 1.05;
  letter-spacing: -.045em;
  font-weight: 500;
}
h1 em { color: var(--red); font-style: normal; }
.intro-copy { margin: 0; color: #5f6064; font-size: 14px; }
.threshold {
  flex: none;
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 4px;
  padding: 8px 13px;
  border: 1px solid #cfc5ad;
  border-radius: 2px;
  color: #65615a;
  font-size: 11px;
  background: #faf8f1;
}
.threshold strong { color: var(--red); font-size: 16px; }
.threshold-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); }

.play-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(260px, .65fr); gap: 18px; align-items: stretch; }
.panel { border: 1px solid #d7d4cd; background: var(--panel); box-shadow: 0 4px 18px #3933290a; }
.draw-panel, .reference-panel { min-width: 0; padding: 19px; }
.panel-heading, .panel-heading > div { display: flex; align-items: center; }
.panel-heading { justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.panel-heading > div { gap: 10px; }
.panel-index { flex: none; color: #9a8d73; font-variant-numeric: tabular-nums; }
.panel-heading h2, .leaderboard-heading h2 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: .01em; }
.live-status, .reference-lock { display: inline-flex; align-items: center; gap: 6px; color: #77766f; font-size: 10px; white-space: nowrap; }
.live-status i, .local-badge i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: #a8a49b; }
.live-status.is-drawing i { background: var(--green); box-shadow: 0 0 0 3px #637d681a; }
.live-status.is-drawing { color: #54705a; }
.reference-lock { padding: 4px 7px; border: 1px solid #ded9cd; text-transform: uppercase; letter-spacing: .08em; }

.canvas-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  background-color: var(--night);
  background-image: radial-gradient(#ffffff17 .65px, transparent .65px);
  background-size: 12px 12px;
  touch-action: none;
}
#drawCanvas { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.canvas-guide {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #aaa9a4;
  pointer-events: none;
  font-size: 11px;
  letter-spacing: .04em;
  transition: opacity .15s ease;
}
.canvas-guide.is-hidden { opacity: 0; }
.guide-cross { color: #c6a969; font-size: 24px; font-weight: 200; }
.canvas-corner { position: absolute; z-index: 1; width: 12px; height: 12px; border-color: #bca773; opacity: .7; pointer-events: none; }
.corner-tl { left: 9px; top: 9px; border-left: 1px solid; border-top: 1px solid; }
.corner-tr { right: 9px; top: 9px; border-right: 1px solid; border-top: 1px solid; }
.corner-bl { left: 9px; bottom: 9px; border-left: 1px solid; border-bottom: 1px solid; }
.corner-br { right: 9px; bottom: 9px; border-right: 1px solid; border-bottom: 1px solid; }

.drawing-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 11px; padding: 13px 0 11px; border-bottom: 1px solid #e6e3dc; }
.tool-group { display: inline-flex; gap: 3px; padding: 3px; background: #efeee9; }
.tool-button, .quiet-button {
  border: 0;
  padding: 7px 9px;
  background: transparent;
  cursor: pointer;
  font-size: 11px;
  transition: color .15s ease, background .15s ease, opacity .15s ease;
}
.tool-button { color: #68686b; }
.tool-button.active { color: #fff; background: #333438; }
.tool-button:focus-visible, .quiet-button:focus-visible, .score-button:focus-visible, .rank-button:focus-visible, .retry-button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.brush-control { display: inline-flex; align-items: center; gap: 8px; color: #68686b; font-size: 10px; }
.brush-control input { width: 75px; accent-color: var(--red); }
.brush-control output { min-width: 17px; color: #35363a; font-variant-numeric: tabular-nums; }
.tool-group-secondary { margin-left: auto; background: transparent; }
.quiet-button { color: #65666a; padding-inline: 8px; }
.quiet-button:hover:not(:disabled) { color: var(--red); background: #f3ece9; }
.quiet-button:disabled { opacity: .38; cursor: default; }
.draw-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-top: 13px; }
.draw-footer p { margin: 0; color: #77777a; font-size: 10px; line-height: 1.6; }
.score-button, .rank-button, .retry-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 13px;
  border: 1px solid var(--red);
  padding: 10px 13px;
  color: #fff;
  background: var(--red);
  cursor: pointer;
  font-size: 11px;
  font-weight: 650;
  white-space: nowrap;
  transition: background .15s ease, transform .15s ease, opacity .15s ease;
}
.score-button:hover:not(:disabled), .rank-button:hover:not(:disabled) { background: var(--red-dark); transform: translateY(-1px); }
.score-button:disabled, .rank-button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.game-message { min-height: 18px; margin: 10px 0 0; color: #8b1c22; font-size: 10px; }

.reference-panel { display: flex; flex-direction: column; }
.reference-stage {
  flex: 1;
  min-height: 280px;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: #ddd7c9;
  background: var(--night);
  background-image: radial-gradient(#ffffff15 .65px, transparent .65px);
  background-size: 12px 12px;
}
.reference-locked { display: grid; gap: 9px; justify-items: center; text-align: center; }
.lock-symbol { color: var(--gold); font-family: Georgia, serif; font-size: 29px; }
.reference-locked strong { color: #f2eee5; font-family: Georgia, serif; font-size: 16px; font-weight: 500; }
.reference-locked span:last-child { color: #a7a49c; font-size: 10px; }
.reference-stage img { width: min(68%, 210px); max-height: 70%; object-fit: contain; }
.reference-caption { display: flex; justify-content: space-between; gap: 8px; padding: 10px 0 9px; border-bottom: 1px solid #e5e2db; color: #89857b; font-size: 9px; letter-spacing: .12em; }
.reference-note { display: flex; align-items: flex-start; gap: 9px; padding-top: 12px; }
.reference-note p { margin: 0; color: #77777a; font-size: 10px; line-height: 1.65; }
.note-mark { display: grid; flex: none; place-items: center; width: 14px; height: 14px; border: 1px solid #b9aa83; border-radius: 50%; color: #8d7b54; font-family: Georgia, serif; font-size: 9px; }

.result-panel { display: grid; grid-template-columns: 1fr auto minmax(200px, .8fr); align-items: center; gap: 22px; margin-top: 18px; padding: 19px 22px; border-left: 3px solid var(--red); }
.result-copy h2 { margin: 6px 0 3px; font-family: Georgia, serif; font-size: 20px; font-weight: 500; }
.result-copy p { margin: 0; color: #77777a; font-size: 11px; }
.score-display { display: flex; align-items: baseline; color: var(--red); font-family: Georgia, serif; font-variant-numeric: tabular-nums; }
.score-display strong { font-size: 43px; font-weight: 500; letter-spacing: -.05em; }
.score-display span { margin-left: 3px; font-size: 17px; }
.result-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 8px; }
.rank-gate { color: #77777a; font-size: 10px; }
.rank-button { padding: 9px 11px; }
.retry-button { border-color: #cac6bc; color: #56565a; background: transparent; }
.retry-button:hover { border-color: var(--red); color: var(--red); }

.leaderboard { margin-top: 22px; padding: 18px 20px 8px; }
.leaderboard-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.leaderboard-heading > div { display: grid; gap: 6px; }
.leaderboard-heading h2 { font-family: Georgia, serif; font-size: 19px; font-weight: 500; }
.local-badge { display: inline-flex; align-items: center; gap: 7px; padding: 5px 8px; color: #68665f; border: 1px solid #ddd9ce; font-size: 9px; letter-spacing: .04em; white-space: nowrap; }
.local-badge i { background: #c6a969; }
.leaderboard-subtitle { margin: 10px 0 0; color: #77777a; font-size: 10px; }
.leaderboard-list { margin-top: 13px; }
.more-entries { display: block; margin: 12px auto 4px; border: 1px solid #d1cdc4; padding: 8px 16px; color: #5f5a50; background: transparent; cursor: pointer; font-size: 10px; }
.more-entries:hover { border-color: var(--gold); color: var(--red); }
.leaderboard-empty { display: grid; place-items: center; min-height: 92px; border-top: 1px solid #e5e2db; color: #8d8a83; font-size: 11px; text-align: center; }
.leaderboard-entry { display: grid; grid-template-columns: 35px 62px minmax(0,1fr) auto; align-items: center; gap: 13px; min-height: 75px; border-top: 1px solid #e5e2db; }
.entry-rank { color: #aaa28e; font-family: Georgia, serif; font-size: 18px; text-align: center; }
.entry-preview { width: 54px; height: 54px; object-fit: contain; padding: 4px; background: var(--night); }
.entry-name { overflow: hidden; color: #343539; font-size: 12px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.entry-date { margin-top: 4px; color: #96938c; font-size: 9px; }
.entry-score { color: var(--red); font-family: Georgia, serif; font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }

.site-footer { display: flex; justify-content: space-between; gap: 12px; padding: 18px 3px 26px; color: #89867e; font-size: 9px; letter-spacing: .1em; }
.rank-dialog { width: min(450px, calc(100% - 26px)); border: 1px solid #d2cec4; padding: 0; color: var(--ink); background: var(--panel); box-shadow: 0 18px 80px #0005; }
.rank-dialog::backdrop { background: #161719ad; backdrop-filter: blur(3px); }
.rank-dialog form { position: relative; padding: 27px; }
.dialog-close { position: absolute; top: 11px; right: 14px; border: 0; color: #777; background: transparent; cursor: pointer; font-size: 24px; }
.rank-dialog h2 { margin: 9px 0 8px; font-family: Georgia, serif; font-size: 25px; font-weight: 500; }
.rank-dialog form > p { margin: 0 0 18px; color: #737378; font-size: 11px; line-height: 1.65; }
.name-label { display: block; margin-bottom: 6px; color: #5d5d61; font-size: 10px; }
.name-label + input { width: 100%; border: 1px solid #cfccc4; border-radius: 0; padding: 10px; outline-color: var(--gold); font-size: 12px; }
.consent-row { display: flex; align-items: flex-start; gap: 8px; margin: 14px 0 18px; color: #5e5e62; font-size: 10px; line-height: 1.5; }
.consent-row input { margin: 2px 0 0; accent-color: var(--red); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
.dialog-actions .quiet-button { border: 1px solid #d1cdc4; padding-inline: 13px; }
.dialog-actions .rank-button { min-width: 100px; }
.rank-dialog .dialog-error { margin: 12px 0 0; color: var(--red); font-size: 10px; line-height: 1.5; }
.rank-dialog .dialog-local-note { margin: 13px 0 0; color: #98958d; font-size: 9px; text-align: right; }

@media (max-width: 760px) {
  .site-header { min-height: 62px; padding-inline: 16px; }
  .site-nav { gap: 12px; }
  .site-nav a { font-size: 10px; }
  .site-nav a:last-child { display: none; }
  main { width: min(100% - 24px, 560px); }
  .intro { padding: 29px 1px 18px; }
  .intro-row { align-items: flex-start; flex-direction: column; gap: 13px; margin-top: 10px; }
  .threshold { align-self: flex-start; }
  .intro-copy { max-width: 34em; font-size: 12px; }
  .play-grid { grid-template-columns: 1fr; gap: 12px; }
  .draw-panel, .reference-panel { padding: 14px; }
  .canvas-wrap { max-height: min(94vw, 520px); }
  .drawing-tools { gap: 7px; }
  .brush-control { margin-left: 3px; }
  .tool-group-secondary { margin-left: auto; }
  .draw-footer { align-items: stretch; flex-direction: column; gap: 10px; }
  .score-button { justify-content: space-between; width: 100%; }
  .reference-stage { min-height: 220px; }
  .reference-stage img { width: min(56%, 180px); }
  .result-panel { grid-template-columns: 1fr auto; gap: 7px 10px; padding: 16px; }
  .result-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .rank-gate { flex: 1 0 100%; }
  .leaderboard { padding-inline: 14px; }
  .leaderboard-heading h2 { font-size: 17px; }
  .leaderboard-entry { grid-template-columns: 27px 52px minmax(0,1fr) auto; gap: 8px; }
  .entry-preview { width: 48px; height: 48px; }
  .site-footer { flex-direction: column; }
}

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