/* Doppelkopf webapp -- mobile-first, dark felt table. */
:root {
  --felt: #1d5c3a;
  --felt-dark: #14432a;
  --panel: #ffffff;
  --panel-2: #f4f1e8;
  --ink: #22262e;
  --muted: #6b7280;
  --accent: #d9a824;
  --accent-ink: #7a5a08;
  --red: #b3212e;
  --ok: #2e8b57;
  --radius: 14px;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: radial-gradient(circle at 50% 30%, var(--felt), var(--felt-dark));
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button {
  font: inherit; cursor: pointer; border: none; border-radius: 10px;
  padding: 10px 16px; background: var(--panel-2); color: var(--ink);
}
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); color: #fff; font-weight: 600; }
button.danger { background: var(--red); color: #fff; }
button.ghost { background: rgba(255, 255, 255, 0.12); color: #fff; }
input, select {
  font: inherit; padding: 10px 12px; border-radius: 10px;
  border: 1px solid #cbd5e1; width: 100%;
}
section.view { display: none; min-height: 100dvh; }
section.view.active { display: block; }

/* language toggle: one flag, cycles de -> en -> de (user decision
 * 2026-08-06); floats over every view */
:root { --langsz: 42px; }
@media (max-width: 699px) { :root { --langsz: 32px; } }
#langbtn { position: fixed; top: 8px; right: 8px; z-index: 50;
  width: var(--langsz); height: var(--langsz); border-radius: 50%;
  padding: 0; background: rgba(255, 255, 255, 0.85);
  box-shadow: var(--shadow); display: flex; align-items: center;
  justify-content: center; }
#langbtn .flagsvg { width: calc(var(--langsz) * 0.62);
  height: calc(var(--langsz) * 0.41); border-radius: 3px;
  display: block; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.2); }

/* ---------- login ---------- */
#view-login { display: none; align-items: center; justify-content: center; }
#view-login.active { display: flex; }
.auth-card {
  background: var(--panel); border-radius: var(--radius); padding: 28px;
  width: min(92vw, 380px); box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 26px; margin-bottom: 4px; }
.auth-card .sub { color: var(--muted); margin-bottom: 18px; font-size: 14px; }
.auth-card label { display: block; font-size: 13px; color: var(--muted);
  margin: 12px 0 4px; }
.auth-card .actions { margin-top: 20px; display: flex; gap: 10px; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.auth-tabs button { flex: 1; }
.auth-tabs button.on { background: var(--accent); color: #fff; }

/* ---------- lobby & table setup ---------- */
.page { max-width: 760px; margin: 0 auto; padding: 18px 14px 40px; }
.page h1, .page h2 { color: #fff; }
.page h1 { font-size: 24px; margin-bottom: 4px; }
.page .sub { color: rgba(255, 255, 255, 0.75); font-size: 14px;
  margin-bottom: 16px; }
.panel {
  background: var(--panel); border-radius: var(--radius); padding: 16px;
  margin-bottom: 14px; box-shadow: var(--shadow);
}
.panel h3 { font-size: 15px; margin-bottom: 10px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em; }
.rowline { display: flex; align-items: center; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid #eee; }
.rowline:last-child { border-bottom: none; }
.rowline .grow { flex: 1; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok);
  flex: none; }
.seatgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 520px) { .seatgrid { grid-template-columns: 1fr; } }
.seatbox {
  border: 2px dashed #cbd5e1; border-radius: 12px; padding: 12px;
  min-height: 92px; display: flex; flex-direction: column; gap: 6px;
}
.seatbox.filled { border-style: solid; border-color: var(--ok); }
.seatbox .who { font-weight: 600; }
.seatbox .tag { font-size: 12px; color: var(--muted); }
.seatbox .tools { display: flex; gap: 6px; flex-wrap: wrap; }
/* a <select> is as wide as its longest option and a grid/flex child
 * defaults to min-width:auto, so one long engine name used to push the
 * whole seat grid past the viewport (user report 2026-08-07).  These
 * two rules make that impossible regardless of label length. */
.seatbox, .seatgrid > * { min-width: 0; }
.seatbox .tools select { width: auto; max-width: 100%; padding: 6px 8px; }
.seatbox .aiinfo { font-size: 11.5px; color: var(--muted); line-height: 1.3;
  overflow-wrap: anywhere; }
.seatbox .tools button { padding: 6px 10px; font-size: 13px; }
.tablecode { font-size: 30px; letter-spacing: 0.35em; font-weight: 700;
  color: var(--accent); }
.startbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------- game ---------- */
#view-game { position: relative; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 54px 8px 12px;   /* right: keep clear of the flag button */
  color: #fff; font-size: 14px; flex-wrap: wrap;
  background: rgba(0, 0, 0, 0.25);
}
.topbar .contract { font-weight: 700; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 700;
}
.badge.re { background: var(--accent); color: #fff; }
.badge.ko { background: #3b6ea5; color: #fff; }
.badge.unknown { background: rgba(255, 255, 255, 0.25); color: #fff; }
.anncbar { margin-left: auto; font-size: 12px; opacity: 0.9; }

#view-game.active { display: flex; flex-direction: column;
  height: 100dvh; }
.tablearea {
  position: relative; flex: 1 1 auto; min-height: 240px;
  /* space reserved for the fixed hand area; --handh is set by the
   * renderer from card scale and row count */
  margin-bottom: var(--handh, 205px);
}
@media (max-width: 699px) {
  /* short phones: a 240px floor overflows into the reserved hand band
   * (uicheck: pause/game at 375x667) */
  .tablearea { min-height: 140px; }
}
.lasttrick {
  display: flex; gap: 5px; align-items: flex-start; align-self: flex-start;
  margin: 6px 8px 0; min-height: 52px;
  background: rgba(0, 0, 0, 0.28); border-radius: 10px; padding: 5px 8px;
}
.lasttrick .lt-empty { color: rgba(255, 255, 255, 0.55); font-size: 11px;
  align-self: center; }
.lasttrick .lt-label { color: rgba(255, 255, 255, 0.75); font-size: 10px;
  line-height: 1.15; align-self: center; }
.lasttrick .lt-item { display: flex; flex-direction: column;
  align-items: center; width: 34px; }
.lasttrick .cardsvg { width: 30px; display: block; }
.lasttrick .lt-item.win .cardsvg {
  outline: 2px solid var(--accent); border-radius: 3px; }
.lasttrick .lt-name { color: #fff; font-size: 9px; max-width: 34px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lasttrick .lt-item.win .lt-name { color: var(--accent); font-weight: 700; }
.lasttrick .lt-aug { color: var(--accent); font-size: 11px;
  font-weight: 700; align-self: center; line-height: 1.2;
  max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 700px) {
  .lasttrick .cardsvg { width: 40px; }
  .lasttrick .lt-item { width: 46px; }
  .lasttrick .lt-name { font-size: 11px; max-width: 46px; }
}

.opp {
  position: absolute; display: flex; flex-direction: column;
  align-items: center; gap: 3px; color: #fff; font-size: 13px;
  min-width: 84px;
}
.opp.pos1 { left: 6px; top: 38%; transform: translateY(-50%); }
.opp.pos2 { top: 6px; left: 50%; transform: translateX(-50%); }
.opp.pos3 { right: 6px; top: 38%; transform: translateY(-50%); }
.opp .nm { font-weight: 600; max-width: 110px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.opp .cnt { display: flex; align-items: center; gap: 4px; }
.opp .cnt .cardsvg { width: 22px; }
.opp .augen { font-size: 11px; opacity: 0.85; }
.opp.turn .nm { color: var(--accent); text-shadow: 0 0 12px var(--accent); }
.me-info { position: absolute; bottom: 4px; left: 10px; color: #fff;
  font-size: 13px; display: flex; gap: 8px; align-items: center; }
.me-info .nm { font-weight: 700; }
.me-info.turn .nm { color: var(--accent); text-shadow: 0 0 12px var(--accent); }

/* trick size scales with the window (vmin: the table area is usually
 * height-limited on desktops): phones stay at the 86px floor, big
 * screens grow up to 170px per card */
.trick { --tcw: clamp(86px, 13vmin, 170px);
  position: absolute; left: 50%; top: 46%;
  transform: translate(-50%, -50%);
  width: calc(var(--tcw) * 2.44); height: calc(var(--tcw) * 2.44); }
.trick .tcard { position: absolute; width: var(--tcw);
  transition: transform 0.2s ease; }
.trick .tcard.anim { animation: playin 0.22s ease; }
@keyframes playin { from { transform: scale(1.25); opacity: 0.4; } }
.trick .tcard.p0 { left: calc(var(--tcw) * 0.72);
  top: calc(var(--tcw) * 1.12); }
.trick .tcard.p1 { left: calc(var(--tcw) * 0.09);
  top: calc(var(--tcw) * 0.51); transform: rotate(-8deg); }
.trick .tcard.p2 { left: calc(var(--tcw) * 0.72); top: 0; }
.trick .tcard.p3 { left: calc(var(--tcw) * 1.35);
  top: calc(var(--tcw) * 0.51); transform: rotate(8deg); }
.trick .tcard.winner { filter: drop-shadow(0 0 12px var(--accent)); }
/* the completed trick + winner banner IS a popup for its 3 seconds:
 * lift the whole group above buttons and player info.  The banner's
 * own z-index cannot escape .trick (its transform makes a stacking
 * context), so the lift must happen here (D2). */
.trick.frozen { z-index: 35; }
.trick .win-banner { position: absolute; left: 50%; bottom: -40px;
  transform: translateX(-50%); background: var(--accent); color: #fff;
  font-weight: 700; font-size: 14px; white-space: nowrap;
  padding: 6px 14px; border-radius: 999px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.45);
  z-index: 35; }   /* above the floating buttons (z 30) */
.trick .win-banner.anim {
  animation: winpop 0.45s cubic-bezier(0.2, 1.6, 0.4, 1); }
.trick .win-extra { position: absolute; left: 50%; bottom: -72px;
  transform: translateX(-50%); color: #ffd35c; font-size: 12.5px;
  font-weight: 600; text-align: center; white-space: nowrap;
  text-shadow: 0 1px 4px #000; z-index: 35; }
.explaintext { max-height: 60dvh; overflow-y: auto; font-size: 14px; }
.explaintext p { margin-bottom: 10px; line-height: 1.45; }
@keyframes winpop {
  from { transform: translateX(-50%) scale(0.3); opacity: 0; }
}

.handwrap { position: fixed; left: 0; right: 0; bottom: 0;
  padding: 6px 8px 10px; }
.annc-actions { display: flex; gap: 6px; justify-content: center;
  margin-bottom: 6px; flex-wrap: wrap; }
.annc-actions button { padding: 6px 12px; font-size: 13px;
  background: rgba(255, 255, 255, 0.92); }
.hand { display: flex; justify-content: center; align-items: flex-end; }
.hcard { width: 88px; position: relative;
  transition: transform 0.14s ease, filter 0.14s ease; flex: none; }
.hcard .cardsvg { width: 100%; display: block;
  filter: drop-shadow(0 2px 5px rgba(0, 0, 0, 0.45)); }
.hcard.playable { cursor: pointer; }
.hcard.playable:hover, .hcard.playable:focus,
.hcard.kbd { transform: translateY(-16px); outline: none; }
.hcard.dim { transform: translateY(10px); }
.hcard.dim .cardsvg { filter: brightness(0.88); }
.hcard.sel { transform: translateY(-20px); }
.hcard.sel::after { content: "✓"; position: absolute; top: -6px; right: 4px;
  background: var(--accent); color: #fff; border-radius: 50%;
  width: 22px; height: 22px; text-align: center; line-height: 22px;
  font-size: 14px; }
/* Armut exchange bar: one unmissable submit button (feedback 2026-08-06) */
.selbar { display: flex; flex-direction: column; gap: 6px; align-items:
  center; background: rgba(0, 0, 0, 0.55); border: 1px solid var(--accent);
  border-radius: 12px; padding: 10px 12px; margin: 0 auto 8px;
  width: min(100%, 440px); }
.selbar .selinfo { color: #ffd35c; font-size: 13px; font-weight: 600;
  text-align: center; }
.selbar .selgo { width: 100%; padding: 12px 16px; font-size: 16px; }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(10, 24, 16, 0.88);
  display: flex; align-items: center; justify-content: center; z-index: 40;
  padding: 18px;
}
.overlay.light { background: none; pointer-events: none;
  align-items: flex-start; padding-top: 9vh; }
.overlay.light .card-panel { pointer-events: auto;
  box-shadow: 0 10px 44px rgba(0, 0, 0, 0.65); }
.overlay .card-panel {
  background: var(--panel); border-radius: var(--radius); padding: 24px;
  width: min(94vw, 430px); max-height: 88dvh; overflow: auto;
  box-shadow: var(--shadow);
}
.overlay h2 { margin-bottom: 8px; font-size: 20px; }
.overlay .sub { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.choices { display: flex; flex-direction: column; gap: 8px; }
.choices button { text-align: left; padding: 12px 14px; }
/* rules button inside a decision panel: same round shape as the table's
 * floating buttons, sized independently of --fabsz (which only exists
 * while the game screen renders) */
.panel-foot { display: flex; align-items: center; justify-content: flex-end;
  gap: 8px; margin-top: 12px; padding-top: 10px;
  border-top: 1px solid #eee; }
.panel-foot .foot-label { font-size: 12.5px; color: var(--muted); }
.fab.small { width: 40px; height: 40px; font-size: 18px; flex: none;
  background: var(--panel-2); }
.handover { text-align: center; }
.handover .big { font-size: 30px; font-weight: 800; margin: 12px 0 4px; }
.scoretable { width: 100%; border-collapse: collapse; margin: 10px 0; }
.scoretable td, .scoretable th { padding: 6px 8px; text-align: right;
  border-bottom: 1px solid #eee; font-size: 14px; }
.scoretable td:first-child, .scoretable th:first-child { text-align: left; }
.scoretable .plus { color: var(--ok); font-weight: 700; }
.scoretable .minus { color: var(--red); font-weight: 700; }
.sp-list { font-size: 13px; color: var(--muted); margin: 8px 0; }
details.rec { font-size: 11px; color: var(--muted); margin-top: 10px;
  word-break: break-all; }

/* ---------- floating buttons & chat ---------- */
/* 2-column grid: the old single column reached up into the right-hand
 * opponent on phones (feedback 2026-08-06) */
.fabs { position: fixed; right: 10px;
  bottom: calc(var(--handh, 205px) + 13px); z-index: 30;
  display: grid; grid-template-columns: repeat(2, var(--fabsz, 46px));
  gap: 8px; }
.fab { width: var(--fabsz, 46px); height: var(--fabsz, 46px);
  border-radius: 50%; font-size: calc(var(--fabsz, 46px) * 0.43);
  padding: 0; background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow); }
@media (max-width: 699px) {
  /* phones: compact 2x3 grid in the top-left corner, below the topbar
   * -- the emptiest region of the screen (user decision 2026-08-06);
   * the last-trick bar moves right to make room */
  .fabs { grid-template-columns: repeat(2, var(--fabsz, 46px));
    left: 8px; right: auto; bottom: auto;
    top: calc(var(--topbarh, 48px) + 8px); }
  .lasttrick { margin-left: calc(2 * var(--fabsz, 34px) + 24px); }
  /* left opponent drops below the button grid */
  .opp.pos1 { top: 56%; }
  .opp.pos3 { top: 42%; }
}
.chatlog { max-height: 46dvh; overflow-y: auto; display: flex;
  flex-direction: column; gap: 8px; }
.chatlog.pausechat { max-height: 26dvh; text-align: left;
  border: 1px solid #e5e1d4; border-radius: 10px; padding: 8px; }
.chatmsg { background: var(--panel-2); border-radius: 10px;
  padding: 8px 10px; font-size: 14px; display: flex;
  flex-direction: column; gap: 2px; max-width: 90%;
  align-self: flex-start; }
.chatmsg.mine { align-self: flex-end; background: #e3edd9; }
.chatmsg .who { font-size: 11px; color: var(--muted); }

/* ---------- toasts ---------- */
#toasts { position: fixed; top: 10px; left: 50%; transform: translateX(-50%);
  z-index: 60; display: flex; flex-direction: column; gap: 8px;
  width: min(94vw, 420px); }
.toast { background: var(--panel); border-radius: 10px; padding: 12px 14px;
  box-shadow: var(--shadow); display: flex; gap: 10px; align-items: center;
  animation: playin 0.2s ease; font-size: 14px; }
.toast.err { background: #fde8e8; color: #8a1c1c; }
.toast .grow { flex: 1; }
#connbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 70;
  background: var(--red); color: #fff; text-align: center; padding: 6px;
  font-size: 13px; display: none; }
