*, *::before, *::after { box-sizing: border-box; }

:root {
  --paper: #f4efe4;
  --paper-2: #ebe3d2;
  --card: #fbf8f1;
  --ink: #1c1a15;
  --ink-2: #625b4d;
  --ink-3: #958d7c;
  --line: rgba(28, 26, 21, 0.11);
  --green: #215c3f;
  --green-soft: #dbe8d6;
  --red: #b4432e;
  --gold: #c99a2e;

  /* Button-System (harte Kante) */
  --btn: var(--green);
  --btn-fg: #f6f2e8;
  --btn-2: #fffcf5;
  --btn-2-fg: var(--ink);
  --btn-2-edge: #d5cab2;

  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
  --shadow: 0 1px 0 rgba(255, 255, 255, .7) inset, 0 18px 40px -18px rgba(40, 35, 20, .45), 0 2px 6px rgba(40, 35, 20, .08);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink); }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.eyebrow { font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-3); }

/* ---------- Buttons (moderndesign) ---------- */
.btn {
  appearance: none; border: 0; cursor: pointer;
  font: 800 1.1rem/1 var(--sans);
  padding: 17px 26px; border-radius: 18px; min-height: 52px;
  background: var(--btn); color: var(--btn-fg);
  box-shadow: 0 6px 0 color-mix(in srgb, var(--btn) 55%, #000);
  transition: transform .1s, box-shadow .1s, filter .15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 color-mix(in srgb, var(--btn) 55%, #000); }
.btn.primary { width: 100%; }
.btn.ghost { background: var(--btn-2); color: var(--btn-2-fg); box-shadow: 0 6px 0 var(--btn-2-edge); }
.btn.ghost:active { box-shadow: 0 2px 0 var(--btn-2-edge); }

.key {
  appearance: none; border: 0; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 46px; padding: 0 16px; border-radius: 14px;
  font: 700 .95rem/1 var(--sans);
  background: var(--btn-2); color: var(--btn-2-fg);
  box-shadow: 0 4px 0 var(--btn-2-edge);
  transition: transform .1s, box-shadow .1s, background .15s, color .15s;
}
.key:hover { background: #fff; }
.key:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--btn-2-edge); }
.key.on { --btn-2: var(--green); --btn-2-fg: var(--btn-fg); --btn-2-edge: #123826; }
.key.on:hover { background: var(--btn-2); filter: brightness(1.08); }
.key.warn svg { color: var(--red); }
.key.armed { --btn-2: var(--red); --btn-2-fg: #fff6ef; --btn-2-edge: #6e2416; }
.key.armed svg { color: currentColor; }
.key.armed:hover { background: var(--btn-2); }
.key.round { width: 46px; padding: 0; justify-content: center; border-radius: 50%; }

.btn:focus-visible, .key:focus-visible, .toggle button:focus-visible, .opp-row:focus-visible, .pz:focus-visible, .link:focus-visible {
  outline: 3px solid var(--green); outline-offset: 3px;
}

/* Pill-Toggle mit gleitendem Daumen */
.toggle { --n: 2; --i: 0; position: relative; display: grid; grid-template-columns: repeat(var(--n), 1fr); background: var(--paper-2); border-radius: 999px; padding: 5px; }
.toggle .thumb {
  position: absolute; top: 5px; bottom: 5px; left: 5px; width: calc((100% - 10px) / var(--n));
  background: var(--btn); border-radius: 999px; box-shadow: 0 3px 0 color-mix(in srgb, var(--btn) 55%, #000);
  transform: translateX(calc(100% * var(--i)));
  transition: transform .35s cubic-bezier(.5, 1.6, .4, 1);
}
.toggle[data-i="1"] { --i: 1; }
.toggle[data-i="2"] { --i: 2; }
.toggle button {
  position: relative; z-index: 1; appearance: none; border: 0; background: none; cursor: pointer;
  font: 700 1rem/1 var(--sans); padding: 12px 0 14px; color: var(--ink-2); transition: color .25s;
}
.toggle button[aria-pressed="true"] { color: var(--btn-fg); }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
.sheet { background: var(--card); border-radius: 20px; box-shadow: var(--shadow); }

.player { position: absolute; top: 16px; left: 16px; width: 292px; padding: 16px; }
.player-row { display: flex; gap: 12px; align-items: center; }
.avatar { width: 48px; height: 48px; flex: none; }
.mono {
  width: 100%; height: 100%; border-radius: 14px; display: grid; place-items: center;
  background: var(--c, var(--green)); color: #fbf6ea;
  font: 600 19px/1 var(--serif); letter-spacing: .02em;
  box-shadow: 0 3px 0 color-mix(in srgb, var(--c, var(--green)) 55%, #000);
}
.player-name { font: 600 20px/1.15 var(--serif); letter-spacing: -.01em; }
.player-sub { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; }
.turn {
  display: flex; align-items: center; gap: 9px; margin-top: 14px; padding: 10px 12px;
  background: var(--paper); border-radius: 12px; font-size: 14px; font-weight: 600;
}
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); flex: none; }
.dot.thinking { background: var(--gold); box-shadow: 0 0 0 4px #f3e5bf; animation: breathe 1.1s ease-in-out infinite; }
.dot.off { background: var(--ink-3); box-shadow: 0 0 0 4px var(--paper-2); }
@keyframes breathe { 50% { transform: scale(.6); } }
.goal { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.goal-text { font: 500 16px/1.35 var(--serif); margin-top: 6px; }
.progress { display: flex; align-items: center; gap: 10px; margin-top: 12px; font: 600 12px/1 var(--mono); color: var(--ink-2); }
.progress .bar { flex: 1; height: 6px; background: var(--paper-2); border-radius: 99px; overflow: hidden; }
.progress .fill { height: 100%; width: 0; background: var(--green); border-radius: 99px; transition: width .5s cubic-bezier(.3, 1.4, .5, 1); }

.score { position: absolute; top: 16px; right: 16px; width: 248px; padding: 16px 16px 12px; max-height: calc(100vh - 130px); display: flex; flex-direction: column; }
.score-head { display: flex; flex-direction: column; gap: 6px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.status { font-size: 14px; font-weight: 600; line-height: 1.35; }
.movelist {
  overflow-y: auto; max-height: 42vh; scrollbar-width: thin;
  display: grid; grid-template-columns: 34px 1fr 1fr; font: 500 13.5px/1 var(--mono);
}
.movelist:empty::after { content: 'Noch keine Züge'; grid-column: 1 / -1; padding: 14px 0 4px; color: var(--ink-3); font-family: var(--sans); font-size: 13px; }
.movelist > span { padding: 8px 6px; border-bottom: 1px solid var(--line); }
.movelist .n { color: var(--ink-3); padding-left: 0; }
.movelist .m.last { color: var(--green); font-weight: 600; background: var(--green-soft); border-radius: 6px; border-bottom-color: transparent; }
.captured { display: flex; flex-direction: column; gap: 2px; margin-top: 10px; font: 20px/1.1 var(--serif); color: var(--ink-2); }
.captured:empty { display: none; }
.captured .adv { font: 600 12px var(--mono); color: var(--green); margin-left: 6px; vertical-align: middle; }

#evalBar {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%); width: 14px; height: 280px;
  border-radius: 99px; background: #2a2823; overflow: hidden; box-shadow: 0 0 0 4px var(--card), var(--shadow);
}
.player ~ #evalBar { top: 58%; }
#evalBar .fill { position: absolute; bottom: 0; left: 0; right: 0; height: 50%; background: #f7f1e3; transition: height .6s cubic-bezier(.3, 1.2, .5, 1); }
#evalBar span {
  position: absolute; left: 22px; top: 50%; transform: translateY(-50%); padding: 4px 7px; border-radius: 8px;
  background: var(--card); font: 600 11px/1 var(--mono); color: var(--ink); box-shadow: var(--shadow); white-space: nowrap;
}
#evalBar { overflow: visible; }
#evalBar .fill { border-radius: 99px; }

.dock {
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  display: flex; gap: 8px; padding: 10px 10px 14px; background: var(--card); border-radius: 22px; box-shadow: var(--shadow);
}
.toast {
  position: absolute; left: 50%; bottom: 100px; transform: translateX(-50%);
  padding: 10px 16px; border-radius: 999px; background: var(--ink); color: #f4efe4;
  font-size: 13.5px; font-weight: 500; max-width: min(520px, calc(100vw - 32px)); text-align: center;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, .5); transition: background .2s;
}
.toast.warn { background: var(--red); }

/* ---------- Modale ---------- */
.modal {
  position: fixed; inset: 0; z-index: 10; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(28, 24, 14, .32);
  animation: fade .25s ease-out;
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(14px) scale(.98); opacity: 0; } }
.card {
  background: var(--card); border-radius: 26px; padding: 26px; width: min(540px, 100%);
  max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 30px 80px -20px rgba(30, 25, 10, .55);
  animation: rise .35s cubic-bezier(.3, 1.3, .5, 1);
}
.card.small { width: min(400px, 100%); text-align: center; }
.masthead { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
h1 { margin: 4px 0 0; font: 600 38px/1 var(--serif); letter-spacing: -.025em; }
h2 { margin: 6px 0 6px; font: 600 28px/1.1 var(--serif); letter-spacing: -.02em; }
.lede { color: var(--ink-2); font-size: 15px; line-height: 1.55; margin: 0 0 18px; }
.menu-card .tabs { margin-bottom: 22px; }
.tabpane > .eyebrow { margin: 0 0 10px; }

.opps { display: flex; flex-direction: column; gap: 8px; margin-bottom: 22px; }
.opp-row {
  appearance: none; border: 0; cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 14px; padding: 10px 14px 10px 10px; border-radius: 16px;
  background: var(--paper); box-shadow: 0 0 0 2px transparent inset; transition: box-shadow .15s, background .15s;
}
.opp-row:hover { background: var(--paper-2); }
.opp-row[aria-pressed="true"] { background: #fff; box-shadow: 0 0 0 2px var(--green) inset; }
.opp-row .avatar { width: 42px; height: 42px; }
.opp-row .mono { font-size: 16px; border-radius: 12px; }
.opp-row .who { flex: 1; }
.opp-row b { display: block; font: 600 16.5px/1.2 var(--serif); }
.opp-row small { color: var(--ink-2); font-size: 12.5px; }
.pips { display: flex; gap: 4px; }
.pips i { width: 8px; height: 8px; border-radius: 50%; background: rgba(28, 26, 21, .14); }
.pips i.on { background: var(--ink); }
#colorSeg { margin-bottom: 24px; }

.puzzles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.pz {
  appearance: none; border: 0; cursor: pointer; position: relative;
  border-radius: 18px; padding: 14px 8px 12px; min-height: 92px;
  background: var(--btn-2); color: var(--ink); box-shadow: 0 5px 0 var(--btn-2-edge);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center;
  transition: transform .1s, box-shadow .1s;
}
.pz:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--btn-2-edge); }
.pz .n { font: 600 28px/1 var(--serif); }
.pz .l { font-size: 11.5px; font-weight: 600; color: var(--ink-2); line-height: 1.2; }
.pz .side { position: absolute; top: 9px; left: 10px; width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid var(--ink); }
.pz .side.b { background: var(--ink); }
.pz.done { --btn-2: var(--green-soft); --btn-2-edge: #a9c3a2; }
.pz.done .n { color: var(--green); }
.pz.done::after {
  content: ''; position: absolute; top: 8px; right: 9px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--green) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 12.5 4 4L18 8'/%3E%3C/svg%3E") center / 10px no-repeat;
}

.switch { display: flex; align-items: center; gap: 12px; margin: 0 0 24px; font-size: 15px; font-weight: 600; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch .track { position: relative; width: 48px; height: 28px; border-radius: 99px; background: var(--paper-2); transition: background .2s; flex: none; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 2px 0 var(--btn-2-edge); transition: transform .3s cubic-bezier(.5, 1.6, .4, 1); }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 3px solid var(--green); outline-offset: 3px; }

.keys { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); }
.keys .wide { flex-basis: 100%; color: var(--ink-3); }
kbd {
  display: inline-block; min-width: 22px; margin-right: 6px; padding: 4px 6px 5px; border-radius: 7px; text-align: center;
  font: 600 11px/1 var(--mono); background: var(--btn-2); color: var(--ink); box-shadow: 0 2px 0 var(--btn-2-edge);
}

.promo-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 18px; }
.promo-row button {
  appearance: none; border: 0; cursor: pointer; aspect-ratio: 1; border-radius: 18px;
  font: 46px/1 var(--serif); background: var(--btn-2); color: var(--ink); box-shadow: 0 5px 0 var(--btn-2-edge);
  transition: transform .1s, box-shadow .1s;
}
.promo-row button:hover { background: #fff; }
.promo-row button:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--btn-2-edge); }

.over-mark {
  width: 76px; height: 76px; margin: 2px auto 10px; border-radius: 24px; display: grid; place-items: center;
  background: var(--green); color: #f6f2e8; font: 46px/1 var(--serif); box-shadow: 0 6px 0 #123826;
}
.over-mark.lose { background: var(--ink); box-shadow: 0 6px 0 #000; }
.over-mark.draw { background: var(--gold); box-shadow: 0 6px 0 #7d5e16; font-size: 34px; }
.row { display: flex; gap: 10px; margin-top: 8px; }
.row .btn { flex: 1; padding-left: 12px; padding-right: 12px; }
.row .btn.ghost { flex: 0 0 auto; }
.link { appearance: none; border: 0; background: none; cursor: pointer; margin-top: 16px; font-weight: 600; font-size: 14px; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line); }
.link:hover { color: var(--ink); }

#loading {
  position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; gap: 18px; align-items: center; justify-content: center;
  background: var(--paper); color: var(--ink-2); font: 500 18px var(--serif); transition: opacity .5s;
}
.loader { display: flex; gap: 8px; }
.loader span { width: 14px; height: 14px; border-radius: 4px; background: var(--ink); animation: hop .9s ease-in-out infinite; }
.loader span:nth-child(2) { background: var(--green); animation-delay: .12s; }
.loader span:nth-child(3) { animation-delay: .24s; }
@keyframes hop { 40% { transform: translateY(-12px); } }

/* Link-Button zum anderen Spiel */
.crosslink {
  --btn: #2a2823;
  display: flex; align-items: center; gap: 14px; margin-top: 20px; padding: 14px 18px; border-radius: 18px;
  text-decoration: none; background: var(--btn); color: #f4efe4; font-weight: 800; font-size: 1.05rem; line-height: 1.2;
  box-shadow: 0 6px 0 color-mix(in srgb, var(--btn) 55%, #000); transition: transform .1s, box-shadow .1s;
}
.crosslink:active { transform: translateY(4px); box-shadow: 0 2px 0 color-mix(in srgb, var(--btn) 55%, #000); }
.crosslink svg { width: 26px; height: 26px; }
.crosslink span { display: flex; flex-direction: column; }
.crosslink small { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .1em; opacity: .7; }
.crosslink:focus-visible { outline: 3px solid var(--green); outline-offset: 3px; }

/* ---------- Kleinere Bildschirme ---------- */
@media (max-width: 1100px) {
  .dock .key span { display: none; }
  .dock .key { width: 46px; padding: 0; justify-content: center; }
}
@media (max-width: 760px) {
  .player { top: 10px; left: 10px; width: auto; right: 10px; padding: 10px 12px; display: flex; align-items: center; gap: 12px; border-radius: 16px; }
  .player-row { flex: 1; min-width: 0; }
  .player-info { min-width: 0; }
  .avatar { width: 38px; height: 38px; }
  .mono { font-size: 15px; border-radius: 11px; }
  .player-name { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .player-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .turn { margin: 0; padding: 8px 10px; font-size: 12.5px; }
  .goal { display: none; }
  .score { top: auto; bottom: 86px; right: 10px; left: 10px; width: auto; max-height: none; padding: 8px 12px; border-radius: 14px; }
  .score-head { flex-direction: row; justify-content: space-between; align-items: center; padding: 0; border: 0; }
  .score-head .eyebrow { display: none; }
  .movelist, .captured { display: none; }
  .toast { bottom: 140px; font-size: 12.5px; }
  .dock { bottom: 10px; gap: 6px; padding: 8px 8px 12px; }
  .dock .key { width: 44px; min-height: 44px; }
  #evalBar { height: 180px; left: 10px; }
  .puzzles { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 20px; border-radius: 22px; }
  h1 { font-size: 30px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
