/* Piles O' Tiles – study app styles. Plain CSS, no framework. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #d9dde3;
  --text: #1c2430;
  --muted: #667085;
  --accent: #2f5fd0;
  --accent-soft: #e5ecfb;
  --ok: #1d7a4a;
  --ok-soft: #dff5e8;
  --warn: #9a6200;
  --warn-soft: #fff3d6;
  --bad: #b3261e;
  --bad-soft: #fde8e6;
  --tile: #fff8e6;
  --tile-border: #d9b25c;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: 0.92em; background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
pre { margin: 0; }
h3, h4 { margin: 0 0 10px; font-size: 1.02rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
h3 .muted, h4 .muted { font-weight: 400; font-size: 0.85rem; }
.right { margin-left: auto; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.ok { color: var(--ok); }
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- header */
.topbar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; flex-direction: column; }
.brand-title { font-weight: 700; font-size: 1.15rem; letter-spacing: 0.2px; }
.brand-sub { color: var(--muted); font-size: 0.8rem; }
.tabs { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.tabs a {
  padding: 7px 14px; border-radius: 999px; color: var(--text); font-weight: 500;
}
.tabs a:hover { background: var(--surface-2); text-decoration: none; }
.tabs a.active { background: var(--accent); color: white; }

main { padding: 18px 20px 60px; max-width: 1500px; margin: 0 auto; }

/* ---------------------------------------------------------------- generic */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 14px;
}
button, .button {
  font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 6px 12px; border-radius: 8px; line-height: 1.2;
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover:not(:disabled), .button:hover { background: var(--surface-2); text-decoration: none; }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: white; border-color: var(--accent); }
button.primary:hover:not(:disabled) { background: #2549a8; }
button.big { padding: 12px 18px; font-size: 1.05rem; width: 100%; justify-content: center; }
button.subtle { padding: 3px 8px; font-size: 0.85rem; border-color: transparent; background: transparent; color: var(--accent); }
button.subtle:hover:not(:disabled) { background: var(--accent-soft); }
button.danger { color: var(--bad); }
button.danger:hover:not(:disabled) { background: var(--bad-soft); }
button.active { border-color: var(--accent); background: var(--accent-soft); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 8px;
}
input[type="number"] { width: 5.5em; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { width: 100%; font-family: var(--mono); font-size: 0.85rem; resize: vertical; }
label { display: inline-flex; align-items: center; gap: 6px; }
details { margin-top: 10px; }
summary { cursor: pointer; font-weight: 500; }
.stack { display: flex; flex-direction: column; gap: 6px; }
.stack button { justify-content: flex-start; text-align: left; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.row input:not([type="file"]) { flex: 1; min-width: 120px; }
.form-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.form-grid label { justify-content: space-between; }
.form-grid input { width: 7em; }
.form-grid button { grid-column: 1 / -1; }
.row-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.hint { background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 6px 10px; margin: 8px 0; font-size: 0.9rem; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: white; padding: 10px 16px; border-radius: 999px; z-index: 100;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25); font-size: 0.9rem;
}
.code-link {
  font-family: var(--mono); font-size: 0.78rem; background: var(--accent-soft); color: var(--accent);
  padding: 1px 6px; border-radius: 999px; white-space: nowrap;
}
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); font-size: 0.82rem; overflow: hidden;
}
.chip-k { font-family: var(--mono); color: var(--muted); padding: 2px 8px; background: var(--surface-2); }
.chip-v { padding: 2px 8px; font-weight: 600; }
.chips-row { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }

/* tile chips */
.tile-chip {
  display: inline-flex; align-items: stretch; border: 1px solid var(--tile-border); background: var(--tile);
  border-radius: 5px; font-family: var(--mono); font-size: 0.8rem; line-height: 1.2; overflow: hidden;
  margin: 1px;
}
.tile-sym { padding: 1px 5px; font-weight: 700; }
.tile-pts { padding: 1px 5px; background: rgba(217, 178, 92, 0.25); color: #6b4d00; }
.tile-chip.top { box-shadow: 0 0 0 2px var(--accent-soft); border-color: var(--accent); }
.tile-chip.big { font-size: 1.3rem; }
.tile-chip.big .tile-sym { padding: 4px 10px; }
.tile-chip.big .tile-pts { padding: 4px 8px; font-size: 0.9rem; display: flex; align-items: center; }

/* banners */
.banner { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 14px; border: 1px solid; }
.banner code { display: block; margin: 6px 0; background: rgba(255,255,255,0.6); padding: 6px 8px; white-space: pre-wrap; }
.banner.crash { background: var(--bad-soft); border-color: #f0b8b3; color: #7a1a14; }
.banner.over { background: var(--ok-soft); border-color: #b5e4c8; color: #145236; }
.banner.ok { background: var(--ok-soft); border-color: #b5e4c8; color: #145236; }
.warnings { margin: 0; padding-left: 18px; }
.warn { padding: 4px 0; font-size: 0.9rem; }
.warn.error { color: var(--bad); }
.warn.warn { color: var(--warn); }
.warn.info { color: var(--muted); }
.warn.error.banner, div.warn.error { background: var(--bad-soft); padding: 8px 10px; border-radius: 8px; margin-top: 8px; }

/* ---------------------------------------------------------------- board */
.board {
  display: grid; gap: 6px; align-items: stretch;
  margin: 8px 0;
}
.axis { display: flex; align-items: center; justify-content: center; color: var(--muted); font-family: var(--mono); font-size: 0.85rem; }
.axis.y { padding-right: 4px; }
.pile {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 74px; padding: 8px 6px; border-radius: 10px; border: 2px solid var(--border);
  background: linear-gradient(180deg, #ffffff, #f6f7f9); box-shadow: var(--shadow);
  cursor: pointer; transition: transform 0.08s ease, border-color 0.1s ease; gap: 2px;
}
.pile:hover { transform: translateY(-1px); border-color: #b8c0cc; background: #fff; }
.pile.empty { background: repeating-linear-gradient(45deg, #f2f3f5, #f2f3f5 6px, #e9ebee 6px, #e9ebee 12px); color: var(--muted); box-shadow: none; }
.pile.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pile.chosen-1::after, .pile.chosen-2::after {
  content: "1"; position: absolute; top: -8px; right: -8px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: white; font-size: 0.72rem; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.pile.chosen-2::after { content: "2"; }
.pile.matched { border-color: var(--ok); background: var(--ok-soft); }
.pile.mismatched { border-color: var(--warn); background: var(--warn-soft); }
.pile.overfull { border-color: var(--bad); }
.pile-coord { position: absolute; top: 4px; left: 6px; font-family: var(--mono); font-size: 0.7rem; color: var(--muted); }
.pile-index { position: absolute; top: 4px; right: 6px; font-family: var(--mono); font-size: 0.7rem; color: var(--accent); }
.pile-count { font-size: 1.7rem; font-weight: 700; line-height: 1; }
.pile.empty .pile-count { color: var(--muted); }
.pile-stack { display: flex; flex-wrap: wrap; justify-content: center; gap: 1px; margin-top: 4px; }
.pile-meta { font-size: 0.68rem; color: var(--muted); font-family: var(--mono); }
.pile-reveal { margin: 2px 0; }
.board.editor .pile { min-height: 96px; }
.board.readonly .pile { cursor: default; }
.board.readonly .pile:hover { transform: none; }
.unreachable { margin: 10px 0; padding: 10px; background: var(--warn-soft); border-radius: 8px; font-size: 0.9rem; }
.pile-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.mini-pile { font-family: var(--mono); font-size: 0.8rem; background: var(--surface); padding: 3px 8px; border-radius: 6px; border: 1px solid var(--border); }
.pile-row .pile { min-width: 110px; flex: 0 0 auto; }

/* ---------------------------------------------------------------- play */
.play-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); gap: 16px; align-items: start; }
.statusbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.statusbar .actions { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; }
.board-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.board-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.board-tools { display: flex; gap: 14px; font-size: 0.9rem; }
.toggle { cursor: pointer; }
.coord-details { margin-top: 10px; }
.coord-form { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.coord-form fieldset { border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px 8px; display: flex; gap: 10px; }
.coord-form legend { font-size: 0.8rem; color: var(--muted); }
.coord-form input { width: 3.5em; font-family: var(--mono); }
.last-turn.ok { border-color: #b5e4c8; }
.console-out {
  font-family: var(--mono); font-size: 0.82rem; line-height: 1.4; background: #1e2430; color: #e6e9ef;
  padding: 10px 12px; border-radius: 8px; white-space: pre-wrap; max-height: 320px; overflow: auto;
}
.console-out.inline { max-height: 160px; margin-top: 8px; }
.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.players li { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 10px; align-items: center; padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); }
.players li.current { border-color: var(--accent); background: var(--accent-soft); }
.p-idx { font-family: var(--mono); color: var(--muted); font-size: 0.8rem; }
.p-name { font-weight: 600; }
.p-score { font-weight: 700; font-family: var(--mono); font-size: 1.1rem; }
.p-bar { grid-column: 2 / 4; height: 5px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.p-bar span { display: block; height: 100%; background: var(--accent); }
.p-turn { grid-column: 1 / 4; font-size: 0.75rem; color: var(--accent); text-transform: uppercase; letter-spacing: 0.5px; }
.trace { margin: 0; padding-left: 20px; font-size: 0.86rem; display: flex; flex-direction: column; gap: 4px; }
.trace li.depth-1 { margin-left: 16px; color: var(--muted); font-size: 0.8rem; list-style: circle; }
.trace-text { font-family: var(--mono); white-space: pre-wrap; }
.trace-note { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }

/* ---------------------------------------------------------------- setup */
.setup-layout { display: grid; grid-template-columns: 330px minmax(0, 1fr); gap: 16px; align-items: start; }
.setup-side { position: sticky; top: 70px; }
.edit-table { width: 100%; border-collapse: collapse; }
.edit-table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 0.8rem; padding: 2px 6px; }
.edit-table td { padding: 3px 6px; }
.edit-table input:not([type="number"]) { width: 100%; }
.tile-rows { display: flex; flex-direction: column; gap: 4px; }
.tile-row { display: inline-flex; gap: 4px; align-items: center; }
.tile-row .sym { width: 3em; text-align: center; font-family: var(--mono); font-weight: 700; text-transform: uppercase; }
.tile-row .pts { width: 4.5em; }
.pile-editor { margin-top: 12px; padding: 12px; background: var(--surface-2); border-radius: 8px; }
.file-list { list-style: none; margin: 8px 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.file-list li { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.file-name { font-family: var(--mono); font-size: 0.85rem; flex: 1; }
.file-text { font-family: var(--mono); font-size: 0.82rem; background: var(--surface-2); padding: 10px; border-radius: 8px; max-height: 360px; overflow: auto; white-space: pre; }

/* ---------------------------------------------------------------- console */
.console-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
.terminal-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.terminal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.terminal { background: #0c0c0c; color: #cccccc; border-radius: 8px; padding: 10px 12px; font-family: var(--mono); font-size: 0.88rem; line-height: 1.35; cursor: text; }
.term-out { white-space: pre-wrap; word-break: break-word; max-height: 60vh; min-height: 200px; overflow: auto; }
.term-form { display: flex; align-items: center; gap: 8px; border-top: 1px solid #2a2a2a; margin-top: 6px; padding-top: 6px; }
.term-caret { color: #6fcf6f; }
.term-in { flex: 1; background: transparent; border: none; color: #fff; font: inherit; padding: 4px 0; }
.term-in:focus { outline: none; }
.term-in:disabled { opacity: 0.4; }
.term-error { color: #ff7b72; }
.cheat td { padding: 2px 8px 2px 0; font-size: 0.88rem; vertical-align: top; }
.live-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-family: var(--mono); font-size: 0.82rem; margin-bottom: 8px; }
.live-grid .chip-k { border-radius: 4px; padding: 0 5px; margin-right: 4px; }
.mini-board { display: inline-flex; flex-direction: column; gap: 2px; margin: 6px 0; }
.mini-row { display: flex; gap: 2px; }
.mini-cell { width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; background: var(--tile); border: 1px solid var(--tile-border); border-radius: 4px; font-family: var(--mono); font-weight: 700; font-size: 0.8rem; }
.mini-cell.empty { background: var(--surface-2); border-color: var(--border); color: var(--muted); }

/* ---------------------------------------------------------------- code */
.code-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 16px; align-items: start; }
.outline { position: sticky; top: 70px; }
.outline-list { list-style: none; margin: 0; padding: 0; font-size: 0.88rem; }
.outline-list ul { list-style: none; margin: 2px 0 8px; padding-left: 14px; }
.outline-class > a { font-weight: 600; font-family: var(--mono); }
.outline-list a.active { background: var(--accent-soft); padding: 0 6px; border-radius: 4px; }
.code-card { padding: 0; overflow: hidden; }
.code { font-family: var(--mono); font-size: 0.84rem; line-height: 1.45; overflow-x: auto; padding: 8px 0; }
.line { display: flex; white-space: pre; }
.line .ln { width: 48px; flex: 0 0 48px; text-align: right; padding-right: 10px; color: #a0a8b4; user-select: none; cursor: pointer; }
.line .ln:hover { color: var(--accent); }
.line .src { flex: 1; padding-right: 16px; }
.line.in-method { background: #f6f8fc; }
.line.hl { background: #fff3c4; }
.line.hl .ln { color: var(--warn); font-weight: 700; }
.tok-keyword { color: #0000ff; }
.tok-type { color: #267f99; }
.tok-string { color: #a31515; }
.tok-comment { color: #008000; }
.tok-number { color: #098658; }
.tok-method { color: #795e26; }
.code-snippet { font-family: var(--mono); font-size: 0.85rem; background: var(--surface-2); padding: 6px 10px; border-radius: 6px; margin: 8px 0; white-space: pre-wrap; }
.related ul { margin: 4px 0 0; padding-left: 18px; font-size: 0.88rem; }

/* ---------------------------------------------------------------- file */
.file-layout { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; align-items: start; }
.file-side { position: sticky; top: 70px; }
.format-list { padding-left: 18px; font-size: 0.88rem; margin: 0; }
.format-list li { margin-bottom: 4px; }
.file-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.file-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 8px; border-bottom: 1px solid var(--border); }
.file-table td { padding: 5px 8px; border-bottom: 1px solid var(--surface-2); vertical-align: top; }
.file-table td.ln { color: var(--muted); font-family: var(--mono); width: 2.5em; }
.file-table code { white-space: pre; }
.file-line.hover td { background: var(--accent-soft); }
.file-line.boardSize td:first-child, .file-line.playerCount td:first-child { border-left: 3px solid var(--accent); }
.file-line.pile td:first-child { border-left: 3px solid var(--tile-border); }
.file-line.player td:first-child { border-left: 3px solid var(--ok); }
.file-line.discard td:first-child { border-left: 3px solid #888; }
.file-line.maxScore td:first-child, .file-line.whoseTurn td:first-child, .file-line.turnsSinceMatch td:first-child { border-left: 3px solid #a06cd5; }
.file-line.err td { background: var(--bad-soft); }
.file-line.unread td { opacity: 0.6; }
.note-summary { font-family: var(--mono); font-size: 0.82rem; }

/* ---------------------------------------------------------------- notes */
.notes-layout { max-width: 1000px; margin: 0 auto; }
.quirks, .practice { padding-left: 22px; margin: 0; }
.quirks li, .practice li { margin-bottom: 12px; }
.quirks li div, .practice li div { color: #3a4452; font-size: 0.92rem; margin-top: 2px; }
.class-diagram {
  display: grid;
  grid-template-columns: max-content max-content minmax(260px, 1fr) max-content minmax(220px, 1fr);
  align-items: center; gap: 0 10px; font-size: 0.85rem;
}
.cd-box { border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); overflow: hidden; }
.cd-tilescs { align-self: center; }
.cd-title { font-weight: 700; padding: 6px 10px; background: var(--accent-soft); font-family: var(--mono); }
.cd-body { padding: 6px 10px; font-family: var(--mono); font-size: 0.78rem; line-height: 1.5; }
.cd-body hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.cd-arrow { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 0.78rem; white-space: nowrap; padding: 0 4px; }
.cd-arrow::after { content: "⟶"; font-size: 1.4rem; line-height: 1; color: var(--accent); }
.cd-stack { display: flex; flex-direction: column; gap: 8px; }
.cd-stack .cd-box { width: 100%; }
@media (max-width: 900px) {
  .class-diagram { grid-template-columns: 1fr; gap: 8px; }
  .cd-arrow { flex-direction: row; justify-content: center; padding: 4px 0; }
  .cd-arrow::after { content: "⟶"; transform: rotate(90deg); display: inline-block; }
}

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1000px) {
  .play-layout, .setup-layout, .console-layout, .code-layout, .file-layout { grid-template-columns: 1fr; }
  .setup-side, .outline, .file-side { position: static; }
  main { padding: 12px; }
}
