:root {
  --bg: #f6f5f1; --panel: #fff; --ink: #1d1d1b; --mute: #6d6a63; --line: #e3e0d8;
  --accent: #2f6b4f; --accent-ink: #fff; --bad: #b3402e;
  --lt: #ecd9b9; --dk: #b58863; --last: rgba(155, 199, 0, .38); --sel: rgba(20, 85, 30, .45);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #1b1b1a; --panel: #242422; --ink: #ecebe6; --mute: #a29f97; --line: #363532; --accent: #5fa47f; --accent-ink: #0e1a13; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: inherit; }
button, select, input { font: inherit; color: inherit; }

.top { display: flex; align-items: center; gap: 24px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; text-decoration: none; }
.brand img { width: 30px; height: 30px; }
.top nav { display: flex; gap: 4px; }
.top nav a { text-decoration: none; padding: 6px 12px; border-radius: 6px; color: var(--mute); }
.top nav a.on { color: var(--ink); background: var(--bg); }
.foot { text-align: center; color: var(--mute); font-size: 13px; padding: 28px 16px; }
main { max-width: 1180px; margin: 0 auto; padding: 24px 20px; }

h1 { font-size: 28px; margin: 0 0 6px; letter-spacing: -.01em; }
h2 { font-size: 18px; margin: 0 0 12px; }
.sub { color: var(--mute); margin: 0 0 22px; }
.muted { color: var(--mute); }

.btn { border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 6px; cursor: pointer; }
.btn:hover { border-color: var(--mute); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* home */
.home { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 32px; align-items: start; }
.home .preview { max-width: 620px; }
.cards { display: grid; gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 18px; }
.field { margin: 0 0 14px; }
.field > label { display: block; font-size: 13px; color: var(--mute); margin-bottom: 6px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: none; padding: 7px 0; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.seg button img { width: 22px; height: 22px; vertical-align: middle; }
select, input[type=text] { width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.join { display: flex; gap: 8px; }
.join input { text-transform: uppercase; letter-spacing: .12em; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 6px; }

/* game */
.game { display: grid; grid-template-columns: minmax(0, min(78vh, 760px)) 320px; gap: 22px; justify-content: center; align-items: start; }
.boardwrap { position: relative; }
.side { display: flex; flex-direction: column; gap: 10px; }
.strip { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; }
.strip .who { display: flex; align-items: center; gap: 8px; min-width: 0; }
.strip .who img { width: 26px; height: 26px; }
.strip .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strip .mat { color: var(--mute); font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: #4caf50; }
.clock { font: 600 22px/1 ui-monospace, "SF Mono", Menlo, monospace; padding: 6px 10px; border-radius: 6px; background: var(--bg); min-width: 92px; text-align: right; }
.clock.run { background: var(--accent); color: var(--accent-ink); }
.clock.low.run { background: var(--bad); color: #fff; }
.clock.none { display: none; }
.moves { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; height: 300px; overflow-y: auto; font-size: 14px; }
.moves table { width: 100%; border-collapse: collapse; }
.moves td { padding: 3px 8px; }
.moves td.n { width: 38px; color: var(--mute); background: var(--bg); text-align: right; }
.moves td.mv { cursor: pointer; border-radius: 3px; }
.moves td.mv:hover { background: var(--bg); }
.moves td.mv.cur { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.moves .empty { color: var(--mute); padding: 12px; }
.banner { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; text-align: center; }
.banner b { display: block; font-size: 18px; }
.banner.hide { display: none; }
.nav { display: flex; gap: 4px; }
.nav .btn { flex: 1; padding: 6px 0; }
.status { font-size: 13px; color: var(--mute); min-height: 18px; }
.share { display: flex; gap: 6px; }
.share input { font: 600 15px ui-monospace, Menlo, monospace; letter-spacing: .1em; }

.promo { position: absolute; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center; z-index: 10; }
.promo .box { background: var(--panel); border-radius: 10px; padding: 14px; display: grid; grid-template-columns: repeat(6, 64px); gap: 6px; }
.promo button { border: 1px solid var(--line); border-radius: 6px; background: var(--bg); padding: 4px; cursor: pointer; }
.promo button:hover { border-color: var(--accent); }
.promo img { width: 54px; height: 54px; display: block; }
.promo .lbl { grid-column: 1 / -1; font-weight: 600; margin-bottom: 4px; }

/* guide */
.glist { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 30px; }
.gitem { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; text-decoration: none; }
.gitem:hover { border-color: var(--mute); }
.gitem img { width: 40px; height: 40px; }
.gitem small { display: block; color: var(--mute); font-size: 12px; }
.gpage { display: grid; grid-template-columns: minmax(0, 520px) minmax(0, 1fr); gap: 32px; align-items: start; }
.gpage .head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.gpage .head img { width: 72px; height: 72px; }
.gpage .rule { font-size: 17px; margin: 0 0 16px; }
.legend { display: flex; gap: 18px; font-size: 13px; color: var(--mute); margin: 10px 0; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; vertical-align: -2px; }
.legend .lm::before { background: rgba(20, 85, 30, .45); transform: scale(.55); }
.legend .lc::before { border: 3px solid rgba(20, 85, 30, .55); box-sizing: border-box; }
.legend .lf::before { background: var(--sel); border-radius: 2px; }
.pager { display: flex; justify-content: space-between; margin-top: 18px; }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 4px; background: var(--bg); border: 1px solid var(--line); color: var(--mute); }

/* puzzles */
.plist { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.plist a { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; text-decoration: none; }
.plist a.done { border-color: var(--accent); }
.plist img { width: 40px; height: 40px; }
.plist .ok { margin-left: auto; color: var(--accent); font-weight: 700; }
.ptask { font-size: 17px; font-weight: 600; margin: 0 0 6px; }
.pmsg { min-height: 24px; font-weight: 600; margin: 10px 0; }
.pmsg.good { color: var(--accent); }
.pmsg.bad { color: var(--bad); }

@media (max-width: 900px) {
  .home, .game, .gpage { grid-template-columns: minmax(0, 1fr); }
  main { padding: 16px; }
  .top { gap: 10px; padding: 8px 16px; }
  .moves { height: 180px; }
  .promo .box { grid-template-columns: repeat(4, 56px); }
  .promo img { width: 46px; height: 46px; }
}
