:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0eee9;
  --text: #1c1b19;
  --text-dim: #6b6862;
  --border: #dcd9d2;
  --accent: #3a6ea5;
  --accent-text: #ffffff;
  --light-sq: #f0d9b5;
  --dark-sq: #b58863;
  --good: #2e7d4f;
  --ok: #b7791f;
  --weak: #b5482e;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #211f1c;
    --surface-2: #2a2824;
    --text: #ecece8;
    --text-dim: #9a968d;
    --border: #38352f;
    --accent: #6ea8dc;
    --accent-text: #14212e;
    --light-sq: #d9c3a0;
    --dark-sq: #9c7250;
    --good: #6fcf97;
    --ok: #e0b055;
    --weak: #e08a72;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 20px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
header, main, footer { max-width: 820px; margin: 0 auto; padding: 0 20px; }
header { padding-top: 40px; }
h1 { margin: 0; font-size: 26px; letter-spacing: -0.01em; }
.tagline { margin: 6px 0 0; color: var(--text-dim); }

.search { position: relative; margin: 28px 0 10px; }
#query {
  width: 100%;
  padding: 13px 40px 13px 15px;
  font-size: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}
#query:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
#clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 30px; height: 30px; border: 0; border-radius: 7px;
  background: transparent; color: var(--text-dim); font-size: 20px; cursor: pointer;
}
#clear:hover { background: var(--surface-2); color: var(--text); }

.rating-filter { display: flex; align-items: center; gap: 8px; margin: 0 2px 6px; font-size: 13px; color: var(--text-dim); }
.rating-filter input {
  width: 90px; padding: 6px 9px; font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px;
}
.rating-filter input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }

.status { min-height: 20px; margin: 6px 2px 16px; color: var(--text-dim); font-size: 13px; }
.status .bad { color: var(--weak); font-family: ui-monospace, monospace; }

.results { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card > summary {
  list-style: none;
  cursor: pointer;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  align-items: baseline;
}
.card > summary::-webkit-details-marker { display: none; }
.card > summary:hover { background: var(--surface-2); }
.title { font-weight: 600; }
.meta { color: var(--text-dim); font-size: 13px; }
.badges { grid-column: 2; grid-row: 1 / span 2; text-align: right; white-space: nowrap; }
.pill {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; background: var(--surface-2); color: var(--text-dim);
}
.pill.good { color: var(--good); } .pill.ok { color: var(--ok); } .pill.weak { color: var(--weak); }
.moves-inline {
  grid-column: 1 / -1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px; color: var(--text); margin-top: 4px;
  overflow-x: auto; white-space: nowrap;
}
mark { background: color-mix(in srgb, var(--accent) 30%, transparent); color: inherit; border-radius: 3px; }

.detail { padding: 0 16px 16px; border-top: 1px solid var(--border); }
.detail-grid { display: grid; grid-template-columns: auto 1fr; gap: 18px; align-items: start; margin-top: 14px; }
@media (max-width: 560px) { .detail-grid { grid-template-columns: 1fr; } }

.board { width: 288px; max-width: 100%; }
.board svg { width: 100%; height: auto; display: block; border-radius: 6px; }
.nav { display: flex; gap: 8px; align-items: center; margin-top: 8px; font-size: 13px; color: var(--text-dim); }
.nav button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 7px; padding: 4px 10px; cursor: pointer; font-size: 13px;
}
.nav button:disabled { opacity: .4; cursor: default; }

.clock-label {
  margin-top: 6px; font-size: 12px; color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.clock-label[hidden] { display: none; }

.move-watch {
  display: block; margin-top: 8px; font-size: 12px;
  color: var(--accent); text-decoration: none;
}
.move-watch:hover { text-decoration: underline; }
.move-watch[hidden] { display: none; }

.pgn {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px; line-height: 1.7;
  background: var(--surface-2); border-radius: 8px; padding: 10px 12px;
  white-space: pre-wrap; word-break: break-word;
}
.detail-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.detail-actions a, .detail-actions button {
  font-size: 13px; text-decoration: none;
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 11px; cursor: pointer;
  background: var(--surface); color: var(--text);
}
.detail-actions a.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }

footer { color: var(--text-dim); font-size: 12px; padding: 40px 20px 60px; }
.empty { padding: 40px 0; text-align: center; color: var(--text-dim); }
