:root {
  --bg: #f3ece2;
  --bg2: #e9dfd1;
  --card: #fffaf3;
  --text: #2a1a14;
  --muted: #7a6458;
  --line: #dccdbb;
  --accent: #7a2e18;      /* Mahagoni */
  --accent-text: #fff6ea;
  --brass: #b8863b;
  --good: #3d7a4a;
  --shadow: 0 10px 30px rgba(60, 25, 10, .15);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15100d; --bg2: #1f1713; --card: #241a15; --text: #f1e6d8; --muted: #a8968a;
    --line: #3a2c24; --accent: #b4512f; --accent-text: #fff6ea; --brass: #d3a35a; --good: #6fbf80;
    --shadow: 0 10px 30px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15100d; --bg2: #1f1713; --card: #241a15; --text: #f1e6d8; --muted: #a8968a;
  --line: #3a2c24; --accent: #b4512f; --accent-text: #fff6ea; --brass: #d3a35a; --good: #6fbf80;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg) 70%) fixed, var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.wrap { max-width: 640px; margin: 0 auto; padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); }
.top { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 14px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none;
  font-family: Fraunces, Georgia, serif; font-weight: 700; font-size: 1.4rem; letter-spacing: .01em; }
.brand svg { width: 30px; height: 30px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 24px; box-shadow: var(--shadow); }
.card.small { max-width: 340px; width: calc(100% - 32px); text-align: center; padding: 22px 20px; }
.card.small h2 { font-family: Fraunces, Georgia, serif; margin: 0 0 6px; font-size: 1.45rem; }
.card.small p { color: var(--muted); margin: 0 0 14px; }

h1 { font-family: Fraunces, Georgia, serif; font-size: 2rem; margin: 0 0 6px; }
.sub { color: var(--muted); margin: 0 0 20px; }

.row { display: flex; gap: 10px; flex-wrap: wrap; }
input {
  flex: 1 1 180px; min-width: 0; font: inherit; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
}
input:focus { outline: 2px solid var(--brass); outline-offset: 1px; }

.btn {
  font: inherit; font-weight: 600; border-radius: 12px; padding: 12px 18px; cursor: pointer;
  border: 1px solid transparent; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  transition: transform .08s ease, background .2s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--bg2); }
.card.small .btn { width: 100%; margin-top: 4px; }
.card.small .btn.ghost { border: none; color: var(--muted); }

.rules { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 14px; }
.rules summary { cursor: pointer; font-weight: 600; }
.rules ol { padding-left: 20px; color: var(--muted); line-height: 1.55; }
.rules b { color: var(--text); }

.history { margin-top: 22px; border-top: 1px solid var(--line); padding-top: 14px; }
.history h2 { font-size: 1rem; margin: 0 0 10px; }
.history ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.history li { display: flex; justify-content: space-between; gap: 10px; font-size: .92rem; padding: 8px 10px; border-radius: 10px; background: var(--bg); }
.history .res { font-weight: 600; white-space: nowrap; }
.history .win { color: var(--good); }
.history .loss { color: var(--accent); }
.history .when { color: var(--muted); font-size: .8rem; }

/* ---------- Spiel ---------- */
.players { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.player {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--card); min-width: 0; transition: box-shadow .25s, border-color .25s;
}
#p2 { flex-direction: row-reverse; text-align: right; }
.player.turn { border-color: var(--brass); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brass) 40%, transparent); }
.player.offline .pname { opacity: .5; }
.pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.pname small { font-weight: 500; color: var(--muted); }
.hand { font-size: .8rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.vs { color: var(--muted); font-size: .8rem; }
.chip { width: 18px; height: 18px; border-radius: 50%; flex: none; }
.chip.white { background: radial-gradient(circle at 35% 30%, #f6efe1, #e6d8bb 50%, #b29b72); box-shadow: 0 0 0 1px #8c7652; }
.chip.black { background: radial-gradient(circle at 35% 30%, #8f7d70, #4b3d35 50%, #1c1512); box-shadow: 0 0 0 1px #100b09; }

.status { text-align: center; min-height: 1.5em; margin: 14px 0 10px; font-weight: 500; }
.status b { color: var(--accent); }

.board-wrap { position: relative; width: 100%; aspect-ratio: 1; }
#board { width: 100%; height: 100%; display: block; touch-action: manipulation; user-select: none; }
#board .hit { cursor: pointer; }
.overlay {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(20, 8, 4, .35); backdrop-filter: blur(2px); border-radius: 4%;
  animation: fade .25s ease;
}
.linkbox { background: var(--bg); border: 1px dashed var(--line); border-radius: 10px; padding: 10px; margin-bottom: 12px; word-break: break-all; }
.linkbox code { font-size: .85rem; }
.hint { font-size: .85rem; min-height: 1.2em; margin: 8px 0 0 !important; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 16px; }
.actions .btn { padding: 10px 14px; font-size: .92rem; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 500;
  box-shadow: var(--shadow); max-width: calc(100% - 32px); animation: fade .2s ease;
}

/* Stein-Animationen */
.stone { transition: opacity .2s; }
.stone.drop { animation: drop .28s cubic-bezier(.2, .9, .3, 1.2); }
.stone.slide { animation: slide .32s cubic-bezier(.3, .8, .3, 1); }
.stone.sel .body { stroke: var(--brass); stroke-width: 4; }
.stone.lift { transform-box: fill-box; }
.ghost-stone { animation: vanish .45s ease forwards; transform-box: fill-box; transform-origin: center; }
.target { animation: pulse 1.4s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.takeable { animation: wobble 1s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.mill-line { animation: glow 1.2s ease-out; }

@keyframes drop { from { transform: translateY(-26px) scale(1.15); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes slide { from { transform: translate(var(--dx), var(--dy)); } to { transform: none; } }
@keyframes vanish { to { transform: scale(.4); opacity: 0; } }
@keyframes pulse { 0%, 100% { opacity: .55; transform: scale(.85); } 50% { opacity: 1; transform: scale(1.05); } }
@keyframes wobble { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-6deg); } 75% { transform: rotate(6deg); } }
@keyframes glow { from { stroke-width: 22; opacity: .9; } to { stroke-width: 10; opacity: .55; } }
@keyframes fade { from { opacity: 0; } }

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

@media (max-width: 420px) {
  .card { padding: 18px; }
  h1 { font-size: 1.7rem; }
  .player { padding: 6px 8px; gap: 6px; }
  .hand { font-size: .72rem; }
}
