/* =====================================================================
   Durak – Übergabe-Variante
   Gestaltung: klassischer, edler Kartentisch. Dunkelgrüner Filz
   (radialer Verlauf), Holzrand, gedämpftes Gold als Akzent,
   Serifen-Überschriften. Responsiv und touch-tauglich.
   ===================================================================== */

:root {
  --felt-1: #0e4429;
  --felt-2: #062d1c;
  --bg: #04120c;
  --wood: #4a2f16;
  --wood-hi: #6b4a26;
  --gold: #c8a44d;
  --gold-soft: #a98c45;
  --ink: #efe9da;
  --ink-dim: #b9c9be;
  --red: #b3202c;
  --panel: rgba(4, 24, 15, .82);
  --card-w: clamp(56px, 12vw, 88px);
  --radius: 12px;
  --serif: Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-family: var(--serif); font-weight: 700; letter-spacing: .02em; }
button { font: inherit; cursor: pointer; }

.screen { min-height: 100dvh; }
[hidden] { display: none !important; }

/* ------------------------------ Buttons ----------------------------- */

.btn {
  border: 1px solid var(--gold-soft);
  background: linear-gradient(180deg, #123c28, #0b2b1c);
  color: var(--ink);
  padding: .65rem 1.1rem;
  border-radius: 10px;
  transition: transform .08s ease, box-shadow .15s ease, background .15s ease;
  min-height: 44px; /* Touch-Ziel */
}
.btn:hover { box-shadow: 0 0 0 2px rgba(200, 164, 77, .25); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-gold {
  background: linear-gradient(180deg, #d8b45e, #a9822f);
  color: #241a05;
  border-color: #e6cd8a;
  font-weight: 600;
}
.btn-ghost { background: transparent; border-color: rgba(200,164,77,.4); }
.btn-small { padding: .35rem .7rem; min-height: 36px; font-size: .9rem; }

.error { color: #ff9d9d; }
.hint { color: var(--ink-dim); font-size: .9rem; margin: .3rem 0; }

/* ------------------------------- Start ------------------------------ */

#screen-start {
  display: grid;
  place-items: center;
  background: radial-gradient(120% 90% at 50% 20%, var(--felt-1), var(--felt-2) 70%, var(--bg));
  padding: 1rem;
}
.start-card {
  width: min(420px, 94vw);
  background: var(--panel);
  border: 1px solid rgba(200, 164, 77, .35);
  border-radius: 16px;
  padding: 1.6rem 1.4rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
  display: flex;
  flex-direction: column;
  gap: .8rem;
}
.brand { margin: 0; font-size: 3rem; text-align: center; color: var(--gold); }
.brand-sub { margin: -0.6rem 0 .6rem; text-align: center; color: var(--ink-dim); font-style: italic; }
.field { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; color: var(--ink-dim); }
.field input {
  padding: .7rem .8rem;
  border-radius: 10px;
  border: 1px solid rgba(200,164,77,.4);
  background: #08170f;
  color: var(--ink);
  font-size: 1rem;
}
.field input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.divider {
  display: flex; align-items: center; gap: .6rem;
  color: var(--ink-dim); font-size: .85rem;
}
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: rgba(200,164,77,.3); }

/* ------------------------------- Lobby ------------------------------ */

#screen-lobby {
  background: radial-gradient(120% 90% at 50% 15%, var(--felt-1), var(--felt-2) 70%, var(--bg));
  display: grid;
  place-items: start center;
  padding: 1rem;
}
.lobby-wrap {
  width: min(560px, 96vw);
  display: flex; flex-direction: column; gap: 1rem;
  margin-top: 2vh;
}
.lobby-head { display: flex; align-items: center; justify-content: space-between; }
.lobby-head h2 { margin: 0; color: var(--gold); font-size: 2rem; }
.code-chip {
  background: var(--panel);
  border: 1px solid rgba(200,164,77,.45);
  border-radius: 10px;
  color: var(--ink);
  padding: .5rem .8rem;
  letter-spacing: .08em;
}
.code-chip strong { color: var(--gold); }
.code-chip.small { padding: .25rem .55rem; font-size: .85rem; }

.player-list {
  list-style: none; margin: 0; padding: .4rem;
  background: var(--panel);
  border: 1px solid rgba(200,164,77,.3);
  border-radius: var(--radius);
}
.player-row {
  display: flex; align-items: center; gap: .6rem;
  padding: .55rem .6rem;
  border-bottom: 1px solid rgba(200,164,77,.12);
}
.player-row:last-child { border-bottom: none; }
.player-row.offline { opacity: .55; }
.p-name { font-weight: 600; }
.p-losses { margin-left: auto; color: var(--ink-dim); font-size: .85rem; }
.crown { min-width: 1.2em; }
.conn-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #8a3b3b; box-shadow: 0 0 4px rgba(0,0,0,.6);
  flex: none;
}
.conn-dot.on { background: #4dbb6b; box-shadow: 0 0 6px rgba(77,187,107,.8); }

.lobby-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .7rem; }

/* -------------------------------- Chat ------------------------------ */

.chat {
  background: var(--panel);
  border: 1px solid rgba(200,164,77,.3);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  position: relative;
}
.chat-log {
  height: 180px; overflow-y: auto;
  padding: .6rem .7rem;
  font-size: .92rem;
  display: flex; flex-direction: column; gap: .25rem;
}
.chat-row strong { color: var(--gold); }
.chat-row.system { color: var(--ink-dim); font-style: italic; font-size: .85rem; }
.chat-time { color: var(--ink-dim); font-size: .72rem; margin-left: .4rem; }
.chat-input {
  display: flex; gap: .4rem; align-items: center;
  padding: .5rem;
  border-top: 1px solid rgba(200,164,77,.2);
}
.chat-input input {
  flex: 1; min-width: 0;
  padding: .55rem .7rem;
  border-radius: 8px;
  border: 1px solid rgba(200,164,77,.35);
  background: #08170f; color: var(--ink);
}
.emoji-btn { background: none; border: none; font-size: 1.25rem; padding: .2rem; }
.emoji-panel {
  position: absolute; bottom: 3.4rem; left: .5rem;
  background: #0a1f14;
  border: 1px solid rgba(200,164,77,.45);
  border-radius: 10px;
  padding: .4rem;
  display: grid; grid-template-columns: repeat(6, 1fr); gap: .15rem;
  z-index: 30;
  box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.emoji-panel button { background: none; border: none; font-size: 1.3rem; padding: .25rem; border-radius: 6px; }
.emoji-panel button:hover { background: rgba(200,164,77,.2); }

/* ------------------------------- Spiel ------------------------------ */

#screen-game {
  display: flex; flex-direction: column;
  height: 100dvh;
  background: var(--bg);
}
.game-top {
  display: flex; align-items: center; gap: .6rem;
  padding: .45rem .7rem;
  background: #071710;
  border-bottom: 1px solid rgba(200,164,77,.25);
  flex-wrap: wrap;
}
.game-top .spacer { flex: 1; }
.trump-badge {
  border: 1px solid rgba(200,164,77,.5);
  border-radius: 8px;
  padding: .2rem .55rem;
  font-size: .9rem;
  background: #0a1f14;
}
.trump-badge.red { color: #ff8f97; }
.trump-badge.black { color: var(--ink); }
.deck-info { color: var(--ink-dim); font-size: .85rem; }

/* Filz-Tisch mit Holzrand */
.felt {
  flex: 1;
  display: flex; flex-direction: column;
  gap: .4rem;
  padding: .7rem;
  margin: .5rem;
  border-radius: 22px;
  border: 10px solid var(--wood);
  outline: 2px solid var(--gold-soft);
  outline-offset: -8px;
  background:
    radial-gradient(120% 100% at 50% 30%, var(--felt-1), var(--felt-2) 75%);
  box-shadow: inset 0 0 60px rgba(0,0,0,.55), 0 12px 40px rgba(0,0,0,.5);
  overflow: hidden;
  min-height: 0;
}

/* Gegner */
.opponents {
  display: flex; justify-content: center; gap: .6rem;
  flex-wrap: wrap;
}
.opp {
  background: rgba(0,0,0,.28);
  border: 1px solid rgba(200,164,77,.25);
  border-radius: 12px;
  padding: .35rem .55rem;
  min-width: 108px;
  transition: box-shadow .2s ease, border-color .2s ease;
}
.opp.is-def { border-color: #6ea8ff; box-shadow: 0 0 12px rgba(110,168,255,.35); }
.opp.is-atk { border-color: #ff9c6e; box-shadow: 0 0 12px rgba(255,156,110,.3); }
.opp.finished, .opp.removed { opacity: .55; }
.opp-head { display: flex; align-items: center; gap: .35rem; }
.opp-name { font-weight: 600; font-size: .92rem; overflow: hidden; text-overflow: ellipsis; max-width: 14ch; }
.opp-badges { min-height: 1.2rem; margin: .15rem 0; }
.badge {
  font-size: .72rem; padding: .1rem .4rem; border-radius: 6px;
  background: rgba(0,0,0,.4); border: 1px solid rgba(255,255,255,.15);
}
.badge.atk { color: #ffb27d; border-color: rgba(255,156,110,.5); }
.badge.def { color: #9cc2ff; border-color: rgba(110,168,255,.5); }
.badge.fin { color: #9fe0ad; }
.badge.gone { color: #d0a0a0; }
.opp-cards { display: flex; align-items: center; position: relative; height: 40px; }
.opp-cards .card.mini { width: 26px; margin-left: -14px; }
.opp-cards .card.mini:first-child { margin-left: 0; }
.opp-count {
  margin-left: .45rem; font-weight: 700; color: var(--gold);
  font-size: .95rem;
}

/* Spielfeldmitte */
.board {
  flex: 1;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: .5rem;
  min-height: 0;
}
.pile-area { display: flex; flex-direction: column; align-items: center; gap: .3rem; }
.pile-label { font-size: .78rem; color: var(--ink-dim); }

.stock { position: relative; width: var(--card-w); height: calc(var(--card-w) * 1.4); }
.stock .trump-under {
  position: absolute; left: 55%; top: 20%;
  transform: rotate(90deg);
}
.stock .stock-top { position: absolute; left: 0; top: 0; }

.discard { position: relative; width: var(--card-w); height: calc(var(--card-w) * 1.4); }
.discard .discard-c { position: absolute; left: 0; top: 0; }
.discard .d1 { transform: rotate(-7deg) translate(3px, 2px); }
.discard .d2 { transform: rotate(6deg) translate(-2px, 4px); }

.center-area {
  display: flex; flex-direction: column; align-items: center; gap: .35rem;
  min-height: 0;
}
.direction-ind {
  width: 34px; height: 34px; color: var(--gold);
  opacity: .9;
  transition: transform .3s ease;
}
.direction-ind.ccw { transform: scaleX(-1); }
.table-cards {
  display: flex; flex-wrap: wrap; justify-content: center;
  gap: .6rem;
  min-height: calc(var(--card-w) * 1.55);
}
.pair { position: relative; width: var(--card-w); height: calc(var(--card-w) * 1.55); }
.pair .atk-card { position: absolute; left: 0; top: 0; }
.pair .def-card {
  position: absolute; left: 18%; top: 14%;
  transform: rotate(8deg);
  filter: drop-shadow(-3px 3px 5px rgba(0,0,0,.5));
}
.pair.targetable .atk-card { animation: pulse 1.1s ease-in-out infinite; cursor: pointer; }
@keyframes pulse {
  0%, 100% { filter: drop-shadow(0 0 3px rgba(200,164,77,.4)); }
  50% { filter: drop-shadow(0 0 12px rgba(200,164,77,.95)); }
}
.table-hint { font-size: .85rem; color: var(--ink-dim); min-height: 1.2rem; text-align: center; }

/* Bestätigungs- und Aktionsleisten */
.confirm-bar, .action-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
  gap: .5rem;
  min-height: 2.2rem;
}
.confirm-bar {
  background: rgba(0,0,0,.35);
  border: 1px solid rgba(200,164,77,.4);
  border-radius: 10px;
  padding: .4rem .6rem;
  font-size: .9rem;
}
.confirm-timer { color: var(--gold); min-width: 3ch; text-align: center; }
.confirm-waiting { color: var(--ink-dim); font-size: .82rem; }
.bar-note { color: var(--ink-dim); font-size: .82rem; }

/* Eigene Hand: aufgefächert */
.me-area { display: flex; flex-direction: column; align-items: center; gap: .25rem; }
.me-badges { display: flex; align-items: center; gap: .45rem; font-size: .95rem; min-height: 1.4rem; }
.me-name { font-weight: 700; color: var(--gold); }
.hand {
  display: flex; justify-content: center; align-items: flex-end;
  padding: .3rem .5rem .5rem;
  max-width: 100%;
  overflow-x: auto;
}
.card {
  width: var(--card-w);
  flex: none;
  transition: transform .15s ease, filter .15s ease, margin .15s ease;
  filter: drop-shadow(0 4px 8px rgba(0,0,0,.45));
  user-select: none;
}
.card svg { display: block; width: 100%; height: auto; }
.hand .card { margin-left: calc(var(--card-w) * -0.42); }
.hand .card:first-child { margin-left: 0; }
.hand .card.playable { cursor: pointer; }
.hand .card.playable:hover { transform: translateY(-8px); }
.hand .card.selected {
  transform: translateY(-16px);
  filter: drop-shadow(0 0 10px rgba(200,164,77,.9));
  z-index: 2;
}
.hand .card:not(.playable) { opacity: .82; }

/* Chat-Schublade im Spiel */
.game-chat {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: min(340px, 92vw);
  background: #06130c;
  border-left: 1px solid rgba(200,164,77,.4);
  display: flex; flex-direction: column;
  z-index: 40;
  box-shadow: -12px 0 30px rgba(0,0,0,.5);
}
.game-chat header {
  display: flex; justify-content: space-between; align-items: center;
  padding: .5rem .7rem;
  border-bottom: 1px solid rgba(200,164,77,.25);
  font-family: var(--serif);
}
.game-chat .chat-log { flex: 1; height: auto; }
.game-chat .emoji-panel { bottom: 4rem; }

/* Overlays */
.overlay {
  position: fixed; inset: 0;
  background: rgba(2, 10, 6, .78);
  display: grid; place-items: center;
  z-index: 50;
  backdrop-filter: blur(3px);
}
.overlay-card {
  width: min(440px, 92vw);
  background: var(--panel);
  border: 1px solid rgba(200,164,77,.5);
  border-radius: 16px;
  padding: 1.3rem 1.4rem;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
}
.overlay-card h3 { margin: 0 0 .7rem; color: var(--gold); font-size: 1.5rem; }
.overlay-actions { display: flex; justify-content: center; gap: .7rem; margin-top: .9rem; flex-wrap: wrap; }
.ranking { text-align: left; margin: .6rem auto; max-width: 260px; padding-left: 1.4rem; }
.ranking .durak { color: #ff9d9d; font-weight: 700; }
.rematch-status { color: var(--ink-dim); font-size: .88rem; display: flex; flex-direction: column; gap: .15rem; }

/* Toasts */
.toasts {
  position: fixed; left: 50%; bottom: 1rem; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: .4rem;
  z-index: 60;
  width: min(420px, 92vw);
}
.toast {
  background: #3a1518; color: #ffd9d9;
  border: 1px solid #7a2a30;
  border-radius: 10px;
  padding: .6rem .8rem;
  opacity: 0; transform: translateY(8px);
  transition: opacity .25s ease, transform .25s ease;
  text-align: center;
}
.toast.info { background: #10281a; color: var(--ink); border-color: rgba(200,164,77,.5); }
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------------------------- Responsiv ----------------------------- */

@media (max-width: 640px) {
  :root { --card-w: clamp(52px, 14vw, 72px); }
  .felt { margin: .3rem; padding: .45rem; border-width: 7px; border-radius: 16px; }
  .board { grid-template-columns: auto 1fr auto; gap: .25rem; }
  .opp { min-width: 88px; padding: .25rem .4rem; }
  .opp-cards { height: 32px; }
  .opp-cards .card.mini { width: 20px; margin-left: -11px; }
  .game-top { font-size: .9rem; }
  .chat-log { height: 140px; }
}

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