:root {
  --felt: #0b3d2e;
  --felt-light: #14513d;
  --ink: #f2efe6;
  --dim: #9db8ad;
  --t0: #4da3ff;
  --t1: #ffb14d;
  --card-w: 52px;
  --card-h: 74px;
  --accent: #ffd866;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100dvh;
  overflow: hidden;
  background: radial-gradient(ellipse at 50% 35%, var(--felt-light), var(--felt) 75%);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  touch-action: manipulation;
  user-select: none; -webkit-user-select: none;
}

body { display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 6px) 10px 6px;
  font-size: 12px;
}
#match-score { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; }
.team-label { font-weight: 600; white-space: nowrap; }
.team-label.t0 { color: var(--t0); }
.team-label.t1 { color: var(--t1); }
.vs { color: var(--dim); }
.dots { letter-spacing: 2px; font-size: 13px; }
#round-label { color: var(--dim); font-weight: 700; min-width: 26px; text-align: right; }
.icon-btn {
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.3); background: rgba(255,255,255,.08);
  color: var(--ink); font-weight: 700; font-size: 14px;
}
.icon-btn.lang { font-size: 15px; line-height: 1; }

/* ---------- layout ---------- */
#game { position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0; }

.opp { position: absolute; display: flex; flex-direction: column; align-items: center; gap: 3px; z-index: 2; }
.opp-top { top: 4px; left: 50%; transform: translateX(-50%); }
.opp-left { top: 28%; left: 6px; }
.opp-right { top: 28%; right: 6px; }

.badge {
  display: flex; align-items: center; gap: 5px;
  background: rgba(0,0,0,.30); border-radius: 14px;
  padding: 3px 10px; font-size: 12px; font-weight: 600;
  border: 2px solid transparent;
  transition: border-color .2s, box-shadow .2s;
}
.badge .cnt {
  background: rgba(255,255,255,.15); border-radius: 9px;
  padding: 0 6px; font-size: 11px;
}
.badge.team0 { box-shadow: inset 0 -2px 0 var(--t0); }
.badge.team1 { box-shadow: inset 0 -2px 0 var(--t1); }
.badge.turn { border-color: var(--accent); box-shadow: 0 0 10px rgba(255,216,102,.55); }
.badge .tag { font-size: 10px; color: var(--dim); font-weight: 700; }
.badge .medal { font-size: 13px; }

.minifan { display: flex; height: 18px; }
.minifan .back {
  width: 12px; height: 17px; border-radius: 2px;
  background: linear-gradient(135deg, #7a2c3c, #4d1b27);
  border: 1px solid rgba(255,255,255,.35);
  margin-left: -7px;
}
.minifan .back:first-child { margin-left: 0; }

/* ---------- table ---------- */
#table-area {
  position: absolute; inset: 18% 15% 38% 15%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px;
}
.play-row { display: flex; justify-content: center; min-height: 8px; }
.play-row.faded { opacity: .28; transform: scale(.72); min-height: 0; }
#table-info { font-size: 12px; color: var(--dim); text-align: center; min-height: 16px; }
#table-info b { color: var(--ink); }

#log-line {
  position: absolute; left: 0; right: 0; bottom: 36%;
  text-align: center; font-size: 13px; font-weight: 600;
  color: var(--accent); text-shadow: 0 1px 3px rgba(0,0,0,.6);
  pointer-events: none; z-index: 3;
}

/* ---------- cards ---------- */
.card {
  width: var(--card-w); height: var(--card-h);
  background: #fdfbf4; border-radius: 6px;
  border: 1px solid #b9b2a0;
  box-shadow: 0 2px 5px rgba(0,0,0,.35);
  position: relative; flex-shrink: 0;
  color: #1c1c1c;
  transition: transform .12s;
}
.card.red { color: #c0392b; }
.card .tl {
  position: absolute; top: 3px; left: 5px;
  font-size: 14px; font-weight: 800; line-height: 1;
  text-align: center;
}
.card .tl span { display: block; font-size: 12px; }
.card .ctr {
  position: absolute; bottom: 4px; right: 6px;
  font-size: 22px; line-height: 1;
}
.play-row .card { margin-left: -18px; }
.play-row .card:first-child { margin-left: 0; }

/* ---------- you ---------- */
#you-area {
  margin-top: auto; z-index: 4;
  padding: 0 6px calc(env(safe-area-inset-bottom) + 8px);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
#you-badge { display: flex; }
#hand {
  display: flex; flex-wrap: wrap; justify-content: center;
  max-width: 560px; row-gap: 6px; padding-top: 14px;
}
#hand .card { margin-left: -22px; }
#hand .card:first-child { margin-left: 0; }
#hand .card.sel { transform: translateY(-14px); box-shadow: 0 6px 12px rgba(0,0,0,.45), 0 0 0 2px var(--accent); }
#hand .card.dim-card { filter: brightness(.75); }

#controls { display: flex; gap: 10px; width: 100%; max-width: 420px; }
.ctl {
  flex: 1; padding: 12px 10px; border-radius: 12px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.10); color: var(--ink);
  font-size: 15px; font-weight: 700;
}
.ctl.primary { background: var(--accent); border-color: var(--accent); color: #3a2c00; }
.ctl.ghost { background: transparent; }
.ctl:disabled { opacity: .35; }
.ctl.big { flex: none; width: 100%; margin-top: 10px; }

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.55); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center;
  padding: 16px;
}
.modal.show { display: flex; }
.sheet {
  background: #103a2d; border: 1px solid rgba(255,255,255,.18);
  border-radius: 18px; padding: 22px;
  width: 100%; max-width: 440px;
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
  text-align: center;
}
.sheet.scroll { max-height: 86dvh; overflow-y: auto; text-align: left; }
.sheet h1 { margin: 0 0 6px; font-size: 30px; }
.sheet h2 { margin: 0 0 10px; }
.sheet h3 { margin: 16px 0 4px; color: var(--accent); font-size: 14px; text-transform: uppercase; letter-spacing: .5px; }
.sheet p, .sheet li { font-size: 14px; line-height: 1.5; margin: 4px 0; }
.sheet .sub { color: var(--dim); }
.sheet .order { font-size: 16px; letter-spacing: 1px; }
.sheet ul { padding-left: 18px; margin: 4px 0; }

#round-results, #match-results { margin: 12px 0; }
.res-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 12px; border-radius: 10px; margin: 4px 0;
  background: rgba(255,255,255,.07); font-size: 14px; font-weight: 600;
}
.res-row .pts { color: var(--dim); }
.res-team { font-size: 15px; font-weight: 800; margin-top: 10px; }

@media (min-width: 700px) {
  :root { --card-w: 64px; --card-h: 92px; }
  #topbar { font-size: 14px; }
  .badge { font-size: 14px; }
}
