:root {
  --bg: #12301f;
  --bg2: #0c2216;
  --felt: #1a4a30;
  --ink: #f4efe2;
  --muted: #a9bfb0;
  --gold: #e6c35c;
  --card: #fbf8ef;
  --red: #c4262e;
  --blk: #1b1b1f;
  --accent: #e6c35c;
  --danger: #d9534f;
  --cw: clamp(36px, calc((100vw - 28px) / 10), 64px);
  --sw: clamp(10px, 2.2vw, 20px);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(ellipse at top, var(--felt), var(--bg) 60%, var(--bg2));
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.hidden { display: none !important; }

.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 12px; background: rgba(0,0,0,.25); border-bottom: 1px solid rgba(255,255,255,.08);
}
.topbar h1 { font-size: 1.05rem; margin: 0; color: var(--gold); letter-spacing: .5px; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.round-info { font-size: .85rem; color: var(--muted); }
.speed { font-size: .78rem; color: var(--muted); display: flex; align-items: center; gap: 4px; }
select, input[type=text] {
  background: #0b2014; color: var(--ink); border: 1px solid rgba(255,255,255,.2); border-radius: 6px; padding: 5px 7px; font: inherit; font-size: .85rem;
}
.btn {
  background: var(--gold); color: #251c00; border: 0; border-radius: 8px; padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer;
  min-height: 38px;
}
.btn:hover:not(:disabled) { filter: brightness(1.08); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.small { padding: 5px 10px; min-height: 30px; font-size: .8rem; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid rgba(255,255,255,.3); }
.btn.danger { background: var(--danger); color: #fff; }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }

main { max-width: 980px; margin: 0 auto; padding: 10px 10px 40px; }
.panel { background: rgba(0,0,0,.25); border: 1px solid rgba(255,255,255,.1); border-radius: 12px; padding: 16px; }
.panel h2 { margin-top: 0; color: var(--gold); }
.field { margin: 12px 0; }
.field label.title { display: block; margin-bottom: 6px; color: var(--muted); font-size: .85rem; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { background: #0b2014; color: var(--ink); border: 1px solid rgba(255,255,255,.2); border-radius: 8px; padding: 8px 14px; cursor: pointer; font: inherit; }
.seg button.on { background: var(--gold); color: #251c00; border-color: var(--gold); font-weight: 700; }
.bot-row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.bot-row .nm { width: 90px; font-weight: 600; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

/* ----- Gegner ----- */
.opponents { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 8px; }
.opp {
  background: rgba(0,0,0,.28); border: 2px solid transparent; border-radius: 10px; padding: 7px 10px; min-width: 140px; flex: 1 1 140px; max-width: 220px;
}
.opp.active { border-color: var(--gold); box-shadow: 0 0 12px rgba(230,195,92,.4); }
.opp .nm { font-weight: 700; display: flex; justify-content: space-between; gap: 6px; }
.opp .lv { font-size: .7rem; color: var(--muted); font-weight: 400; }
.opp .sc { color: var(--gold); }
.backs { display: flex; gap: 2px; margin: 5px 0; }
.mini-back { width: 14px; height: 20px; border-radius: 3px; background: repeating-linear-gradient(45deg,#6b2431,#6b2431 3px,#85323f 3px,#85323f 6px); border: 1px solid #f0e6d0; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; min-height: 18px; }
.badge { font-size: .68rem; background: rgba(255,255,255,.12); border-radius: 10px; padding: 1px 7px; }
.badge.warn { background: rgba(217,83,79,.35); }
.badge.good { background: rgba(80,180,120,.35); }

/* ----- Mitte ----- */
.center { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 8px 0; }
.pile-wrap { text-align: center; }
.pile-label { font-size: .7rem; color: var(--muted); margin-top: 3px; }
.pile {
  position: relative; width: calc(var(--cw) * 1.25); height: calc(var(--cw) * 1.9);
  min-width: 52px; min-height: 80px; background: transparent; border: 2px dashed rgba(255,255,255,.2); border-radius: 8px; padding: 0; color: var(--ink); cursor: default;
  display: flex; align-items: center; justify-content: center;
}
.pile.clickable { cursor: pointer; border-color: var(--gold); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(230,195,92,.0);} 50% { box-shadow: 0 0 12px 3px rgba(230,195,92,.55);} }
.pile .count { position: absolute; bottom: -2px; right: 2px; font-size: .7rem; background: rgba(0,0,0,.6); border-radius: 8px; padding: 0 5px; z-index: 3; }
.back-card { width: 100%; height: 100%; border-radius: 6px; background: repeating-linear-gradient(45deg,#6b2431,#6b2431 6px,#85323f 6px,#85323f 12px); border: 2px solid #f0e6d0; }
.center-info { flex: 1; max-width: 360px; text-align: center; }
.ticker { font-size: .8rem; color: var(--muted); min-height: 2.4em; }
.status { font-size: .95rem; font-weight: 600; margin-top: 4px; color: var(--ink); }

.controls { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin: 10px 0; min-height: 40px; }

/* ----- Karten ----- */
.card {
  position: relative; width: var(--cw); height: calc(var(--cw) * 1.5); background: var(--card); border-radius: 6px;
  border: 1px solid #b9b19b; color: var(--blk); display: flex; flex-direction: column; flex: 0 0 auto;
  box-shadow: 0 2px 4px rgba(0,0,0,.35); transition: transform .35s, box-shadow .15s, outline-color .15s; user-select: none;
}
.card.flipped { transform: rotate(180deg); }
.card .half { position: relative; flex: 1; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.card .half.bottom { transform: rotate(180deg); }
.card .half.top { border-bottom: 1px dashed #c7bfa8; }
.card .half.red { color: var(--red); }
.card .rk { position: absolute; top: 1px; left: 3px; font-weight: 800; font-size: calc(var(--cw) * .27); line-height: 1; }
.card .st { font-size: calc(var(--cw) * .55); line-height: 1; margin-top: calc(var(--cw) * .1); }
.card.small { --cw: 40px; }
.card.mini { --cw: 30px; }
.card.clickable { cursor: pointer; }
.card.clickable:hover { box-shadow: 0 0 0 2px var(--gold), 0 4px 8px rgba(0,0,0,.4); }
.card.selected { outline: 3px solid var(--gold); outline-offset: 1px; }
.card.dim { opacity: .45; }
.card.target { outline: 3px solid #70c1ff; }
.card.isnew::after { content: "neu"; position: absolute; top: -9px; left: 50%; transform: translateX(-50%) rotate(0deg); font-size: .6rem; background: var(--gold); color: #251c00; border-radius: 6px; padding: 0 4px; font-weight: 700; z-index: 2; }
.card.flipped.isnew::after { transform: translateX(-50%) rotate(180deg); top: auto; bottom: -9px; }

/* ----- Eigene Hand ----- */
.me { margin-top: 6px; }
.me-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; font-size: .9rem; }
.me-bar .nm { font-weight: 700; }
.me-bar .sc { color: var(--gold); font-weight: 700; }
.pending-area { display: flex; justify-content: center; align-items: center; gap: 12px; min-height: 8px; margin: 4px 0 8px; }
.pending-area .lbl { font-size: .8rem; color: var(--muted); }
.hand { display: flex; align-items: center; justify-content: center; padding: 14px 4px 4px; overflow-x: auto; min-height: calc(var(--cw) * 1.5 + 22px); }
.hand-idx { display: flex; justify-content: center; font-size: .65rem; color: var(--muted); }
.slot {
  flex: 0 0 var(--sw); width: var(--sw); height: calc(var(--cw) * 1.5); display: flex; align-items: center; justify-content: center;
  background: rgba(230,195,92,.18); border: 1px dashed var(--gold); border-radius: 4px; color: var(--gold); font-weight: 800; cursor: pointer; font-size: .8rem; padding: 0;
}
.slot:hover { background: rgba(230,195,92,.45); }
.gap { flex: 0 0 4px; }
.idx { text-align: center; }

/* ----- Log ----- */
.logbox { margin-top: 14px; background: rgba(0,0,0,.22); border-radius: 8px; padding: 6px 10px; font-size: .8rem; }
.logbox summary { cursor: pointer; color: var(--muted); }
.log { max-height: 220px; overflow-y: auto; margin: 6px 0 0; padding-left: 18px; display: flex; flex-direction: column-reverse; }
.log li { margin: 1px 0; color: #d6e2d9; }
.log li.round { color: var(--gold); font-weight: 600; }
.log li.attack { color: #ff9c8f; }
.log li.score { color: #9fe3b4; }

/* ----- Modal ----- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 14px; z-index: 50; }
.modal-card { background: #17392a; border: 1px solid rgba(255,255,255,.2); border-radius: 12px; padding: 16px; width: 100%; max-width: 760px; margin: auto; }
.modal-card h2 { margin: 0 0 8px; color: var(--gold); }
.modal-card h3 { color: var(--gold); margin: 14px 0 4px; font-size: 1rem; }
.modal-card p, .modal-card li { line-height: 1.45; font-size: .92rem; }
.modal-card ul { padding-left: 20px; }
.res-row { border-top: 1px solid rgba(255,255,255,.12); padding: 8px 0; }
.res-row .head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.res-row .cards { display: flex; gap: 4px; margin: 6px 0; flex-wrap: wrap; }
.res-row .pts { color: var(--gold); }
table.score { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.score td, table.score th { padding: 4px 6px; border-bottom: 1px solid rgba(255,255,255,.12); text-align: left; font-size: .9rem; }
table.score td.num, table.score th.num { text-align: right; }
.win-opts { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; }
.win-opt { text-align: left; background: #0b2014; color: var(--ink); border: 2px solid rgba(255,255,255,.2); border-radius: 8px; padding: 8px 10px; cursor: pointer; font: inherit; }
.win-opt.on { border-color: var(--gold); background: #24472f; }
.hand-preview { display: flex; justify-content: center; gap: 4px; flex-wrap: wrap; margin: 8px 0; }
.hand-preview .card.inwin { outline: 3px solid var(--gold); outline-offset: 1px; }
.hand-preview .card.outwin { opacity: .45; }

@media (max-width: 520px) {
  .center { gap: 6px; }
  .opp { min-width: 120px; padding: 5px 7px; }
}

/* Ergänzungen */
.hc { display: flex; flex-direction: column; align-items: center; flex: 0 0 auto; }
.hc .idx { font-size: .65rem; color: var(--muted); margin-top: 3px; }
.hand { align-items: flex-start; }
.pile .card { width: 100%; height: 100%; }
.pile .card.flipped { transform: rotate(180deg); }
.pending-area .card { --cw: clamp(44px, 12vw, 70px); }
.card.small .rk { font-size: 11px; }
.card.small .st { font-size: 20px; }
