/* Tabiya Scoresheet Scanner. Phone first; colors match tabiyachessdatabase.com. */
:root {
  --ink: #22252b;
  --slate: #2f333c;
  --slate-2: #383d47;
  --line: #454a53;
  --parchment: #ece8df;
  --muted: #9aa0ab;
  --brass: #c9974e;
  --brass-ink: #22252b;
  --red: #e07a6a;
  --red-bg: rgba(224, 122, 106, 0.18);
  --amber: #e2b85a;
  --amber-bg: rgba(226, 184, 90, 0.16);
  --green: #8fbf7f;
  --sq-light: #e8d9b8;
  --sq-dark: #7c5c3e;
  --sq-mark: rgba(201, 151, 78, 0.55);
  --radius: 6px;
  --gutter: 16px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ink); }
body {
  color: var(--parchment);
  font-family: "Work Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }

.top {
  display: flex; align-items: baseline; gap: 10px;
  padding: calc(14px + env(safe-area-inset-top)) var(--gutter) 10px;
  border-bottom: 1px solid var(--line);
}
.brand { font-family: "Fraunces", Georgia, serif; font-style: italic; font-size: 22px; color: var(--brass); }
.sub { font-family: "JetBrains Mono", Consolas, monospace; font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }

main { max-width: 560px; margin: 0 auto; padding: 8px var(--gutter) 32px; }
section { display: flex; flex-direction: column; gap: 12px; }

h1 { font-family: "Fraunces", Georgia, serif; font-style: italic; font-weight: 500; font-size: 30px; line-height: 1.2; margin: 16px 0 4px; }
h2 { font-family: "Fraunces", Georgia, serif; font-style: italic; font-weight: 500; font-size: 22px; margin: 20px 0 0; }
p { margin: 0; color: var(--muted); }
.hint, .fine { font-size: 14px; }
.fine { color: var(--muted); }
.center { text-align: center; }
.error { color: var(--red); font-weight: 500; }
.mono, code { font-family: "JetBrains Mono", Consolas, monospace; }
label { color: var(--parchment); font-weight: 500; }

input, select, textarea {
  width: 100%; font: inherit; font-size: 17px; color: var(--parchment);
  background: var(--slate); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 12px; min-height: 48px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brass); outline-offset: 1px; }
textarea { resize: vertical; font-size: 14px; line-height: 1.5; }

button, .filebtn {
  font: inherit; font-weight: 600; border-radius: var(--radius); border: 0; cursor: pointer;
  min-height: 48px; padding: 10px 16px; display: inline-flex; align-items: center; justify-content: center;
  text-align: center; -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
button:disabled { opacity: .45; cursor: not-allowed; }
.primary { background: var(--brass); color: var(--brass-ink); }
.primary:not(:disabled):active { filter: brightness(.92); }
.secondary { background: var(--slate-2); color: var(--parchment); border: 1px solid var(--line); }
.big { min-height: 60px; font-size: 19px; width: 100%; }
.huge { min-height: 76px; font-size: 20px; width: 100%; line-height: 1.25; }
.link { background: none; color: var(--brass); padding: 4px 0; min-height: 36px; font-weight: 500; }
.icon { background: var(--slate-2); color: var(--parchment); min-width: 52px; font-size: 18px; border: 1px solid var(--line); }
.icon svg { width: 20px; height: 20px; fill: currentColor; }
.icon svg.line { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.filebtn { position: relative; overflow: hidden; width: 100%; }
.filebtn.big, label.primary.filebtn { min-height: 72px; font-size: 21px; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; min-height: 0; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.banner { background: var(--red-bg); color: var(--parchment); padding: 10px var(--gutter); font-size: 15px; text-align: center; }

/* Photos */
.page-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.page-list:empty { display: none; }
.page { position: relative; background: var(--slate); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.page img { display: block; width: 100%; aspect-ratio: 3 / 4; object-fit: cover; }
.page .n { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.6); padding: 0 8px; border-radius: 4px; font-size: 14px; }
.page .rm { position: absolute; right: 4px; top: 4px; min-height: 40px; min-width: 40px; padding: 0; background: rgba(0,0,0,.6); color: var(--parchment); }

.details { background: var(--slate); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 14px; }
.details summary { min-height: 52px; display: flex; align-items: center; cursor: pointer; font-weight: 500; }
.details[open] { padding-bottom: 14px; }
.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.fields .wide { grid-column: 1 / -1; }
.fields label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); font-weight: 500; }

/* Reading */
.stages { list-style: none; margin: 8px 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.stages li { padding: 12px 14px 12px 44px; position: relative; background: var(--slate); border-radius: var(--radius); color: var(--muted); }
.stages li::before { content: ""; position: absolute; left: 16px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%; border: 2px solid var(--line); }
.stages li.active { color: var(--parchment); }
.stages li.active::before { border-color: var(--brass); border-top-color: transparent; animation: spin 0.9s linear infinite; }
.stages li.done { color: var(--parchment); }
.stages li.done::before { background: var(--brass); border-color: var(--brass); }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .stages li.active::before { animation: none; border-top-color: var(--brass); } }
.elapsed { font-family: "JetBrains Mono", Consolas, monospace; font-size: 40px; color: var(--parchment); text-align: center; }

/* Board */
.board-wrap { position: sticky; top: 0; z-index: 2; background: var(--ink); padding-top: 8px; margin: 0 calc(-1 * var(--gutter)); padding-left: var(--gutter); padding-right: var(--gutter); }
/* Small enough on a phone to leave room for the move list under it. */
.board { display: grid; grid-template-columns: repeat(8, 1fr); width: min(100%, 38vh, 420px); margin: 0 auto; aspect-ratio: 1; border-radius: 4px; overflow: hidden; }
.board.small { width: min(100%, 300px); }
.board div { position: relative; }
.board .l { background: var(--sq-light); }
.board .d { background: var(--sq-dark); }
.board .mark::after { content: ""; position: absolute; inset: 0; background: var(--sq-mark); }
.board img { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; }
.nav { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 0; max-width: 420px; margin: 0 auto; }
.nav .ply { flex: 1; text-align: center; font-size: 15px; color: var(--muted); }
.nav .icon { min-height: 44px; }

.reader-note { background: var(--slate); border-left: 3px solid var(--brass); padding: 10px 12px; border-radius: 4px; font-size: 15px; }

/* Move list */
.moves { display: grid; grid-template-columns: 2.4em 1fr 1fr; gap: 4px; }
.moves .num { color: var(--muted); font-family: "JetBrains Mono", Consolas, monospace; font-size: 14px; display: flex; align-items: center; justify-content: flex-end; padding-right: 6px; }
.mv { scroll-margin-top: calc(38vh + 80px); scroll-margin-bottom: 90px; min-height: 44px; padding: 6px 10px; justify-content: flex-start; background: var(--slate); color: var(--parchment); font-weight: 500;
      border: 1px solid transparent; font-family: "JetBrains Mono", Consolas, monospace; font-size: 15px; }
.mv.check { background: var(--amber-bg); border-color: var(--amber); }
.mv.illegal { background: var(--red-bg); border-color: var(--red); }
.mv.blocked { color: var(--muted); background: transparent; border: 1px dashed var(--line); }
.mv.current { outline: 2px solid var(--brass); outline-offset: -2px; }
.mv .flag { margin-left: auto; font-size: 12px; font-family: "Work Sans", sans-serif; font-weight: 600; }
.mv.check .flag { color: var(--amber); }
.mv.illegal .flag { color: var(--red); }
.mv.gap::before { content: "⋯ "; color: var(--amber); }
.mv.empty { visibility: hidden; }

.spacer { height: 76px; }
.footbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
           padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom)); background: var(--slate); border-top: 1px solid var(--line); }
.footbar span { flex: 1; font-size: 15px; }
.footbar .primary { min-width: 140px; min-height: 52px; }

/* Approval */
.summary { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; background: var(--slate); padding: 12px 14px; border-radius: var(--radius); }
.summary dt { color: var(--muted); font-size: 14px; }
.summary dd { margin: 0; overflow-wrap: anywhere; }
.movetext { font-size: 14px; color: var(--parchment); line-height: 1.7; background: var(--slate); padding: 12px 14px; border-radius: var(--radius); }

/* Done */
.status { color: var(--parchment); background: var(--slate); padding: 12px 14px; border-radius: var(--radius); border-left: 3px solid var(--brass); }
.status.ok { border-left-color: var(--green); }
.status.bad { border-left-color: var(--red); }
.row.three > * { min-width: 0; }

/* Fix sheet */
dialog.sheet { width: 100%; max-width: 560px; margin: auto auto 0; padding: 0; border: 0; border-radius: 14px 14px 0 0;
               background: var(--slate); color: var(--parchment); max-height: 72vh; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.35); }
.sheet-inner { display: flex; flex-direction: column; gap: 10px; padding: 14px var(--gutter) calc(18px + env(safe-area-inset-bottom)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { margin: 0; }
.label { font-size: 14px; color: var(--muted); font-weight: 500; }
.cands { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; }
.cands button { background: var(--slate-2); color: var(--parchment); border: 1px solid var(--line); flex-direction: column; gap: 0;
                font-family: "JetBrains Mono", Consolas, monospace; font-size: 17px; min-height: 56px; padding: 6px; }
.cands button small { font-family: "Work Sans", sans-serif; font-size: 11px; color: var(--muted); font-weight: 500; }
.cands button.best { border-color: var(--brass); }
.cands.all button { min-height: 44px; font-size: 15px; }
.type-move { display: flex; gap: 8px; }
.type-move button { min-width: 80px; }
.extra { display: flex; flex-direction: column; gap: 8px; }

.foot { max-width: 560px; margin: 0 auto; padding: 8px var(--gutter) 24px; display: flex; align-items: center; justify-content: space-between; font-size: 14px; color: var(--muted); }

@media (min-width: 700px) {
  h1 { font-size: 34px; }
}
