:root {
  --wood: #2b1d14;
  --wood-2: #3a281b;
  --wood-3: #4a3424;
  --parch: #f1e2c0;
  --parch-2: #e4cf9f;
  --ink: #3b2414;
  --ink-soft: #6b4a32;
  --gold: #e0a42b;
  --gold-2: #b97f12;
  --green: #5d8a3a;
  --green-2: #436a27;
  --red: #c8442f;
  --red-2: #962d1d;
  --cream: #fff8e8;
  --serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; touch-action: manipulation; }
body {
  background: var(--wood);
  background-image:
    repeating-linear-gradient(92deg, rgba(255,255,255,.018) 0 2px, transparent 2px 9px),
    radial-gradient(circle at 50% 0%, #4a3222 0%, var(--wood) 70%);
  color: var(--cream);
  font-family: var(--sans);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-text-size-adjust: 100%;
}
input { -webkit-user-select: text; user-select: text; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
[hidden] { display: none !important; }

#app { max-width: 520px; margin: 0 auto; height: 100dvh; position: relative; }
.screen { display: none; height: 100%; overflow-y: auto; padding: calc(var(--safe-t) + 12px) 16px calc(var(--safe-b) + 16px); }
.screen.active { display: block; }
#scr-game.active { display: flex; flex-direction: column; overflow: hidden; padding: calc(var(--safe-t) + 6px) 10px calc(var(--safe-b) + 8px); gap: 6px; }

/* ---------- Buttons ---------- */
.btn {
  display: block; width: 100%; border: 0; border-radius: 14px; padding: 13px 16px;
  font-weight: 700; font-size: 17px; background: var(--wood-3); color: var(--cream);
  box-shadow: 0 4px 0 rgba(0,0,0,.35); transition: transform .06s, box-shadow .06s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.btn:disabled { opacity: .45; }
.btn-big { font-size: 20px; padding: 16px; font-family: var(--serif); }
.btn-gold { background: linear-gradient(#f0bd4f, var(--gold)); color: #3a2205; box-shadow: 0 4px 0 var(--gold-2); }
.btn-gold:active { box-shadow: 0 1px 0 var(--gold-2); }
.btn-green { background: linear-gradient(#73a64b, var(--green)); box-shadow: 0 4px 0 var(--green-2); }
.btn-green:active { box-shadow: 0 1px 0 var(--green-2); }
.btn-ghost { background: transparent; box-shadow: none; color: #cdb999; font-weight: 500; font-size: 15px; text-decoration: underline; }
.btn-small { display: inline-block; width: auto; padding: 8px 16px; font-size: 15px; }

/* ---------- Start ---------- */
.start-wrap, .lobby-wrap, .vote-wrap, .end-wrap { display: flex; flex-direction: column; gap: 14px; min-height: 100%; }
.logo { text-align: center; margin: 8px 0 6px; }
.logo-pot { font-size: 72px; line-height: 1; filter: drop-shadow(0 6px 10px rgba(0,0,0,.5)); animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-3deg); } }
h1 { font-family: var(--serif); font-size: 34px; line-height: 1.05; margin: 10px 0 4px; color: var(--parch); text-shadow: 0 3px 0 rgba(0,0,0,.4); }
h1 span { font-size: 23px; color: var(--gold); font-style: italic; }
h2 { font-family: var(--serif); color: var(--parch); margin: 4px 0; font-size: 24px; }
.tagline { color: #cdb999; margin: 4px 0 0; }
.field span { display: block; font-size: 14px; color: #cdb999; margin-bottom: 6px; }
input {
  width: 100%; font-size: 19px; padding: 13px 14px; border-radius: 12px; border: 2px solid var(--parch-2);
  background: var(--parch); color: var(--ink); font-family: var(--serif); outline: none;
}
input:focus { border-color: var(--gold); }
.or { text-align: center; color: #a88f6d; font-size: 14px; display: flex; align-items: center; gap: 10px; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: #5a4330; }
.join-row { display: flex; gap: 10px; }
.join-row input { flex: 1; text-transform: uppercase; letter-spacing: 6px; text-align: center; font-weight: 700; }
.join-row .btn { width: auto; flex: 0 0 auto; }
.rules { background: var(--parch); color: var(--ink); border-radius: 14px; padding: 12px 14px; margin-top: 6px; }
.rules summary { font-family: var(--serif); font-weight: 700; font-size: 17px; }
.rules ol { padding-left: 20px; margin: 10px 0 0; line-height: 1.45; font-size: 15px; }
.rules li { margin-bottom: 6px; }

/* ---------- Lobby ---------- */
.lobby-head { text-align: center; background: var(--parch); color: var(--ink); border-radius: 18px; padding: 14px; box-shadow: 0 6px 0 rgba(0,0,0,.3); }
.lbl { font-size: 13px; text-transform: uppercase; letter-spacing: 2px; color: var(--ink-soft); }
.code { font-family: var(--serif); font-size: 54px; font-weight: 700; letter-spacing: 10px; margin: 2px 0 8px; padding-left: 10px; }
.link { font-size: 13px; color: var(--ink-soft); margin-top: 8px; word-break: break-all; -webkit-user-select: text; user-select: text; }
.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.plist li { display: flex; align-items: center; gap: 10px; background: var(--wood-2); border-radius: 12px; padding: 10px 12px; font-size: 17px; }
.plist li.off { opacity: .45; }
.dot { width: 26px; height: 26px; border-radius: 50%; flex: 0 0 auto; display: grid; place-items: center; font-size: 13px; font-weight: 800; color: #fff; border: 2px solid rgba(255,255,255,.6); }
.plist .tag { margin-left: auto; font-size: 13px; color: #cdb999; }
.settings { background: var(--wood-2); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.settings.readonly .seg button { pointer-events: none; }
.set-row { display: flex; flex-direction: column; gap: 6px; }
.set-lbl { font-size: 13px; color: #cdb999; text-transform: uppercase; letter-spacing: 1.5px; }
.seg { display: flex; background: var(--wood); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; border-radius: 9px; padding: 10px 4px; background: transparent; font-weight: 700; font-size: 15px; color: #cdb999; }
.seg button.on { background: var(--gold); color: #3a2205; }
.mode-desc { margin: 0; font-size: 14px; color: #e5d4b5; line-height: 1.4; }
.lobby-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.wait { text-align: center; color: #cdb999; font-style: italic; margin: 6px 0; }

/* ---------- Spiel: HUD ---------- */
.hud { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.timer { font-family: var(--serif); font-weight: 700; font-size: 22px; min-width: 58px; color: var(--parch); }
.timer.hurry { color: #ff8a6a; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.teambar { flex: 1; height: 28px; background: var(--wood); border-radius: 14px; position: relative; overflow: hidden; border: 2px solid var(--wood-3); }
.teambar .fill { position: absolute; inset: 0 auto 0 0; width: 0; background: linear-gradient(90deg, var(--gold-2), var(--gold)); transition: width .4s; }
.teambar span { position: relative; display: block; text-align: center; line-height: 24px; font-weight: 800; font-size: 14px; text-shadow: 0 1px 2px rgba(0,0,0,.6); }
.role-badge { font-size: 22px; min-width: 28px; text-align: center; }
.order {
  flex: 0 0 auto; display: flex; align-items: center; gap: 10px; background: var(--parch); color: var(--ink);
  border-radius: 12px; padding: 6px 12px; box-shadow: 0 3px 0 rgba(0,0,0,.3);
}
.order .o-emoji { font-size: 28px; }
.order .o-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--ink-soft); }
.order .o-name { font-family: var(--serif); font-weight: 700; font-size: 18px; line-height: 1.1; }
.order .o-stars { margin-left: auto; font-size: 13px; color: var(--ink-soft); text-align: right; }

/* ---------- Mitspieler ---------- */
.others { flex: 0 0 auto; display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; min-height: 0; }
.others::-webkit-scrollbar { display: none; }
.others:empty { display: none; }
.mate {
  flex: 0 0 auto; width: 66px; border: 2px solid transparent; border-radius: 12px; background: var(--wood-2);
  padding: 4px 3px 3px; display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative;
}
.mate canvas { width: 54px; height: 54px; display: block; }
.mate .m-name { font-size: 11px; font-weight: 700; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mate .m-status { position: absolute; top: 2px; right: 2px; font-size: 14px; }
.mate.off { opacity: .4; }
.mate.pick { border-color: var(--gold); animation: wiggle .8s ease-in-out infinite; }
.mate.pick.bad { border-color: var(--red); }
.mate.pick.shielded { animation: none; opacity: .5; border-color: transparent; }
.mate.flash { animation: flash .6s; }
@keyframes wiggle { 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }
@keyframes flash { 30% { background: var(--gold); } }

/* ---------- Topf ---------- */
.potwrap { flex: 1 1 auto; min-height: 120px; position: relative; display: flex; align-items: center; justify-content: center; }
#g-map { display: block; touch-action: none; }
.potmsg {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none;
  background: rgba(43,29,20,.88); color: var(--parch); padding: 10px 16px; border-radius: 14px; font-weight: 700;
  font-size: 17px; text-align: center; display: none; white-space: nowrap;
}
.potmsg.show { display: block; }
.toasts { position: absolute; left: 0; right: 0; top: 4px; display: flex; flex-direction: column; align-items: center; gap: 4px; pointer-events: none; z-index: 5; }
.toast {
  background: rgba(241,226,192,.96); color: var(--ink); font-size: 13px; font-weight: 600; padding: 6px 12px; border-radius: 10px;
  box-shadow: 0 3px 8px rgba(0,0,0,.35); max-width: 94%; text-align: center; animation: tin .25s ease-out;
}
.toast.bad { background: #f6c9bd; }
.toast.good { background: #f8e3a3; }
.toast.me { outline: 2px solid var(--red); }
.toast.out { opacity: 0; transform: translateY(-6px); transition: all .3s; }
@keyframes tin { from { opacity: 0; transform: translateY(-8px) scale(.95); } }
.toasts-global { position: fixed; top: auto; bottom: calc(var(--safe-b) + 16px); z-index: 50; }

.hint { flex: 0 0 auto; font-size: 13px; color: #e5d4b5; text-align: center; min-height: 18px; line-height: 1.3; padding: 0 4px; }

/* ---------- Hand ---------- */
.hand { flex: 0 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.card {
  position: relative; border: 0; border-radius: 12px; background: var(--parch); color: var(--ink); padding: 5px 2px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 1px; box-shadow: 0 4px 0 #b49a6a; transition: transform .1s;
  height: 96px; overflow: hidden;
}
.card .c-emoji { font-size: 22px; line-height: 1.1; }
.card .c-name { font-size: 11px; font-weight: 700; }
.card svg { width: 40px; height: 40px; flex: 0 0 auto; }
.card.sel { transform: translateY(-6px); box-shadow: 0 4px 0 var(--gold-2), 0 0 0 3px var(--gold); }
.card.wait { opacity: .55; }
.card .c-wait { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(43,29,20,.55); color: #fff; font-weight: 800; font-size: 18px; border-radius: 12px; }
.card .c-grind { position: absolute; top: 3px; right: 5px; font-size: 10px; color: var(--gold-2); letter-spacing: -1px; }

/* ---------- Aktionen ---------- */
.actions { flex: 0 0 auto; display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.act {
  border: 0; border-radius: 12px; background: var(--wood-3); color: var(--cream); padding: 6px 2px; font-size: 12px; font-weight: 700;
  display: flex; flex-direction: column; align-items: center; gap: 1px; box-shadow: 0 4px 0 rgba(0,0,0,.4); min-height: 56px;
}
.act span { font-size: 22px; line-height: 1.1; }
.act b { font-weight: 700; }
.act:active, .act.held { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.4); }
.act:disabled { opacity: .4; }
.act-gold { background: linear-gradient(#f0bd4f, var(--gold)); color: #3a2205; box-shadow: 0 4px 0 var(--gold-2); }
.act-gold.ready { animation: glow 1s ease-in-out infinite; }
.act-gold.idle { filter: saturate(.35) brightness(.8); }
@keyframes glow { 50% { box-shadow: 0 4px 0 var(--gold-2), 0 0 18px 4px rgba(255,210,90,.8); } }
.act-red { background: linear-gradient(#d65a44, var(--red)); box-shadow: 0 4px 0 var(--red-2); }
.act-wide { grid-column: span 2; }
#act-water.held { background: #3f7fbf; }

/* ---------- Sabotage-Sheet ---------- */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--parch); color: var(--ink);
  border-radius: 20px 20px 0 0; padding: 14px 14px calc(var(--safe-b) + 10px); box-shadow: 0 -8px 30px rgba(0,0,0,.5);
  animation: up .2s ease-out;
}
@keyframes up { from { transform: translateY(100%); } }
.sheet-title { font-family: var(--serif); font-weight: 700; font-size: 20px; text-align: center; margin-bottom: 10px; }
.sab-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sab {
  border: 0; border-radius: 12px; background: #fff7e3; color: var(--ink); padding: 10px 8px; text-align: left;
  box-shadow: 0 3px 0 #c9b083; display: flex; flex-direction: column; gap: 2px;
}
.sab .s-emoji { font-size: 24px; }
.sab .s-name { font-weight: 800; font-size: 15px; }
.sab .s-desc { font-size: 12px; color: var(--ink-soft); line-height: 1.25; }
.sheet .btn-ghost { color: var(--ink-soft); margin-top: 6px; }

/* ---------- Abstimmung / Ende ---------- */
.big-emoji { font-size: 68px; text-align: center; line-height: 1.1; }
.vote-wrap h2, .end-wrap h2 { text-align: center; }
.sub { text-align: center; color: #e5d4b5; margin: 0; line-height: 1.4; }
.vote-timer { text-align: center; font-family: var(--serif); font-size: 26px; color: var(--gold); }
.vote-list { display: flex; flex-direction: column; gap: 8px; }
.vote-btn { display: flex; align-items: center; gap: 12px; text-align: left; font-size: 18px; }
.vote-btn.chosen { outline: 3px solid var(--gold); }
.vote-btn .tag { margin-left: auto; font-size: 13px; color: #cdb999; }
.awards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.award { background: var(--parch); color: var(--ink); border-radius: 12px; padding: 8px 10px; text-align: center; }
.award .a-emoji { font-size: 26px; }
.award .a-title { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--ink-soft); }
.award .a-name { font-weight: 800; font-family: var(--serif); font-size: 16px; }
.ranking { width: 100%; border-collapse: collapse; background: var(--wood-2); border-radius: 12px; overflow: hidden; font-size: 14px; }
.ranking th { font-size: 12px; color: #cdb999; padding: 8px 4px; font-weight: 600; }
.ranking td { padding: 8px 4px; text-align: center; border-top: 1px solid var(--wood-3); }
.ranking td:nth-child(2) { text-align: left; font-weight: 700; }
.ranking tr.rat td { background: rgba(200,68,47,.25); }
.end-wrap .btn-big { margin-top: auto; }

/* ---------- Overlay ---------- */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(20,12,7,.82); display: grid; place-items: center; padding: 24px; }
.ov-card { background: var(--parch); color: var(--ink); border-radius: 22px; padding: 22px 20px; text-align: center; max-width: 360px; width: 100%; box-shadow: 0 10px 40px rgba(0,0,0,.6); animation: pop .3s ease-out; }
.ov-card h2 { color: var(--ink); }
.ov-card p { line-height: 1.45; margin: 8px 0; }
.ov-card.rat { background: #3a1d17; color: #ffd9cf; }
.ov-card.rat h2 { color: #ff9b85; }
.ov-count { font-family: var(--serif); font-size: 54px; font-weight: 700; color: var(--gold-2); }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }

.conn-banner { position: fixed; left: 0; right: 0; bottom: 0; z-index: 60; background: var(--red); color: #fff; text-align: center; padding: 10px calc(var(--safe-b) + 10px); font-weight: 700; }

/* Kleine / niedrige Displays */
@media (max-height: 680px) {
  .card { height: 80px; }
  .card svg { width: 30px; height: 30px; }
  .card .c-emoji { font-size: 18px; }
  .act { min-height: 48px; }
  .act span { font-size: 18px; }
  .mate canvas { width: 44px; height: 44px; }
  .mate { width: 56px; }
  .order { padding: 4px 10px; }
  .order .o-emoji { font-size: 22px; }
  .toast { font-size: 12px; padding: 4px 10px; }
}
@media (min-width: 521px) {
  #app { border-left: 1px solid #3a281b; border-right: 1px solid #3a281b; }
}

/* ---------- Nachrichten-Leiste (verdeckt nie den Topf) ---------- */
.feed {
  flex: 0 0 auto; height: 26px; border-radius: 9px; padding: 0 10px; font-size: 13px; font-weight: 600; line-height: 26px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center;
  background: rgba(241,226,192,.12); color: #e5d4b5; transition: background .2s, color .2s;
}
.feed.good { background: #f8e3a3; color: var(--ink); }
.feed.bad { background: #f6c9bd; color: var(--ink); }
.feed.me { box-shadow: inset 0 0 0 2px var(--red); }
.feed.pop { animation: feedpop .25s ease-out; }
@keyframes feedpop { from { transform: scale(.96); opacity: .4; } }

/* ---------- Bestenliste ---------- */
.scores-wrap { display: flex; flex-direction: column; gap: 12px; min-height: 100%; }
.center { text-align: center; }
.small { font-size: 13px; }
.scores-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.scores-list li { display: flex; align-items: center; gap: 10px; background: var(--wood-2); border-radius: 12px; padding: 9px 12px; }
.scores-list .rank { font-family: var(--serif); font-weight: 700; font-size: 18px; min-width: 30px; color: var(--gold); }
.scores-list .who { flex: 1; min-width: 0; }
.scores-list .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scores-list .who small { color: #cdb999; font-size: 12px; }
.scores-list .val { text-align: right; font-weight: 800; font-size: 17px; }
.scores-list .val small { display: block; font-weight: 500; font-size: 11px; color: #cdb999; }
.scores-list .empty { justify-content: center; color: #cdb999; font-style: italic; }
.scores-wrap .btn-gold { margin-top: auto; }
.records { background: linear-gradient(#f8e3a3, #f0c860); color: #3a2205; border-radius: 14px; padding: 10px 12px; text-align: center; font-weight: 700; line-height: 1.5; animation: pop .4s ease-out; }
