:root {
  --bg: #161512;
  --panel: #262421;
  --panel2: #302e2b;
  --line: #3d3a36;
  --text: #e8e6e3;
  --muted: #9a958e;
  --primary: #629924;
  --primary-h: #74b32c;
  --accent: #d59020;
  --ok: #7fc241;
  --bad: #e5604d;
  --warn: #e0b33c;
  --info: #5fa8e0;
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
#app { display: contents; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 .25rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
p { margin: .5rem 0; }

.loading { text-align: center; padding: 4rem 1rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; justify-content: center; }
.right { text-align: right; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }

/* Layout */
.top {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: .6rem 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.2rem; cursor: pointer; }
.top nav { display: flex; gap: .25rem; }
.top nav button, .tabs button {
  background: none; border: 0; color: var(--muted); font: inherit; padding: .45rem .8rem;
  border-radius: 6px; cursor: pointer;
}
.top nav button:hover, .tabs button:hover { color: var(--text); background: var(--panel2); }
.top nav button.on, .tabs button.on { color: var(--text); background: var(--panel2); font-weight: 600; }
main { width: 100%; max-width: 1080px; margin: 0 auto; padding: 24px 16px; flex: 1; }
.foot-links { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; margin-top: .4rem; }
.foot { padding: 1rem 16px; text-align: center; color: var(--muted); font-size: .8rem; border-top: 1px solid var(--line); }

.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: .7rem; }

/* Forms */
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; color: var(--muted); }
label.inline { flex-direction: row; align-items: center; gap: .6rem; }
input[type=text], select, textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: .55rem .65rem; font: inherit; width: 100%;
}
label.inline select { width: auto; }
textarea { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; resize: vertical; }
input[type=file] { color: var(--muted); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.btn {
  background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 6px;
  padding: .55rem 1rem; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--muted); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-h); border-color: var(--primary-h); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #1b1300; }
.btn.ghost { background: none; }
.btn.small { padding: .3rem .65rem; font-size: .85rem; }
.link { background: none; border: 0; padding: 0; color: var(--info); font: inherit; cursor: pointer; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--bad); }

.pill { display: inline-block; padding: 0 .5rem; border-radius: 99px; font-size: .75rem; font-weight: 700; margin-right: .4rem; }
.pill.white { background: #e8e6e3; color: #161512; }
.pill.black { background: #000; color: #e8e6e3; border: 1px solid var(--line); }

.progress { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); transition: width .3s; }

.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; color: var(--muted); font-weight: 500; padding: .4rem .5rem; border-bottom: 1px solid var(--line); }
.table td { padding: .45rem .5rem; border-bottom: 1px solid var(--line); }
.table tr:last-child td { border-bottom: 0; }
.table td.me { font-weight: 700; }
.card:has(> .table) { overflow-x: auto; }

.res { display: inline-block; min-width: 2.6rem; text-align: center; border-radius: 4px; padding: 0 .3rem; font-size: .8rem; font-weight: 700; }
.res.w { background: #2f4a14; color: var(--ok); }
.res.l { background: #4d221b; color: var(--bad); }
.res.d { background: var(--panel2); color: var(--muted); }

.msg { border-radius: 6px; padding: .55rem .75rem; font-size: .95rem; background: var(--panel2); border-left: 4px solid var(--line); }
.msg p { margin: .35rem 0 0; color: var(--text); }
.msg.ok { border-color: var(--ok); }
.msg.bad { border-color: var(--bad); }
.msg.info, .msg.teach { border-color: var(--info); }
.msg.ask { border-color: var(--accent); }
.msg.idle { color: var(--muted); }

/* Board */
.board-wrap { width: 100%; }
.board { width: 100%; aspect-ratio: 1 / 1; }
.board cg-board { border-radius: 4px; }

/* Trainer */
.trainer { display: grid; grid-template-columns: minmax(0, 600px) minmax(280px, 1fr); gap: 20px; align-items: start; }
.trainer-side { min-height: 420px; }
.trainer-head { display: flex; justify-content: space-between; align-items: start; gap: .5rem; }
.eyebrow { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.status { display: flex; flex-direction: column; gap: .5rem; min-height: 5.5rem; }
.movelist {
  background: var(--bg); border-radius: 6px; padding: .6rem .7rem; font-size: .95rem; line-height: 1.8;
  max-height: 260px; min-height: 80px; overflow-y: auto; flex: 1;
}
.mv { display: inline-block; margin-right: .45rem; padding: 0 .2rem; border-radius: 3px; font-weight: 600; }
.mv .no { color: var(--muted); font-weight: 400; margin-right: .2rem; }
.mv.last { background: var(--panel2); outline: 1px solid var(--line); }
.cm { display: block; color: var(--muted); font-size: .88rem; line-height: 1.4; margin: .1rem 0 .3rem; }
.trainer-actions { min-height: 2.6rem; }
.finish { text-align: center; padding: 1.5rem 0; }
.finish .row { justify-content: center; margin-top: 1rem; }

/* Heute / Motivation */
.today { flex-direction: row; flex-wrap: wrap; gap: 24px; align-items: stretch; }
.today-main { flex: 2; min-width: 220px; display: flex; flex-direction: column; gap: .45rem; }
.today-stat { flex: 1; min-width: 150px; display: flex; flex-direction: column; gap: .35rem; align-items: flex-start; }
.big { font-size: 1.7rem; font-weight: 700; line-height: 1.2; }
.big .muted { font-size: 1rem; font-weight: 400; }
.week { display: flex; gap: 6px; align-items: flex-end; }
.day { display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: .7rem; color: var(--muted); }
.day .bar { width: 18px; height: 64px; background: var(--bg); border-radius: 4px; display: flex; align-items: flex-end; overflow: hidden; }
.day .bar > div { width: 100%; background: var(--muted); border-radius: 4px; }
.day .bar > div.full { background: var(--primary); }
.drill { flex-direction: row; }

/* Schalter */
label.check { flex-direction: row; align-items: center; gap: .4rem; cursor: pointer; color: var(--muted); font-size: .85rem; }
label.check input { accent-color: var(--primary); width: 16px; height: 16px; }
.toggles { border-top: 1px solid var(--line); padding-top: .6rem; gap: 1rem; }

/* Abgleich: Repertoire pro Farbe */
label.pick { cursor: pointer; color: var(--text); gap: .5rem; padding: 12px 14px; }
label.pick.on { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }

/* Editor */
main.wide { max-width: 1280px; }
.editor { display: grid; grid-template-columns: minmax(0, 620px) minmax(320px, 1fr); gap: 20px; align-items: start; }
.editor-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.editor .nav { margin-top: .6rem; }
.title-input { font-size: 1.1rem !important; font-weight: 700; flex: 1; }
select.auto { width: auto; }
select.grow, .grow { flex: 1; min-width: 0; }
h3.flat { margin: 0; }
.tree {
  background: var(--bg); border-radius: 6px; padding: .6rem .7rem; font-size: .95rem; line-height: 1.9;
  max-height: 300px; min-height: 90px; overflow-y: auto;
}
.tree .mv { cursor: pointer; margin-right: .25rem; }
.tree .mv:hover { background: var(--panel2); }
.tree .mv.cur { background: var(--primary); color: #fff; }
.tree .mv.cur .no { color: #e3f2cf; }
.tree .gl { color: var(--accent); }
.tree .mv.cur .gl { color: #fff; }
.tree .var { color: var(--muted); font-size: .9rem; }
.tree .var .mv { font-weight: 500; color: var(--text); }
.tree .cmi { color: #8fb3d9; font-size: .88rem; margin-right: .4rem; }
.node-tools { display: flex; flex-direction: column; gap: .5rem; border-top: 1px solid var(--line); padding-top: .7rem; }
.node-tools textarea { font-family: inherit; font-size: .9rem; }
.btn.glyph { min-width: 2.2rem; padding: .25rem .4rem; }
.btn.glyph.on { background: var(--accent); border-color: var(--accent); color: #1b1300; }
.btn.danger { color: var(--bad); }
.pvs { display: flex; flex-direction: column; gap: 2px; }
.pv {
  display: flex; gap: .6rem; align-items: baseline; text-align: left; background: none; border: 0; color: var(--text);
  font: inherit; font-size: .88rem; padding: .3rem .4rem; border-radius: 5px; cursor: pointer;
}
.pv:hover { background: var(--panel2); }
.pv span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.ev { min-width: 3.4rem; text-align: center; border-radius: 4px; padding: 0 .3rem; font-size: .82rem; }
.ev.w { background: #e8e6e3; color: #161512; }
.ev.b { background: #000; color: #e8e6e3; }
.explorer tr { cursor: pointer; }
.explorer tr:hover td { background: var(--panel2); }
.explorer td.wide { width: 45%; }
.wdlbar { display: flex; height: 16px; border-radius: 3px; overflow: hidden; font-size: .68rem; line-height: 16px; }
.wdlbar i { font-style: normal; text-align: center; overflow: hidden; }
.wdlbar .w { background: #e8e6e3; color: #161512; }
.wdlbar .d { background: #7d7a75; }
.wdlbar .b { background: #000; color: #e8e6e3; }
.cloud td { padding-top: .25rem; padding-bottom: .25rem; }
.rank2 { color: var(--ok); } .rank1 { color: var(--muted); } .rank0 { color: var(--bad); }
.list.cover { padding: 0; max-height: 260px; }
.list.cover .item { padding: .4rem .5rem; }
.list.cover .item .count { min-width: 3.2rem; font-size: .9rem; }
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .65); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; width: min(900px, 100%); max-height: 100%; overflow: auto; display: flex; flex-direction: column; gap: 12px; }
.viewer { display: grid; grid-template-columns: minmax(0, 480px) minmax(200px, 1fr); gap: 16px; align-items: start; }
.viewer > * { min-width: 0; }
.viewer .tree { max-height: 480px; }
.viewer .nav { margin-top: .6rem; }

.boardrow { display: flex; gap: 6px; align-items: stretch; }
.boardrow .board-wrap { flex: 1; min-width: 0; }
.evalbar { position: relative; width: 20px; flex: none; background: #000; border-radius: 4px; overflow: hidden; }
.evalbar .white { position: absolute; left: 0; right: 0; bottom: 0; background: #e8e6e3; transition: height .4s; }
.evalbar.flip .white { bottom: auto; top: 0; }
.evalbar span { position: absolute; left: 0; right: 0; text-align: center; font-size: .62rem; font-weight: 700; }
.evalbar span.low { bottom: 3px; } .evalbar span.high { top: 3px; }
.evalbar span.w { color: #161512; } .evalbar span.b { color: #e8e6e3; }
.promo { margin-top: .6rem; background: var(--panel2); border-radius: 6px; padding: .5rem .7rem; }
.tree .fold { cursor: pointer; color: var(--accent); margin-right: .15rem; user-select: none; }
label.check.small { font-size: .85rem; }

/* Compare */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; }
.tile b { font-size: 1.6rem; line-height: 1.2; }
.tile span { color: var(--muted); font-size: .82rem; }
.tile.bad b { color: var(--bad); }
.tile.warn b { color: var(--warn); }
.tile.ok b { color: var(--ok); }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--line); padding-bottom: .4rem; }
.compare { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 440px); gap: 16px; align-items: start; }
.list { padding: 6px; gap: 2px; max-height: 720px; overflow-y: auto; }
.item {
  display: flex; align-items: center; gap: .7rem; width: 100%; text-align: left; background: none; border: 0;
  color: var(--text); font: inherit; padding: .55rem .6rem; border-radius: 6px; cursor: pointer;
}
.item:hover { background: var(--panel2); }
.item.on { background: var(--panel2); outline: 1px solid var(--line); }
.item .count { font-weight: 700; min-width: 2.4rem; color: var(--accent); }
.item .grow { flex: 1; min-width: 0; }
.wdl { display: flex; gap: 2px; font-size: .75rem; }
.wdl i { font-style: normal; padding: 0 .35rem; border-radius: 3px; background: var(--bg); }
.wdl .w { color: var(--ok); } .wdl .d { color: var(--muted); } .wdl .l { color: var(--bad); }
.games { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .35rem; font-size: .9rem; }
.games li { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }

@media (max-width: 820px) {
  .trainer, .compare, .editor, .viewer { grid-template-columns: 1fr; }
  .trainer-side { min-height: 0; }
  main { padding: 16px 12px; }
  .top { gap: .4rem 1rem; padding-top: .5rem; padding-bottom: .5rem; }
  .today { gap: 14px; }
  .today-main { flex: 1 1 100%; min-width: 0; }
  .today-stat { flex: 1 1 40%; min-width: 0; }
  .today-stat .small { display: none; }
  .week { flex: 1 1 100%; justify-content: space-between; }
  .card .row > .btn { flex: 1 1 auto; }
  .modal { padding: 6px; }
}
