:root {
  --bg: #f6f1e7;
  --paper: #fffdf8;
  --ink: #1f1a14;
  --muted: #6d6459;
  --line: #e2d9c8;
  --accent: #8a3b12;
  --accent-soft: #f3e2d3;
  --ok: #2f7a3d;
  --ok-soft: #e0f1e2;
  --bad: #a52a2a;
  --bad-soft: #f8e1e1;
  --gold: #c98f1b;
  --radius: 10px;
  font-size: 16px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--line); background: var(--paper); padding: .45rem .9rem; color: var(--ink); }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { filter: brightness(1.1); }
button.ghost { background: transparent; }
button:disabled { opacity: .45; cursor: default; }
.pill { display: inline-block; min-width: 1.4em; padding: 0 .4em; border-radius: 999px; background: var(--accent); color: #fff; font-size: .75rem; text-align: center; vertical-align: middle; }

header.top { display: flex; justify-content: space-between; align-items: center; padding: .7rem 1.4rem; border-bottom: 1px solid var(--line); background: var(--paper); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; color: var(--ink); font-size: 1.1rem; letter-spacing: .01em; }
header nav a { margin-left: 1.2rem; color: var(--muted); }
header nav a.active { color: var(--accent); font-weight: 600; }

main { max-width: 1180px; margin: 0 auto; padding: 1.4rem; }

/* ---------- home */
.hero { margin: .5rem 0 1.5rem; }
.hero h1 { margin: 0 0 .3rem; font-size: 2rem; font-weight: 700; }
.hero p { margin: 0; color: var(--muted); max-width: 60ch; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; display: flex; flex-direction: column; gap: .4rem; }
.card h3 { margin: 0; font-size: 1.15rem; }
.card .sub { color: var(--muted); font-style: italic; }
.card .meta { font-size: .85rem; color: var(--muted); display: flex; justify-content: space-between; margin-top: .4rem; }
.card .bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.card .bar i { display: block; height: 100%; background: var(--ok); }
.card.locked { opacity: .55; }
.card .num { font-size: .8rem; color: var(--muted); letter-spacing: .08em; text-transform: uppercase; }
.card .actions { margin-top: .6rem; }
.upcoming { margin-top: 2rem; color: var(--muted); }
.upcoming ol { columns: 2; margin: .3rem 0 0; padding-left: 1.2rem; font-size: .9rem; }
.review-box { background: var(--accent-soft); border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 1.4rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.stars { color: var(--gold); letter-spacing: .05em; }

/* ---------- lesson layout */
.lesson { display: grid; grid-template-columns: minmax(300px, 560px) minmax(320px, 1fr); gap: 1.6rem; align-items: start; }
@media (max-width: 860px) { .lesson { grid-template-columns: 1fr; } }
.boardwrap { position: sticky; top: 4.2rem; }
.board { width: 100%; aspect-ratio: 1 / 1; }
.board .cg-wrap { width: 100%; height: 100%; }
.board-caption { display: flex; justify-content: space-between; align-items: center; margin-top: .5rem; font-size: .9rem; color: var(--muted); min-height: 1.6rem; }
.turnbadge { display: inline-flex; align-items: center; gap: .4rem; }
.turnbadge i { width: .9rem; height: .9rem; border-radius: 50%; border: 1px solid #555; display: inline-block; }
.turnbadge.white i { background: #fff; } .turnbadge.black i { background: #222; }
.moves { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; color: var(--ink); overflow-wrap: anywhere; }
.moves b { color: var(--accent); }

.panel { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem 1.4rem; min-height: 60vh; display: flex; flex-direction: column; }
.panel .kicker { font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.panel h2 { margin: .2rem 0 .8rem; font-size: 1.45rem; line-height: 1.25; }
.panel .body { flex: 1; }
.panel .body p { margin: .6rem 0; }
.panel .body ul, .panel .body ol { padding-left: 1.3rem; }
.panel blockquote { margin: .8rem 0; padding: .4rem 1rem; border-left: 3px solid var(--accent); color: var(--muted); font-style: italic; }
.panel .nav { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin-top: 1.2rem; padding-top: .9rem; border-top: 1px solid var(--line); }
.progress { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; margin: 0 0 1rem; }
.progress a { width: 12px; height: 12px; display: block; border: 1px solid transparent; }
/* exercises: squares – grey until solved */
.progress a.ex { border-radius: 3px; background: var(--line); }
.progress a.ex.done { background: var(--ok); }
.progress a.ex.cur { border-color: var(--accent); background: var(--accent); }
/* ideas: a small star – outlined until read */
.progress a.idea { width: auto; min-width: 12px; height: 12px; font-size: 13px; line-height: 12px; text-align: center; color: var(--line); -webkit-text-stroke: .6px var(--muted); }
.progress a.idea.done { color: var(--muted); -webkit-text-stroke: 0; }
.progress a.idea.cur { color: var(--accent); -webkit-text-stroke: 0; transform: scale(1.25); }
.progress .legend { margin-left: auto; font-size: .72rem; color: var(--muted); display: inline-flex; align-items: center; gap: .25rem; }
.progress .legend i { font-style: normal; display: inline-block; }
.progress .legend i.ex { width: 10px; height: 10px; border-radius: 3px; background: var(--ok); margin-left: .5rem; }
.progress .legend i.idea { color: var(--muted); font-size: 12px; }

.msg { border-radius: 8px; padding: .7rem .9rem; margin: .6rem 0; }
.msg.ok { background: var(--ok-soft); border-left: 4px solid var(--ok); }
.msg.bad { background: var(--bad-soft); border-left: 4px solid var(--bad); }
.msg.hint { background: var(--accent-soft); border-left: 4px solid var(--accent); }
.msg.note { background: #eef1f5; border-left: 4px solid #6b7b8c; }
.msg p:first-child { margin-top: 0; } .msg p:last-child { margin-bottom: 0; }
.msg.new { animation: msgin .45s cubic-bezier(.2,.8,.2,1); }
@keyframes msgin { from { opacity: 0; transform: translateY(-10px) scale(.98); } 60% { opacity: 1; } to { opacity: 1; transform: none; } }
.feed .msg:first-child { box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.feed .msg:not(:first-child) { opacity: .78; }
.toolbar .score { margin-left: auto; align-self: center; }
.boardtools { display: block; margin-top: .4rem; font-size: .82rem; color: var(--muted); cursor: pointer; user-select: none; }
.boardtools input { vertical-align: -1px; margin-right: .3rem; }
.zone, .sqhl { position: absolute; inset: 0; pointer-events: none; z-index: 3; }
.sqhl i { position: absolute; width: 12.5%; height: 12.5%; box-shadow: inset 0 0 0 4px var(--gold), 0 0 0 2px rgba(201,143,27,.5); border-radius: 4px; animation: sqpulse .9s ease-in-out infinite alternate; }
@keyframes sqpulse { from { box-shadow: inset 0 0 0 3px var(--gold); } to { box-shadow: inset 0 0 0 6px var(--gold); } }
.sq { border-bottom: 1px dotted var(--gold); cursor: default; }
.sq:hover { background: #fbefcf; }
.var .sq { border-bottom: none; cursor: pointer; border-radius: 3px; }   /* moves inside a variation: hover plays the line up to that move */
.var .sq:hover { background: #f3dfa8; }
.zone .cell { position: absolute; width: 12.5%; height: 12.5%; mix-blend-mode: multiply; transition: opacity .3s; }
.zone .cell.red { background: #c0392b; }      /* attacked – the king cannot go there */
.zone .cell.green { background: #2e9e5b; }    /* free flight square (empty, or an enemy piece it can take) */
.board.king-hover cg-board { cursor: help; }
.zone .cell.undefended { box-shadow: inset 0 0 0 3px rgba(160, 20, 20, .55); }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin: .8rem 0; }
.score { font-size: .85rem; color: var(--muted); }
.branches { margin-top: 1rem; }
.branches h4 { margin: .8rem 0 .4rem; font-size: 1rem; }
.branches button { display: block; width: 100%; text-align: left; margin-bottom: .4rem; }
.branches button.done { border-color: var(--ok); }
.options button { display: block; width: 100%; text-align: left; margin-bottom: .5rem; padding: .7rem .9rem; }
.options button.right { background: var(--ok-soft); border-color: var(--ok); }
.options button.wrong { background: var(--bad-soft); border-color: var(--bad); }
.spotprompt { font-size: 1.05rem; }
.eval { font-family: ui-monospace, Menlo, monospace; font-size: .85rem; }
.var { text-decoration: underline dotted var(--accent); text-underline-offset: 3px; cursor: pointer; border-radius: 3px; padding: 0 2px; }
.var:hover { background: var(--accent-soft); }
.board.previewing { outline: 3px solid var(--accent); outline-offset: 3px; }
.board.previewing::after { content: "previewing line – move the mouse away to return"; position: absolute; left: 0; right: 0; top: -1.35rem; text-align: center; font-size: .75rem; color: var(--accent); }
.board { position: relative; }
.small { font-size: .85rem; color: var(--muted); }
.playout { margin-top: 1rem; padding-top: .8rem; border-top: 1px dashed var(--line); }
/* positions from the learner's own games */
.mine { margin-top: .6rem; }
.progress .mine, .legend .mine { color: var(--accent); }
.minelist { list-style: none; padding: 0; margin: .4rem 0; display: flex; flex-direction: column; gap: .4rem; }
.minelist li { display: grid; grid-template-columns: auto 1fr auto auto; gap: .7rem; align-items: center; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }
.minelist .date { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }
.minelist .stars { min-width: 3em; text-align: right; }
.minelist li.trivial { opacity: .7; }
.mine-more { margin-top: .5rem; }
.mine-home { display: block; margin-top: 1.4rem; }
.minegroup { margin: 1.4rem 0; }
.minegroup h2 { font-size: 1.2rem; margin: 0 0 .5rem; }
.minegroup h2 a { color: inherit; }
.mine-home p { margin: .4rem 0 0; }
.gamelink { margin: -.4rem 0 .6rem; }
/* player plates above / below the board */
.plate { display: flex; align-items: center; gap: .4rem; font-size: .92rem; padding: .2rem .1rem; min-height: 1.5rem; }
.plate:empty { display: none; }
.plate .turnbadge i { width: .8rem; height: .8rem; }
.plate .small { color: var(--muted); }
.you { background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 0 .5em; font-size: .72rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.warn { color: var(--bad); }
.done-banner { text-align: center; padding: 2rem 1rem; }
.done-banner h2 { font-size: 1.8rem; }
kbd { font-family: ui-monospace, Menlo, monospace; background: var(--line); padding: 0 .35em; border-radius: 4px; font-size: .85em; }
.spinner { display: inline-block; width: .9em; height: .9em; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- phones (iPhone portrait and the like) */
.cards { grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }
.board cg-board, .board .cg-wrap { touch-action: none; }      /* drag pieces without scrolling the page */
.boardtools .lbl-short { display: none; }
@media (max-width: 860px) {
  .boardwrap { position: static; }                              /* one column: the board must scroll away with the page */
  .panel { min-height: 0; }
}
@media (max-width: 600px) {
  :root { --header-h: 2.6rem; }
  header.top { padding: .3rem .8rem; gap: .6rem; }
  .brand { font-size: 1.15rem; width: 1.2em; color: transparent; white-space: nowrap; overflow: hidden; position: relative; }   /* just the crown */
  .brand::before { content: "♔"; color: var(--ink); position: absolute; left: 0; top: 0; }
  header nav { display: flex; gap: 1rem; margin-left: auto; }
  header nav a { margin-left: 0; font-size: .95rem; }
  main { padding: .8rem .9rem calc(1rem + env(safe-area-inset-bottom)); }
  .hero { margin: .2rem 0 1rem; }
  .hero h1 { font-size: 1.5rem; }
  .cards { gap: .7rem; }
  .card { padding: .9rem 1rem; }
  .upcoming ol { columns: 1; }
  .review-box { padding: .8rem .9rem; }
  button { padding: .55rem .9rem; }                             /* finger-sized */
  .done-banner { padding: 1.2rem .5rem; }
  .done-banner h2 { font-size: 1.4rem; }

  /* lesson screen: the board on top, the text fills the rest of the screen and scrolls on its own */
  main:has(> .lesson) { padding: 0; }
  .lesson { display: flex; flex-direction: column; align-items: stretch; gap: 0; height: calc(100dvh - var(--header-h)); overflow: hidden; }
  .boardwrap { flex: none; padding: .15rem .6rem 0; }
  .board { width: min(100%, 44dvh); margin: 0 auto; }
  .plate { font-size: .8rem; min-height: 1.2rem; padding: 0 .1rem; width: min(100%, 44dvh); margin: 0 auto; }
  .underboard { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0 .7rem; width: 100%; margin: 0; padding: 0 .1rem; font-size: .76rem; line-height: 1.35; }
  .underboard .plate { width: auto; margin: 0; }
  .board-caption { margin: 0; min-height: 0; font-size: .78rem; display: contents; }
  .board-caption .moves, .yourmove { display: none; }           /* the moves are in the text panel anyway */
  .boardtools { margin: 0; font-size: .74rem; }
  .boardtools .lbl, .boardtools .small { display: none; }
  .boardtools .lbl-short { display: inline; }
  .panel { flex: 1 1 0; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; border-radius: 12px 12px 0 0; border-bottom: 0; padding: .45rem .9rem 0; margin-top: .2rem; }
  .panel h2 { font-size: 1.05rem; margin: 0 0 .4rem; }
  .panel .kicker { font-size: .66rem; }
  .panel .body p { margin: .45rem 0; }
  .progress { gap: 2px; margin: 0 0 .35rem; }
  .progress a { width: 8px; height: 8px; border-radius: 2px; }
  .progress a.idea { min-width: 8px; height: 8px; font-size: 9px; line-height: 8px; }
  .progress .legend { display: none; }
  .toolbar { margin: .5rem 0; gap: .4rem; }
  .toolbar button { flex: 1 1 auto; padding: .45rem .6rem; }
  .toolbar .score { width: 100%; text-align: right; font-size: .78rem; }
  .msg { padding: .5rem .7rem; margin: .45rem 0; }
  .panel .nav { position: sticky; bottom: 0; margin-top: auto; background: var(--paper); padding: .4rem 0 calc(.4rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); gap: .4rem; }
  .panel .nav > span { flex: 1; text-align: center; font-size: .68rem; line-height: 1.2; }
  .panel .nav button { padding: .4rem .7rem; white-space: nowrap; }
  .board.previewing::after { content: "previewing – tap elsewhere to return"; }
  .minelist li { grid-template-columns: 1fr auto; gap: .3rem .6rem; }
  .minelist .date { grid-column: 1 / -1; font-size: .8rem; }
  .minelist li a { grid-column: 1 / -1; }
  .minelist li a button { width: 100%; }
  .minelist .stars { min-width: 0; }
}
/* phone held sideways: board on the left, text on the right */
@media (max-width: 900px) and (max-height: 500px) and (orientation: landscape) {
  :root { --header-h: 2.6rem; }
  header.top { padding: .3rem .8rem; }
  main:has(> .lesson) { padding: 0; }
  .lesson { display: flex; flex-direction: row; align-items: stretch; gap: 0; height: calc(100dvh - var(--header-h)); overflow: hidden; }
  .boardwrap { flex: none; width: calc(100dvh - var(--header-h) - 3.2rem); padding: .2rem .5rem; }
  .board { width: 100%; }
  .plate { font-size: .75rem; min-height: 1.1rem; padding: 0; }
  .board-caption .moves { display: none; }
  .boardtools { display: none; }
  .panel { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: .5rem .8rem 0; border-radius: 10px 0 0 0; }
  .progress .legend { display: none; }
  .panel .nav { position: sticky; bottom: 0; margin-top: auto; background: var(--paper); padding: .4rem 0; border-top: 1px solid var(--line); }
}
@media (hover: none) {
  button:hover { border-color: var(--line); }                  /* no sticky hover states on touch screens */
  button.primary:hover { filter: none; }
  .board.previewing::after { content: "previewing line – tap elsewhere to return"; }
}
