/* ============================================================
   Flip 7 – Zählhilfe · Stylesheet
   Warme, papierartige Optik · echte Karten · Hell/Dunkel
   ============================================================ */

/* ---- Design-Tokens ------------------------------------------------ */
:root {
  --bg:        #f4f0e8;
  --bg-2:      #ece6da;
  --surface:   #fffdf9;
  --surface-2: #f7f2e9;
  --ink:       #211f1b;
  --ink-soft:  #4a463e;
  --muted:     #857f72;
  --line:      #e3dccd;
  --line-2:    #d6cdba;
  --accent:    #e4572e;
  --accent-ink:#ffffff;
  --accent-2:  #2e7da3;
  --good:      #3fa34d;
  --warn:      #d98a1f;
  --bad:       #d64545;
  --gold:      #caa53d;
  --shadow:    0 1px 2px rgba(40,30,15,.06), 0 6px 18px rgba(40,30,15,.08);
  --shadow-lg: 0 8px 40px rgba(30,20,10,.20);
  --radius:    18px;
  --radius-sm: 12px;
  --card-radius: 14px;
  --tap: 46px;
  --maxw: 720px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:        #14161a;
    --bg-2:      #101216;
    --surface:   #1e2127;
    --surface-2: #262a31;
    --ink:       #f1efe9;
    --ink-soft:  #d3d0c8;
    --muted:     #938e84;
    --line:      #2c313a;
    --line-2:    #3a4049;
    --accent:    #f26a43;
    --accent-ink:#1a1108;
    --accent-2:  #58b0d6;
    --good:      #56c168;
    --warn:      #e0a244;
    --bad:       #ef6b6b;
    --gold:      #d9b84a;
    --shadow:    0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
    --shadow-lg: 0 10px 44px rgba(0,0,0,.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg:        #14161a;
  --bg-2:      #101216;
  --surface:   #1e2127;
  --surface-2: #262a31;
  --ink:       #f1efe9;
  --ink-soft:  #d3d0c8;
  --muted:     #938e84;
  --line:      #2c313a;
  --line-2:    #3a4049;
  --accent:    #f26a43;
  --accent-ink:#1a1108;
  --accent-2:  #58b0d6;
  --good:      #56c168;
  --warn:      #e0a244;
  --bad:       #ef6b6b;
  --gold:      #d9b84a;
  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
  --shadow-lg: 0 10px 44px rgba(0,0,0,.55);
  color-scheme: dark;
}

/* ---- Reset -------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
h1, h2, h3 { line-height: 1.15; letter-spacing: -0.02em; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.tnum { font-variant-numeric: tabular-nums; }

/* ---- App-Shell ---------------------------------------------------- */
#app { min-height: 100dvh; display: flex; flex-direction: column; }
.wrap { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 16px; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  padding-top: var(--safe-t);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar__inner { display: flex; align-items: center; gap: 12px; height: 58px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.03em; }
.brand__mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(160deg, #ef6b3f, #c93a1a); color: #fff;
  font-weight: 900; font-size: 17px; box-shadow: var(--shadow);
}
.brand__name { font-size: 17px; }
.brand__sub { color: var(--muted); font-weight: 600; font-size: 12px; margin-left: -4px; }
.topbar__spacer { flex: 1; }

.iconbtn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line);
  box-shadow: var(--shadow); transition: transform .12s ease;
}
.iconbtn:active { transform: scale(.92); }
.iconbtn svg { width: 20px; height: 20px; }

.screen { flex: 1; padding: 20px 0 calc(28px + var(--safe-b)); }

/* ---- Typo-Bausteine ---------------------------------------------- */
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: 12px; font-weight: 700; color: var(--muted); }
.muted { color: var(--muted); }
.h-title { font-size: clamp(26px, 7vw, 34px); font-weight: 850; }
.lead { color: var(--ink-soft); font-size: 16px; }

/* ---- Buttons ------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 20px; border-radius: 14px;
  font-weight: 700; font-size: 16px; letter-spacing: -.01em;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line-2);
  box-shadow: var(--shadow); transition: transform .12s ease, filter .12s ease;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active { transform: translateY(1px) scale(.99); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn--primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn--ghost { background: transparent; box-shadow: none; }
.btn--lg { min-height: 56px; font-size: 18px; border-radius: 16px; width: 100%; }
.btn--block { width: 100%; }
.btn--danger { color: var(--bad); }
.btn svg { width: 20px; height: 20px; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row--wrap { flex-wrap: wrap; }

/* ---- Panels / Cards ---------------------------------------------- */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.panel + .panel { margin-top: 14px; }
.panel__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }

/* ---- Start / Join ------------------------------------------------- */
.hero { text-align: center; padding: 22px 0 8px; }
.hero__logo {
  width: 82px; height: 82px; border-radius: 22px; margin: 0 auto 18px;
  background: linear-gradient(160deg, #ef6b3f, #c93a1a); color: #fff;
  display: grid; place-items: center; font-size: 46px; font-weight: 900;
  box-shadow: var(--shadow-lg);
}
.field { display: flex; flex-direction: column; gap: 7px; }
.field > label { font-weight: 700; font-size: 14px; color: var(--ink-soft); }
.input {
  width: 100%; min-height: var(--tap); padding: 0 16px; border-radius: 14px;
  background: var(--surface-2); border: 1.5px solid var(--line-2); color: var(--ink);
  font-size: 17px;
}
.input::placeholder { color: var(--muted); }
.input--code { text-align: center; letter-spacing: .35em; font-weight: 800; text-transform: uppercase; font-size: 24px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; margin: 6px 0; }
.divider::before, .divider::after { content: ""; height: 1px; flex: 1; background: var(--line); }

/* ---- Modus-Auswahl ------------------------------------------------ */
.modeopts { display: flex; flex-direction: column; gap: 10px; }
.modeopt {
  display: block; width: 100%; text-align: left; padding: 14px 16px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1.5px solid var(--line-2); box-shadow: var(--shadow);
  transition: border-color .12s ease, transform .1s ease;
}
.modeopt:active { transform: scale(.99); }
.modeopt--on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--surface)); }
.modeopt__head { display: flex; align-items: center; gap: 10px; }
.modeopt__title { font-weight: 800; font-size: 16px; flex: 1; }
.modeopt__radio { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-2); flex: none; position: relative; }
.modeopt--on .modeopt__radio { border-color: var(--accent); }
.modeopt--on .modeopt__radio::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--accent); }
.modeopt__text { color: var(--ink-soft); font-size: 13.5px; margin-top: 6px; line-height: 1.4; }

.modeinfo {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--accent-2) 10%, var(--surface)); border: 1px solid var(--line);
}
.modeinfo__icon { font-size: 22px; line-height: 1; }
.modeinfo b { display: block; margin-bottom: 2px; }
.modeinfo p { color: var(--ink-soft); font-size: 13.5px; line-height: 1.4; }

/* ---- Zähl-Modus: Punkteingabe ------------------------------------ */
.scoreentry { display: flex; flex-direction: column; gap: 12px; align-items: center; }
.scoreinput {
  width: 100%; max-width: 260px; text-align: center; font-size: 46px; font-weight: 850;
  height: 88px; border-radius: 16px; letter-spacing: .02em;
}
.scoreentry .btn { width: 100%; }
.submitcount { text-align: center; color: var(--muted); font-size: 13px; }

/* ---- Lobby -------------------------------------------------------- */
.roomname { display: flex; align-items: center; gap: 8px; }
.roomname h1 { font-size: clamp(22px, 6vw, 30px); font-weight: 850; }
.roomname .iconbtn { width: 34px; height: 34px; }
.codechip {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--line-2); font-weight: 800; letter-spacing: .18em;
}

.players { display: flex; flex-direction: column; gap: 8px; }
.playerrow {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line);
}
.avatar {
  width: 38px; height: 38px; border-radius: 11px; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 800; font-size: 16px;
}
.playerrow__name { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em;
  padding: 3px 8px; border-radius: 999px; background: var(--bg-2); color: var(--muted); }
.badge--admin { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.badge--you { background: color-mix(in srgb, var(--accent-2) 18%, transparent); color: var(--accent-2); }

/* ---- Turn banner -------------------------------------------------- */
.turnbanner {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
}
.turnbanner--me {
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 20%, var(--surface)), var(--surface));
  border-color: color-mix(in srgb, var(--accent) 40%, var(--line));
}
.turnbanner__dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); flex: none;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); }
.turnbanner--me .turnbanner__dot { animation: pulse 1.6s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 55%, transparent); }
  70% { box-shadow: 0 0 0 12px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
.turnbanner__txt b { font-size: 18px; }
.turnbanner__txt span { display: block; font-size: 13px; color: var(--muted); }

/* ---- Player strip (live) ----------------------------------------- */
.strip { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(112px, 1fr);
  gap: 10px; overflow-x: auto; padding: 4px 2px 8px; scroll-snap-type: x proximity; }
.strip::-webkit-scrollbar { height: 6px; }
.strip::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }
.pcard {
  scroll-snap-align: start; position: relative; padding: 12px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1.5px solid var(--line); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px; min-width: 112px;
}
.pcard--turn { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent), var(--shadow); }
.pcard--done { opacity: .82; }
.pcard__top { display: flex; align-items: center; gap: 8px; }
.pcard__name { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pcard__dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.pcard__score { font-size: 30px; font-weight: 850; letter-spacing: -.03em; }
.pcard__meta { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); }
.pcard__state { font-weight: 800; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.state-active { color: var(--good); }
.state-stayed { color: var(--accent-2); }
.state-busted { color: var(--bad); }
.state-frozen { color: var(--accent-2); }
.state-flip7  { color: var(--gold); }
.pcard__sc { position: absolute; top: 8px; right: 8px; font-size: 13px; }

/* ---- Hand --------------------------------------------------------- */
.hand__head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.hand__score { font-size: 40px; font-weight: 850; letter-spacing: -.03em; }
.hand__score small { font-size: 14px; color: var(--muted); font-weight: 700; }
.cards { display: flex; flex-wrap: wrap; gap: 8px; min-height: 74px; align-content: flex-start; }
.cards--empty { align-items: center; justify-content: center; color: var(--muted); font-size: 14px; }

.card {
  --c: #888;
  width: 52px; height: 72px; border-radius: var(--card-radius); flex: none;
  display: grid; place-items: center; position: relative;
  background: var(--surface); border: 2px solid var(--c);
  box-shadow: var(--shadow); font-weight: 850; font-size: 26px; color: var(--c);
  animation: dealin .18s ease;
}
@keyframes dealin { from { transform: translateY(6px) scale(.9); opacity: 0; } }
.card__pip { position: absolute; top: 4px; left: 6px; font-size: 11px; font-weight: 800; opacity: .8; }
.card--num { background: var(--c); color: #fff; border-color: transparent; text-shadow: 0 1px 1px rgba(0,0,0,.18); }
.card--mod { background: var(--surface); color: var(--gold); border-color: var(--gold); font-size: 22px; }
.card--act { font-size: 13px; text-align: center; line-height: 1.05; padding: 4px; }
.card--freeze { color: var(--accent-2); border-color: var(--accent-2); }
.card--flipThree { color: var(--accent); border-color: var(--accent); }
.card--secondChance { color: var(--good); border-color: var(--good); }
.card--sm { width: 34px; height: 48px; font-size: 17px; border-width: 1.5px; }

/* ---- Action bar --------------------------------------------------- */
.actionbar {
  position: sticky; bottom: 0; z-index: 15; margin-top: 14px;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.actionbar__inner { max-width: var(--maxw); margin: 0 auto; display: flex; gap: 10px; }
.actionbar .btn { flex: 1; }
.hint { text-align: center; color: var(--muted); font-size: 13px; padding: 10px; }

/* ---- Card picker (dialog) ---------------------------------------- */
.dialog {
  border: none; padding: 0; background: transparent; color: var(--ink);
  max-width: 100vw; width: 100%; margin: auto auto 0;
}
.dialog::backdrop { background: rgba(15,10,5,.5); backdrop-filter: blur(2px); }
.sheet {
  background: var(--surface); border-radius: 22px 22px 0 0; border: 1px solid var(--line);
  padding: 16px 16px calc(20px + var(--safe-b)); box-shadow: var(--shadow-lg);
  max-width: var(--maxw); margin: 0 auto; animation: sheetin .22s cubic-bezier(.2,.9,.3,1);
}
@media (min-width: 560px) { .dialog { margin: auto; } .sheet { border-radius: 22px; } }
@keyframes sheetin { from { transform: translateY(24px); opacity: .6; } }
.sheet__grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line-2); margin: 2px auto 14px; }
.sheet__title { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.sheet__sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.sheet__section { margin-top: 16px; }
.sheet__label { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin-bottom: 8px; }

.numgrid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.pickcard {
  aspect-ratio: 3/4; border-radius: 12px; display: grid; place-items: center; position: relative;
  background: var(--c, var(--surface-2)); color: #fff; border: 2px solid transparent;
  font-weight: 850; font-size: 22px; box-shadow: var(--shadow); transition: transform .1s ease;
}
.pickcard:active { transform: scale(.9); }
.pickcard--owned::after { content: ""; position: absolute; inset: 0; border-radius: 10px;
  background: repeating-linear-gradient(45deg, transparent, transparent 6px, rgba(255,255,255,.25) 6px, rgba(255,255,255,.25) 8px); }
.pickcard--owned-dot { position: absolute; top: 4px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: #fff; box-shadow: 0 0 0 2px rgba(0,0,0,.15); }
.modrow, .actrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chipbtn {
  min-height: 52px; border-radius: 12px; background: var(--surface-2); border: 1.5px solid var(--line-2);
  font-weight: 800; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  box-shadow: var(--shadow); transition: transform .1s ease;
}
.chipbtn:active { transform: scale(.94); }
.chipbtn small { font-size: 11px; font-weight: 600; color: var(--muted); }
.chipbtn--mod { color: var(--gold); border-color: color-mix(in srgb, var(--gold) 55%, var(--line-2)); }
.chipbtn--freeze { color: var(--accent-2); }
.chipbtn--flip { color: var(--accent); }
.chipbtn--sc { color: var(--good); }

.targetlist { display: flex; flex-direction: column; gap: 8px; }

/* ---- Scoreboard grid --------------------------------------------- */
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; }
.tab { padding: 8px 16px; border-radius: 999px; font-weight: 700; font-size: 14px; color: var(--muted); }
.tab--on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.board { overflow-x: auto; border-radius: var(--radius-sm); border: 1px solid var(--line); }
table.grid { border-collapse: collapse; width: 100%; min-width: max-content; background: var(--surface); }
table.grid th, table.grid td { padding: 10px 12px; text-align: center; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); white-space: nowrap; }
table.grid th:first-child, table.grid td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; }
table.grid thead th { background: var(--surface-2); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
table.grid td.total { font-weight: 850; font-size: 17px; background: var(--surface-2); }
table.grid tr.leader td.total { color: var(--accent); }
table.grid td.playercell { display: flex; align-items: center; gap: 8px; }

/* ---- Winner ------------------------------------------------------- */
.winner { text-align: center; padding: 26px 0; }
.winner__crown { font-size: 52px; }
.winner__name { font-size: 32px; font-weight: 850; margin-top: 6px; }
.winner__score { color: var(--muted); font-size: 16px; }

/* ---- Toasts ------------------------------------------------------- */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(90px + var(--safe-b)); z-index: 50;
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast {
  pointer-events: auto; max-width: 420px; width: fit-content; padding: 12px 16px; border-radius: 14px;
  background: var(--ink); color: var(--bg); font-weight: 700; font-size: 14px; box-shadow: var(--shadow-lg);
  animation: toastin .2s ease; display: flex; align-items: center; gap: 8px;
}
.toast--good { background: var(--good); color: #04220a; }
.toast--bad { background: var(--bad); color: #2a0606; }
.toast--gold { background: var(--gold); color: #241c02; }
.toast--info { background: var(--accent-2); color: #041722; }
@keyframes toastin { from { transform: translateY(10px); opacity: 0; } }

/* ---- Misc --------------------------------------------------------- */
.spinner { width: 30px; height: 30px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--accent); animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-note { text-align: center; color: var(--muted); padding: 40px 20px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
