[hidden] { display: none !important; }
:root {
  --pink: #f2b9c0;
  --pink-d: #d97f8d;
  --violet: #c49be3;
  --violet-d: #8d5cc0;
  --ink: #1b1717;
  --paper: #fbfaf6;
  --wood: #c99257;
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--wood);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* ---------- Holztisch ---------- */
.table {
  min-height: 100vh;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='600' height='600'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.004 0.09' numOctaves='4' seed='7'/%3E%3CfeColorMatrix values='0 0 0 0 0.35  0 0 0 0 0.2  0 0 0 0 0.08  0 0 0 -1.4 0.95'/%3E%3C/filter%3E%3Crect width='600' height='600' filter='url(%23f)' opacity='0.55'/%3E%3C/svg%3E"),
    repeating-linear-gradient(90deg, transparent 0 239px, rgba(80,45,15,.18) 239px 241px, transparent 241px 480px),
    linear-gradient(90deg, #c48c50, #d4a066 30%, #c99257 55%, #d7a56c 80%, #c38a4e);
  background-size: 600px 600px, 480px 100%, 100% 100%;
  padding: 18px 14px 28px;
}
.layout {
  max-width: 1240px; margin: 0 auto;
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 28px; align-items: start;
}

/* ---------- Brett (Leinwand) ---------- */
.board-area { display: flex; justify-content: center; }
.board {
  position: relative;
  width: min(100%, calc((100vh - 36px) * 1060 / 1430));
  aspect-ratio: 1060 / 1430;
}
.board svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
#boardStatic { filter: drop-shadow(0 2px 0 #e9e4da) drop-shadow(0 4px 0 #d8d1c4) drop-shadow(0 18px 24px rgba(40, 20, 5, .45)); }
#boardFx { pointer-events: none; }

.tk-ring { transform-box: fill-box; transform-origin: center; animation: ring 1.3s ease-in-out infinite; }
@keyframes ring { 0%,100% { opacity: .9; transform: scale(1); } 50% { opacity: .35; transform: scale(1.18); } }

/* Hinweis-Blase über dem Brett */
.toast {
  position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(.6);
  padding: .55em 1.1em; border-radius: 999px; font-weight: 800; font-size: clamp(18px, 3.2vw, 30px);
  background: var(--paper); border: 4px solid var(--ink); box-shadow: 0 10px 0 rgba(0,0,0,.18), 0 18px 30px rgba(0,0,0,.25);
  opacity: 0; pointer-events: none; white-space: nowrap; transition: opacity .2s, transform .35s cubic-bezier(.2,1.6,.4,1);
  z-index: 5;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.toast.ladder { background: #fff3cf; }
.toast.snake { background: #ffd7dd; }
.toast.six { background: #e9dbff; }

/* ---------- Seitenleiste ---------- */
.side {
  position: sticky; top: 18px;
  background: var(--paper); border-radius: 18px; padding: 18px;
  box-shadow: 0 3px 0 #e2dccf, 0 16px 30px rgba(50, 25, 5, .3);
  display: flex; flex-direction: column; gap: 14px;
}
.title { margin: 0; font-size: 26px; line-height: 1.05; letter-spacing: -.01em; }
.title span { color: var(--violet-d); }
.room-badge { font-size: 14px; background: var(--violet); border-radius: 10px; padding: 6px 10px; font-weight: 700; display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.room-badge button { border: 0; background: rgba(255,255,255,.6); border-radius: 8px; padding: 3px 8px; font-size: 13px; font-weight: 700; }

.turn { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 14px; background: var(--pink); transition: background .3s; }
.turn-token { width: 46px; height: 54px; flex: none; }
.turn-text { display: flex; flex-direction: column; min-width: 0; }
.turn-text small { font-size: 13px; opacity: .7; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.turn-text strong { font-size: 22px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Würfel (silberne Knete) ---------- */
.dice-zone { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 6px 0 2px; }
.die-scene { --s: 74px; width: calc(var(--s) * 1.6); height: calc(var(--s) * 1.5); perspective: 600px; border: 0; background: none; padding: 0; display: grid; place-items: center; position: relative; }
.die-scene::after { content: ""; position: absolute; bottom: 4px; width: calc(var(--s) * .95); height: 14px; border-radius: 50%; background: rgba(0,0,0,.28); filter: blur(5px); transition: transform .3s; }
.die-scene.rolling::after { transform: scale(.65); }
.die-scene:disabled { cursor: default; }
.die { width: var(--s); height: var(--s); position: relative; transform-style: preserve-3d; transform: rotateX(-18deg) rotateY(24deg); transition: transform 1s cubic-bezier(.15, .9, .25, 1.05); }
.die.spin { transition: none; animation: spin .5s linear infinite; }
@keyframes spin { from { transform: rotateX(0) rotateY(0) rotateZ(0); } to { transform: rotateX(360deg) rotateY(720deg) rotateZ(180deg); } }
.die-scene.rolling .die { animation-name: spin; }
.die-scene.bounce { animation: bounce 1s cubic-bezier(.3, 0, .3, 1); }
@keyframes bounce { 0% { transform: translateY(0); } 25% { transform: translateY(-34px); } 50% { transform: translateY(0); } 65% { transform: translateY(-12px); } 80% { transform: translateY(0); } 90% { transform: translateY(-3px); } 100% { transform: translateY(0); } }
.face {
  position: absolute; inset: 0; border-radius: 22%;
  background:
    radial-gradient(circle at 30% 25%, rgba(255,255,255,.95), rgba(255,255,255,0) 45%),
    radial-gradient(circle at 70% 80%, rgba(60,60,70,.35), rgba(0,0,0,0) 60%),
    linear-gradient(135deg, #e6e7ea, #a9abb2 55%, #8d8f97);
  box-shadow: inset 0 0 8px rgba(0,0,0,.35), inset 2px 2px 3px rgba(255,255,255,.7);
  display: grid; grid-template: repeat(3, 1fr) / repeat(3, 1fr); padding: 16%;
  backface-visibility: hidden;
}
.face i { width: 68%; aspect-ratio: 1; border-radius: 50%; place-self: center; background: radial-gradient(circle at 60% 65%, #3a3a3a, #050505 70%); box-shadow: inset 1px 2px 2px rgba(0,0,0,.9), 0 1px 0 rgba(255,255,255,.7); }
.f1 { transform: translateZ(calc(var(--s) / 2)); }
.f6 { transform: rotateY(180deg) translateZ(calc(var(--s) / 2)); }
.f3 { transform: rotateY(90deg) translateZ(calc(var(--s) / 2)); }
.f4 { transform: rotateY(-90deg) translateZ(calc(var(--s) / 2)); }
.f2 { transform: rotateX(90deg) translateZ(calc(var(--s) / 2)); }
.f5 { transform: rotateX(-90deg) translateZ(calc(var(--s) / 2)); }
.f1 i { grid-area: 2 / 2; }
.f2 i:nth-child(1) { grid-area: 1 / 1; } .f2 i:nth-child(2) { grid-area: 3 / 3; }
.f3 i:nth-child(1) { grid-area: 1 / 1; } .f3 i:nth-child(2) { grid-area: 2 / 2; } .f3 i:nth-child(3) { grid-area: 3 / 3; }
.f4 i:nth-child(1) { grid-area: 1 / 1; } .f4 i:nth-child(2) { grid-area: 1 / 3; } .f4 i:nth-child(3) { grid-area: 3 / 1; } .f4 i:nth-child(4) { grid-area: 3 / 3; }
.f5 i:nth-child(1) { grid-area: 1 / 1; } .f5 i:nth-child(2) { grid-area: 1 / 3; } .f5 i:nth-child(3) { grid-area: 2 / 2; } .f5 i:nth-child(4) { grid-area: 3 / 1; } .f5 i:nth-child(5) { grid-area: 3 / 3; }
.f6 i:nth-child(1) { grid-area: 1 / 1; } .f6 i:nth-child(2) { grid-area: 2 / 1; } .f6 i:nth-child(3) { grid-area: 3 / 1; } .f6 i:nth-child(4) { grid-area: 1 / 3; } .f6 i:nth-child(5) { grid-area: 2 / 3; } .f6 i:nth-child(6) { grid-area: 3 / 3; }

.hint { margin: 0; font-size: 13px; opacity: .6; text-align: center; }

/* ---------- Buttons ---------- */
.btn {
  border: 3px solid var(--ink); background: var(--violet); border-radius: 14px; padding: 10px 18px; font-weight: 800; font-size: 17px;
  box-shadow: 0 4px 0 var(--ink); transition: transform .08s, box-shadow .08s, opacity .2s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .45; cursor: default; transform: none; box-shadow: 0 4px 0 var(--ink); }
.btn.roll { width: 100%; font-size: 20px; padding: 12px; background: var(--pink); }
.btn.ghost { background: var(--paper); }
.btn.small { font-size: 14px; padding: 6px 12px; border-width: 2px; box-shadow: 0 3px 0 var(--ink); }

/* ---------- Spielerliste ---------- */
.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.players li { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 12px; border: 2px solid transparent; transition: border-color .3s, background .3s; }
.players li.active { border-color: var(--ink); background: #fff; }
.players .mini { width: 30px; height: 36px; flex: none; }
.players .nm { flex: 1; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.players .pos { font-weight: 800; font-variant-numeric: tabular-nums; background: #f1ede5; border-radius: 8px; padding: 2px 8px; font-size: 14px; }
.players .tag { font-size: 11px; font-weight: 800; background: var(--violet); border-radius: 6px; padding: 1px 6px; margin-left: 4px; vertical-align: middle; }
.players .off { opacity: .45; }

.log { font-size: 14px; max-height: 120px; overflow: auto; display: flex; flex-direction: column-reverse; gap: 3px; border-top: 2px dashed #e3ddd1; padding-top: 8px; }
.log div { opacity: .8; }
.log div:first-child { opacity: 1; font-weight: 700; }
.tools { display: flex; gap: 8px; }
.tools .btn { flex: 1; padding: 8px 6px; font-size: 14px; border-width: 2px; box-shadow: 0 3px 0 var(--ink); }

/* ---------- Dialoge ---------- */
.modal { position: fixed; inset: 0; background: rgba(40, 20, 8, .55); backdrop-filter: blur(4px); display: grid; place-items: center; padding: 16px; z-index: 20; animation: fade .25s; }
.modal[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }
.card {
  width: min(460px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--paper); border: 4px solid var(--ink); border-radius: 22px;
  padding: 0 22px 22px; box-shadow: 0 10px 0 rgba(0,0,0,.25), 0 30px 60px rgba(0,0,0,.35); animation: pop .35s cubic-bezier(.2, 1.5, .4, 1);
}
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
.checker { height: 18px; margin: 0 -22px 14px; background: repeating-conic-gradient(#121212 0 25%, var(--pink) 0 50%) 0 0 / 18px 18px; border-bottom: 3px solid var(--ink); }
.card h2 { margin: 6px 0 6px; font-size: 28px; }
.sub { margin: 0 0 14px; opacity: .7; }
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice { text-align: left; border: 3px solid var(--ink); border-radius: 16px; padding: 12px 14px; background: var(--pink); box-shadow: 0 4px 0 var(--ink); display: flex; flex-direction: column; gap: 2px; transition: transform .08s; }
.choice:nth-child(2) { background: var(--violet); }
.choice:nth-child(3) { background: #fff; }
.choice b { font-size: 19px; }
.choice span { font-size: 14px; opacity: .75; }
.choice:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.choice:disabled { opacity: .4; }
.offline-note { font-size: 13px; opacity: .7; margin: 12px 0 0; }

.count { display: flex; gap: 8px; margin-bottom: 14px; }
.count button { flex: 1; border: 3px solid var(--ink); border-radius: 12px; background: #fff; font-size: 20px; font-weight: 800; padding: 6px; }
.count button.on { background: var(--violet); }
.prow { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.prow input { flex: 1; min-width: 0; }
input { font: inherit; font-size: 17px; padding: 10px 12px; border: 3px solid var(--ink); border-radius: 12px; background: #fff; width: 100%; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: 700; font-size: 14px; }
#codeInput { text-transform: uppercase; letter-spacing: .3em; font-weight: 800; font-size: 22px; }
.label { font-weight: 700; font-size: 14px; display: block; margin-bottom: 6px; }
.token-pick { display: flex; gap: 6px; }
.token-pick button { width: 52px; height: 58px; border: 3px solid transparent; border-radius: 12px; background: #f1ede5; padding: 2px; }
.prow .token-pick button { width: 42px; height: 48px; }
.token-pick button.on { border-color: var(--ink); background: #fff; }
.token-pick button:disabled { opacity: .25; }
.token-pick svg { width: 100%; height: 100%; }
.actions { display: flex; gap: 10px; margin-top: 18px; }
.actions .btn { flex: 1; }
.error { color: #b3123f; font-weight: 700; min-height: 1.2em; margin: 8px 0 0; font-size: 14px; }
.bigcode { font-size: 54px; font-weight: 900; letter-spacing: .18em; text-align: center; background: var(--pink); border: 3px dashed var(--ink); border-radius: 16px; margin-bottom: 10px; }
.lobby-list { margin: 14px 0 6px; }
.rules { padding-left: 20px; line-height: 1.45; }
.rules li { margin-bottom: 6px; }
.win .card { text-align: center; }
.win-token { width: 110px; height: 130px; margin: 6px auto 0; animation: jump 1s ease-in-out infinite; }
@keyframes jump { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-14px) rotate(-4deg); } }
.win h2 { font-size: 36px; }

#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 30; }

/* ---------- Handy / Tablet ---------- */
@media (max-width: 900px) {
  .table { padding: 10px 6px 18px; }
  .layout { grid-template-columns: 1fr; gap: 14px; }
  .board { width: min(100%, 640px); }
  .side { position: static; display: grid; grid-template-columns: 1fr 1fr; padding: 14px; gap: 12px; }
  .title, .room-badge, .players, .log, .tools { grid-column: 1 / -1; }
  .title { display: none; }
  .turn { grid-column: 1; align-self: center; }
  .dice-zone { grid-column: 2; padding: 0; }
  .die-scene { --s: 54px; }
  .btn.roll { font-size: 16px; padding: 10px 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .board { width: min(100%, 640px, calc((100vh - 190px) * 1060 / 1430)); }
  .turn-text strong { font-size: 18px; }
  .hint { display: none; }
  .players { flex-direction: row; flex-wrap: wrap; }
  .players li { flex: 1 1 45%; }
  .log { max-height: 70px; }
  .roll-dock { position: sticky; bottom: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .tk-ring, .win-token { animation: none; }
}
