:root {
  --felt: #0f3d2e;
  --felt-dark: #0a2a20;
  --felt-light: #165a43;
  --gold: #e3b448;
  --gold-dim: #a8842f;
  --ink: #f4efe2;
  --ink-dim: #b9c6bd;
  --red: #d63b3b;
  --black: #1b1b1b;
  --panel: rgba(0, 0, 0, .28);
  --line: rgba(255, 255, 255, .12);
  --card-w: 64px;
  --card-h: 92px;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Zen Kaku Gothic New", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 50% 40%, var(--felt-light), var(--felt) 55%, var(--felt-dark));
  background-attachment: fixed;
  overflow-x: hidden;
}
.hidden { display: none !important; }
button { font-family: inherit; }

.btn {
  border: 1px solid var(--gold-dim); background: rgba(0,0,0,.35); color: var(--ink);
  padding: 9px 16px; border-radius: 8px; font-weight: 700; cursor: pointer; font-size: 15px;
}
.btn:hover:not(:disabled) { border-color: var(--gold); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--gold); color: #2a1e00; border-color: var(--gold); }
.btn.danger { border-color: #a33; color: #ffb4b4; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.sel { background: var(--gold); color: #2a1e00; }

/* ---------- login / lobby ---------- */
.screen { min-height: 100vh; }
#login, #lobby { display: grid; place-items: center; padding: 16px; }
.login-card, .lobby-card {
  width: min(560px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 28px 24px; text-align: center;
}
.title { font-family: "Shippori Mincho B1", serif; letter-spacing: .18em; font-size: 44px; margin: 0; color: var(--gold); }
.sub { color: var(--ink-dim); margin: 4px 0 22px; }
.hint { color: var(--ink-dim); font-size: 13px; }
.name-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.name-btn { padding: 12px 8px; font-size: 16px; }
.name-btn .st { display: block; font-size: 11px; font-weight: 500; color: var(--ink-dim); margin-top: 2px; }
.name-btn.away { border-color: #3b82f6; }
.pts-plus { color: #7ee2a8; font-weight: 900; }
.pts-minus { color: #ff8b8b; font-weight: 900; }
.score-detail { text-align: left; font-size: 13px; margin: 8px auto; max-width: 520px; }
.score-detail td { padding: 3px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.score-detail .why { color: var(--ink-dim); font-size: 12px; }
input {
  flex: 1; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: rgba(0,0,0,.35); color: var(--ink); font-size: 16px; font-family: inherit;
}
.seat-list { display: grid; gap: 8px; margin: 16px 0; text-align: left; }
.seat { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; background: rgba(0,0,0,.25); }
.seat .num { color: var(--gold); font-weight: 900; width: 1.5em; }
.seat .dot { width: 8px; height: 8px; border-radius: 50%; background: #555; margin-left: auto; }
.seat .dot.on { background: #4cd964; }
.lobby-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
table.stats { width: 100%; border-collapse: collapse; margin-top: 16px; font-size: 14px; }
table.stats th, table.stats td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: center; }
table.stats th { color: var(--ink-dim); font-weight: 500; }

/* ---------- table layout ---------- */
#table { display: grid; grid-template-columns: 1fr 280px; grid-template-rows: auto 1fr; height: 100vh; }
#topbar {
  grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center;
  padding: 8px 16px; background: rgba(0,0,0,.35); border-bottom: 1px solid var(--line); font-size: 14px;
}
#topbar .k { color: var(--ink-dim); margin-right: 4px; }
#topbar .v { font-weight: 900; }
#topbar .grow { flex: 1; }
.suit-S, .suit-C { color: #e8e8e8; }
.suit-H, .suit-D { color: #ff6b6b; }
#board { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; overflow: auto; }
#side { border-left: 1px solid var(--line); background: rgba(0,0,0,.25); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; }
.tab { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--ink-dim); padding: 10px; cursor: pointer; }
.tab.active { color: var(--gold); border-color: var(--gold); }
.tabpane { flex: 1; overflow: auto; padding: 10px; font-size: 13px; line-height: 1.6; min-height: 0; }
#tabChat { display: flex; flex-direction: column; }
#chatList { flex: 1; overflow: auto; }
#chatForm { display: flex; gap: 6px; margin-top: 6px; }
.log-line { border-bottom: 1px dashed var(--line); padding: 2px 0; }

/* ---------- opponents ---------- */
#opponents { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; padding: 12px; }
.pl {
  min-width: 132px; max-width: 200px; padding: 8px 10px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--line); position: relative;
}
.pl.turn { border-color: var(--gold); box-shadow: 0 0 0 2px rgba(227,180,72,.35), 0 0 18px rgba(227,180,72,.35); }
.pl.off { opacity: .55; }
.pl .name { font-weight: 900; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl .meta { font-size: 12px; color: var(--ink-dim); margin-top: 2px; }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 999px; background: #333; color: #fff; font-weight: 700; }
.badge.nap { background: var(--gold); color: #2a1e00; }
.badge.adj { background: #3b82f6; }
.badge.pass { background: #555; }
.badge.dealer { background: transparent; border: 1px solid var(--ink-dim); color: var(--ink-dim); }
.pics { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 5px; }
.mini { font-size: 11px; padding: 0 3px; border-radius: 3px; background: #f8f5ec; font-weight: 900; line-height: 16px; }
.mini.r { color: #c62828; } .mini.b { color: #111; }

/* ---------- trick ---------- */
#center { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 8px; }
#trickArea { display: flex; flex-wrap: wrap; justify-content: center; gap: 12px; min-height: calc(var(--card-h) + 30px); }
.played { display: flex; flex-direction: column; align-items: center; gap: 4px; animation: drop .25s ease-out; }
.played .who { font-size: 12px; color: var(--ink-dim); max-width: 80px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.played.win .card { box-shadow: 0 0 0 3px var(--gold), 0 0 22px var(--gold); }
.played.win .who { color: var(--gold); font-weight: 900; }
@keyframes drop { from { transform: translateY(-14px) scale(1.05); opacity: 0; } }
.trick-msg { color: var(--ink-dim); font-size: 14px; }

#actionArea { width: min(680px, 100%); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; text-align: center; }
.panel h3 { margin: 0 0 8px; font-size: 16px; color: var(--gold); }
.row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; align-items: center; margin: 6px 0; }
.suitbtn { font-size: 22px; width: 52px; padding: 6px 0; }
select { background: rgba(0,0,0,.35); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 8px; font-size: 16px; font-family: inherit; }
.bidlog { font-size: 13px; color: var(--ink-dim); }

/* ---------- my hand ---------- */
#me { padding: 10px 12px 16px; background: linear-gradient(transparent, rgba(0,0,0,.35)); }
.me-head { display: flex; gap: 8px; align-items: center; justify-content: center; margin-bottom: 8px; font-size: 14px; }
.hand { display: flex; justify-content: center; flex-wrap: nowrap; overflow-x: auto; padding: 20px 10px 4px; }
.hand .card { margin-left: calc(var(--card-w) * -0.32); transition: transform .12s; cursor: pointer; }
.hand .card:first-child { margin-left: 0; }
.hand .card.legal:hover, .hand .card.picked { transform: translateY(-14px); }
.hand .card.dim { filter: brightness(.55); cursor: default; }
.hand .card.picked { box-shadow: 0 0 0 3px var(--gold); }
.hand .card.kitty::after { content: "伏"; position: absolute; top: -8px; right: -6px; background: var(--gold); color: #2a1e00; font-size: 10px; font-weight: 900; border-radius: 50%; width: 18px; height: 18px; display: grid; place-items: center; }

/* ---------- cards ---------- */
.card {
  width: var(--card-w); height: var(--card-h); border-radius: 7px; flex: none; position: relative;
  background: #fbf8f0; color: var(--black); box-shadow: 0 2px 6px rgba(0,0,0,.45);
  display: block; user-select: none;
}
.card img { width: 100%; height: 100%; object-fit: contain; border-radius: 7px; display: block; }
.card.img { background: transparent; }
.card .c-tl { position: absolute; top: 4px; left: 5px; font-weight: 900; font-size: 15px; line-height: 1; text-align: center; }
.card .c-mid { position: absolute; inset: 0; display: grid; place-items: center; font-size: 32px; }
.card.red { color: #c62828; }
.card.joker .c-mid { font-size: 13px; font-weight: 900; letter-spacing: .05em; writing-mode: vertical-rl; }
.card.joker { background: linear-gradient(135deg, #fff3c4, #fbf8f0 40%, #d9ecff); }
.card.sm { --card-w: 40px; --card-h: 58px; }
.card.sm .c-tl { font-size: 11px; }
.card.sm .c-mid { font-size: 20px; }
.picker { display: grid; grid-template-columns: repeat(13, 1fr); gap: 4px; margin: 8px 0; }
.picker .card { width: 100%; height: auto; aspect-ratio: 64/92; cursor: pointer; }
.picker .card.picked { box-shadow: 0 0 0 3px var(--gold); transform: scale(1.06); }
.picker .card .c-tl { font-size: 10px; }
.picker .card .c-mid { font-size: 16px; }

/* ---------- result ---------- */
.result-title { font-family: "Shippori Mincho B1", serif; font-size: 28px; color: var(--gold); margin: 4px 0; }

/* ---------- cut-in ---------- */
#cutin { position: fixed; inset: 0; z-index: 50; pointer-events: none; display: grid; place-items: center; background: rgba(0,0,0,.25); }
.cutin-band {
  --c: #d4af37;
  width: 120vw; transform: rotate(-6deg); padding: 18px 0; display: flex; align-items: center; justify-content: center; gap: 26px;
  background: linear-gradient(90deg, transparent, var(--c) 12%, var(--c) 88%, transparent);
  box-shadow: 0 0 40px rgba(0,0,0,.6); position: relative;
  border-top: 3px solid rgba(255,255,255,.75); border-bottom: 3px solid rgba(255,255,255,.75);
}
#cutin.show .cutin-band { animation: band-in .38s cubic-bezier(.2,.9,.3,1.2) both; }
#cutin.out .cutin-band { animation: band-out .3s ease-in both; }
@keyframes band-in { from { transform: rotate(-6deg) translateX(-110%); } to { transform: rotate(-6deg) translateX(0); } }
@keyframes band-out { to { transform: rotate(-6deg) translateX(110%); opacity: .2; } }
.cutin-text {
  font-family: "Shippori Mincho B1", serif; font-size: clamp(34px, 8vw, 84px); color: #fff; font-weight: 800;
  text-shadow: 0 3px 0 rgba(0,0,0,.45), 0 0 18px rgba(0,0,0,.4); letter-spacing: .04em; white-space: nowrap;
}
#cutin.show .cutin-text { animation: pop .5s .15s both; }
@keyframes pop { from { transform: scale(1.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.cutin-img img { max-height: min(34vh, 260px); max-width: 38vw; display: block; filter: drop-shadow(0 6px 10px rgba(0,0,0,.5)); }
.cutin-img .card { --card-w: 90px; --card-h: 130px; }
.cutin-img .card .c-mid { font-size: 46px; }
.cutin-who { position: absolute; bottom: -30px; right: 18%; font-weight: 900; font-size: 18px; color: #fff; text-shadow: 0 2px 4px #000; }

/* ---------- modal / toast ---------- */
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 40; padding: 16px; }
.modal-box { background: var(--felt-dark); border: 1px solid var(--gold-dim); border-radius: 14px; padding: 18px; width: min(420px, 100%); text-align: center; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #7a1f1f; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  :root { --card-w: 52px; --card-h: 75px; }
  #table { grid-template-columns: 1fr; grid-template-rows: auto auto auto; height: auto; }
  #side { border-left: 0; border-top: 1px solid var(--line); height: 260px; }
  .pl { min-width: 104px; padding: 6px 8px; }
  .picker { grid-template-columns: repeat(7, 1fr); }
  .card .c-mid { font-size: 22px; padding-top: 14px; }
  .card .c-tl { font-size: 13px; }
  .hand .card { margin-left: calc(var(--card-w) * -0.42); }
}
#tabScore table.stats { font-size: 12px; margin-top: 0; }
#tabScore table.stats th, #tabScore table.stats td { white-space: nowrap; padding: 5px 2px; }
.badge.cpu { background: #5b6b73; }
.seat .btn.small { margin-left: 4px; }
#keyForm { display: flex; gap: 8px; margin-bottom: 12px; }
#keyForm.hidden { display: none; }
