:root {
  color-scheme: dark;
  --background: #080b12;
  --surface: #111621;
  --surface-raised: #171e2b;
  --border: #293143;
  --text: #f4f1e8;
  --muted: #9ca6b8;
  --gold: #f6c453;
  --gold-dark: #9a6d13;
  --green: #53d69a;
  --red: #ff7a83;
  --radius: 18px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 18% -5%, rgba(113, 82, 29, 0.28), transparent 34rem),
    radial-gradient(circle at 90% 25%, rgba(28, 76, 73, 0.18), transparent 31rem),
    var(--background);
}

button, input, select { font: inherit; }
button, label[for="upload"] { -webkit-tap-highlight-color: transparent; }

.shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.brand { display: flex; align-items: center; gap: 13px; font-weight: 750; letter-spacing: -0.02em; }
.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid #584420;
  border-radius: 12px;
  color: var(--gold);
  background: #17140e;
  font-size: 27px;
}

.model-status {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
}
.model-status::before { content: ""; width: 8px; height: 8px; border-radius: 999px; background: #788397; }
.model-status[data-mode="loading"]::before { background: var(--gold); box-shadow: 0 0 0 4px rgba(246,196,83,.1); }
.model-status[data-mode="ready"]::before { background: var(--green); }
.model-status[data-mode="error"]::before { background: var(--red); }

main { padding: 76px 0 90px; }
.hero { max-width: 780px; margin-bottom: 44px; }
.eyebrow { margin: 0 0 14px; color: var(--gold); font-size: .78rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
h1 { margin: 0; max-width: 740px; font-size: clamp(2.65rem, 7vw, 5.5rem); line-height: .98; letter-spacing: -.065em; }
.lede { max-width: 650px; margin: 24px 0 0; color: var(--muted); font-size: clamp(1rem, 2vw, 1.17rem); line-height: 1.7; }

.card {
  padding: clamp(20px, 4vw, 34px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: linear-gradient(145deg, rgba(23,30,43,.97), rgba(13,18,28,.97));
  box-shadow: 0 24px 70px rgba(0,0,0,.25);
}
.card + .card { margin-top: 28px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 24px; }
.section-heading h2 { margin: 0 0 7px; font-size: 1.35rem; letter-spacing: -.025em; }
.section-heading p { margin: 0; color: var(--muted); line-height: 1.55; }

.upload-zone {
  display: grid;
  min-height: 220px;
  place-items: center;
  padding: 28px;
  border: 1.5px dashed #475166;
  border-radius: 14px;
  text-align: center;
  background: rgba(7,10,17,.4);
  transition: border-color .2s, background .2s, transform .2s;
}
.upload-zone:hover, .upload-zone.dragging { border-color: var(--gold); background: rgba(246,196,83,.045); transform: translateY(-1px); }
.upload-zone.has-image { border-style: solid; border-color: #4a5d55; }
.upload-icon { display: block; margin-bottom: 17px; color: var(--gold); font-size: 2.3rem; }
.upload-zone strong { display: block; margin-bottom: 6px; font-size: 1.08rem; }
.upload-zone span { color: var(--muted); font-size: .92rem; }
.upload-zone label { display: inline-block; margin-top: 20px; padding: 10px 16px; border-radius: 9px; color: #1b1507; background: var(--gold); font-weight: 750; cursor: pointer; }
#upload { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }

.editor-wrap { overflow: hidden; border: 1px solid #343e51; border-radius: 13px; background: #05070b; }
#crop-editor { display: block; width: 100%; height: auto; max-height: 680px; touch-action: none; cursor: move; }
.editor-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 12px; color: var(--muted); font-size: .88rem; }

.ghost-button, .copy-button {
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
}
.ghost-button { padding: 8px 12px; }
.copy-button { flex: none; padding: 7px 10px; color: var(--muted); font-size: .78rem; }
.ghost-button:hover, .copy-button:hover { border-color: #59657b; color: #fff; }

.controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-top: 26px; }
.control { display: grid; gap: 8px; }
.control label { color: #c8cfda; font-size: .86rem; font-weight: 650; }
select, input[type="range"] { width: 100%; }
select { padding: 11px 12px; border: 1px solid var(--border); border-radius: 9px; color: var(--text); background: #0d121c; }
.range-label { display: flex; justify-content: space-between; }

.primary-button {
  width: 100%;
  margin-top: 24px;
  padding: 14px 20px;
  border: 0;
  border-radius: 10px;
  color: #1b1507;
  background: linear-gradient(135deg, #ffd46f, #eeb642);
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(213,153,37,.15);
}
.primary-button:disabled { color: #808897; background: #2b3340; box-shadow: none; cursor: not-allowed; }

.result-grid { display: grid; grid-template-columns: minmax(260px, 1fr) minmax(0, 1.25fr); gap: 28px; }
.preview-frame { overflow: hidden; border-radius: 12px; background: #070a10; }
#crop-preview { display: block; width: 100%; height: auto; }
.predicted-board { display: grid; grid-template-columns: repeat(8, 1fr); width: 100%; aspect-ratio: 1; overflow: hidden; border-radius: 12px; }
.board-square { display: grid; position: relative; place-items: center; aspect-ratio: 1; font-size: clamp(1.65rem, 5.2vw, 3.7rem); line-height: 1; }
.board-square.light { background: #d8c7a3; }
.board-square.dark { background: #6d775e; }
.board-square.white-piece { color: #fff8e8; text-shadow: 0 1px 2px #111820, 0 0 1px #111820; }
.board-square.black-piece { color: #171a20; text-shadow: 0 1px 1px rgba(255,255,255,.3); }
.board-square.uncertain::after { content: ""; position: absolute; inset: 3px; border: 3px solid #ff535e; border-radius: 3px; }
.panel-label { margin: 0 0 10px; color: var(--muted); font-size: .8rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }

.fen-group { margin-top: 28px; }
.fen-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px; border: 1px solid var(--border); border-radius: 10px; background: #090d15; }
.fen-line code { overflow: auto; color: #f8df9f; font-family: "SFMono-Regular", Consolas, monospace; white-space: nowrap; }
.assumption { margin: 8px 0 0; color: var(--muted); font-size: .79rem; }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 22px; }
.metric { padding: 16px; border: 1px solid var(--border); border-radius: 11px; background: rgba(7,10,17,.42); }
.metric span { display: block; margin-bottom: 6px; color: var(--muted); font-size: .78rem; }
.metric strong { font-size: 1.55rem; }
.confidence-note { margin: 14px 0 0; color: #c4cad4; font-size: .9rem; }
.timing { margin: 6px 0 0; color: var(--muted); font-size: .82rem; }

details { margin-top: 24px; border-top: 1px solid var(--border); padding-top: 20px; }
summary { cursor: pointer; font-weight: 700; }
.table-wrap { max-height: 420px; margin-top: 15px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th { position: sticky; top: 0; color: var(--muted); background: #121824; text-align: left; }
th, td { padding: 10px 12px; border-bottom: 1px solid #252d3c; }
tr.low-row td { color: #ffadb2; }

.error { margin: 18px 0 0; padding: 13px 15px; border: 1px solid rgba(255,122,131,.4); border-radius: 9px; color: #ffc4c8; background: rgba(150,34,45,.16); }
.privacy { display: flex; gap: 12px; align-items: flex-start; margin-top: 18px; color: var(--muted); font-size: .84rem; line-height: 1.5; }
.privacy strong { color: var(--green); }
[hidden] { display: none !important; }

footer { padding: 28px 0 40px; border-top: 1px solid rgba(255,255,255,.08); color: var(--muted); font-size: .84rem; }

@media (max-width: 760px) {
  header { align-items: flex-start; flex-direction: column; }
  main { padding-top: 48px; }
  .controls, .result-grid { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: 1fr; }
  .section-heading { flex-direction: column; }
  .board-square { font-size: clamp(1.6rem, 10vw, 3rem); }
}
