:root {
  --tw: clamp(34px, 4.4vw, 54px);
  --gold: #e2c17a;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: 'Cormorant Garamond', Georgia, serif;
  color: #f4ead2;
  background: radial-gradient(ellipse at 50% 0%, #2b2a33 0%, #121116 70%, #08070a 100%);
  display: flex; flex-direction: column; min-height: 100vh; overflow-x: hidden;
}
button, select { font: inherit; }

header.top { display: flex; justify-content: space-between; align-items: center; padding: 10px 18px; gap: 12px; flex-wrap: wrap; }
.brand { font-size: 26px; letter-spacing: .18em; text-transform: uppercase; color: var(--gold); text-shadow: 0 2px 6px rgba(0,0,0,.6); font-weight: 700; }
.tools { display: flex; gap: 8px; align-items: center; }
.btn {
  background: linear-gradient(#3a3d45, #23252b); color: #f4ead2;
  border: 1px solid rgba(226,193,122,.45); border-radius: 999px; padding: 7px 16px; cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.12);
  font-size: 17px; font-weight: 600; letter-spacing: .03em;
  transition: transform .15s, border-color .2s, opacity .2s;
}
.btn:hover { border-color: var(--gold); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(#f0d48f, #b8924a); color: #2a1d07; border-color: #f6e2a8; font-weight: 700; }
.btn.dim { opacity: .4; }
select.lang { background: #23252b; color: #f4ead2; border: 1px solid rgba(226,193,122,.45); border-radius: 999px; padding: 6px 10px; }

/* ---------- table ---------- */
.table {
  margin: 0 14px; flex: 1; position: relative;
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(0, 3fr) minmax(150px, 1fr);
  grid-template-rows: auto 1fr; gap: 12px; padding: 22px 24px; min-height: 48vh;
  border-radius: 28px;
  background:
    radial-gradient(ellipse at 50% 40%, #2c8061 0%, #17553f 55%, #0b2e22 100%);
  box-shadow:
    inset 0 0 0 10px #4a2e18, inset 0 0 0 12px #b58a4c,
    inset 0 0 70px rgba(0,0,0,.6), 0 30px 60px rgba(0,0,0,.6);
}
.table::before {
  content: ""; position: absolute; inset: 12px; border-radius: 20px; pointer-events: none;
  background-image: radial-gradient(rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 3px 3px;
}
.seat-top { grid-column: 2; grid-row: 1; justify-self: center; }
.seat-left { grid-column: 1; grid-row: 2; align-self: center; }
.seat-right { grid-column: 3; grid-row: 2; align-self: center; }
.seat { display: flex; flex-direction: column; align-items: center; gap: 8px; position: relative; }
.center { grid-column: 2; grid-row: 2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; position: relative; }

.nameplate { display: flex; align-items: center; gap: 10px; padding: 4px 10px 4px 6px; border-radius: 14px; }
.nameplate.active { background: rgba(0,0,0,.22); box-shadow: 0 0 0 1px rgba(226,193,122,.55), 0 0 22px rgba(226,193,122,.25); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  font-size: 20px; font-weight: 700; color: #2a1d07;
  background: radial-gradient(circle at 35% 30%, #fff3c8, #d8ad58 55%, #8a6626);
  box-shadow: 0 3px 8px rgba(0,0,0,.5), inset 0 -3px 6px rgba(0,0,0,.25);
}
.pname { font-size: 19px; font-weight: 700; line-height: 1.1; }
.pscore { font-size: 15px; opacity: .75; }
.fanrow { display: flex; align-items: center; gap: 10px; }
.fan { position: relative; width: 112px; height: 34px; }
.mini {
  position: absolute; top: 0; width: 24px; height: 32px; border-radius: 4px;
  background: linear-gradient(#2f7a60, #1a4a3a);
  box-shadow: 0 0 0 1px rgba(0,0,0,.45), 0 3px 4px rgba(0,0,0,.45), inset 0 0 0 2px rgba(226,193,122,.5);
}
.count {
  min-width: 28px; height: 28px; padding: 0 6px; border-radius: 14px; display: grid; place-items: center;
  background: #0f2a20; border: 1px solid var(--gold); color: var(--gold); font-weight: 700; font-size: 16px;
  box-shadow: 0 2px 5px rgba(0,0,0,.5);
}

.melds { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; min-height: 44px; max-width: 920px; }
.meld {
  display: flex; gap: 3px; padding: 6px 7px; border-radius: 12px;
  background: rgba(0,0,0,.22);
  box-shadow: inset 0 2px 8px rgba(0,0,0,.4), 0 1px 0 rgba(255,255,255,.08);
  transition: box-shadow .2s, background .2s;
}
.meld.target { cursor: pointer; box-shadow: 0 0 0 2px var(--gold), inset 0 2px 8px rgba(0,0,0,.4); }
.meld.target:hover { background: rgba(226,193,122,.2); }
.meld .tile { --tw: 32px; }

.midrow { display: flex; align-items: center; gap: 26px; margin-top: 4px; }
.pile { position: relative; width: var(--tw); height: calc(var(--tw) * 1.32); }
.pile .tile { position: absolute; left: 0; top: 0; }
.pile .label {
  position: absolute; left: 50%; top: calc(100% + 8px); transform: translateX(-50%); white-space: nowrap;
  font-size: 15px; letter-spacing: .12em; text-transform: uppercase; color: rgba(244,234,210,.85); text-shadow: 0 1px 2px #000;
}
.status {
  min-width: 240px; max-width: 360px; min-height: 24px; font-size: 18px; font-style: italic; text-align: left;
  color: rgba(244,234,210,.95); text-shadow: 0 1px 3px rgba(0,0,0,.7);
}

/* ---------- tiles ---------- */
.tile {
  position: relative; width: var(--tw); height: calc(var(--tw) * 1.32);
  border-radius: calc(var(--tw) * 0.13); container-type: inline-size;
  display: flex; align-items: center; justify-content: center; flex: none; user-select: none;
  background: linear-gradient(160deg, #fffdf6 0%, #f6efdc 60%, #e9dfc6 100%);
  box-shadow:
    inset 0 2px 1px rgba(255,255,255,.95),
    inset 0 -4px 6px rgba(120,95,50,.22),
    inset 3px 0 4px rgba(255,255,255,.5),
    inset -3px 0 4px rgba(120,95,50,.12),
    0 0 0 1px rgba(70,50,20,.35),
    0 2px 0 #cdbf9c,
    0 3px 0 #b5a77f,
    0 4px 0 #9d8f69,
    0 9px 14px rgba(0,0,0,.45);
  transition: transform .25s cubic-bezier(.2,.8,.2,1), box-shadow .25s;
}
.tile::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  background: linear-gradient(115deg, rgba(255,255,255,.6) 0%, rgba(255,255,255,0) 40%, rgba(255,255,255,0) 72%, rgba(0,0,0,.08) 100%);
}
.tile .num {
  font-family: 'Trebuchet MS', Helvetica, Arial, sans-serif; font-weight: 800; font-size: 56cqw; line-height: 1;
  text-shadow: 0 1px 0 rgba(255,255,255,.7), 0 -1px 0 rgba(0,0,0,.08);
}
.c-k .num { color: #1e1e24; }
.c-b .num { color: #1c5fc2; }
.c-r .num { color: #c3262d; }
.c-o .num { color: #e0791a; }
.tile .joker {
  font-size: 62cqw; line-height: 1;
  background: linear-gradient(135deg, #e43d3d, #f2a33a 25%, #e9d847 45%, #3fc07a 65%, #3a8ee6 85%, #9b5de5);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 1px 0 rgba(0,0,0,.2));
}
.tile.back {
  background: radial-gradient(ellipse at 30% 25%, #2f7a60, #1a4a3a 70%);
}
.tile.back::before {
  content: ""; position: absolute; inset: 9%; border-radius: calc(var(--tw) * 0.09);
  border: 1.5px solid rgba(226,193,122,.6);
  background: repeating-linear-gradient(45deg, rgba(226,193,122,.14) 0 1.5px, transparent 1.5px 6px);
}
.tile.enter { animation: enter .4s cubic-bezier(.2,.8,.2,1) backwards; }
@keyframes enter { from { opacity: 0; transform: translateY(-14px) scale(.9); } to { opacity: 1; transform: none; } }

/* ---------- rack ---------- */
.me-area { padding: 6px 14px 18px; }
.me-bar { display: flex; justify-content: space-between; align-items: center; max-width: 1200px; margin: 0 auto 10px; gap: 12px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.rack {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 5px;
  max-width: 1200px; margin: 0 auto; padding: 14px 18px 12px; border-radius: 14px;
  background: linear-gradient(#c59563, #94643a 60%, #7a4e2b);
  box-shadow: inset 0 3px 0 rgba(255,235,200,.35), inset 0 -8px 14px rgba(0,0,0,.35), 0 14px 26px rgba(0,0,0,.55);
  min-height: calc(var(--tw) * 1.32 + 30px);
}
.rack .tile { cursor: pointer; }
.rack .tile:hover { transform: translateY(-4px); }
.rack .tile.sel {
  transform: translateY(-14px);
  box-shadow: 0 0 0 2px var(--gold), 0 0 16px rgba(226,193,122,.7), 0 8px 16px rgba(0,0,0,.5);
}

/* ---------- modals ---------- */
.modal {
  position: fixed; inset: 0; display: none; place-items: center; padding: 16px; z-index: 50;
  background: rgba(4,8,6,.66); backdrop-filter: blur(5px);
}
.modal.open { display: grid; }
.sheet {
  width: min(620px, 100%); max-height: 84vh; overflow: auto; color: #2a2218; padding: 24px 28px; border-radius: 20px;
  background: linear-gradient(#fbf6e8, #f1e7cc);
  box-shadow: 0 0 0 6px #5a3a1f, 0 0 0 8px #d8b06a, 0 30px 60px rgba(0,0,0,.6);
}
.sheet.small { width: min(420px, 100%); text-align: center; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 6px; }
.sheet h2 { font-size: 30px; margin: 0 0 8px; color: #3a2a10; }
.sheet h3 { font-size: 20px; margin: 14px 0 2px; color: #6b4b1c; }
.sheet p { font-size: 17px; line-height: 1.4; margin: 0 0 6px; }
.sheet table { width: 100%; border-collapse: collapse; font-size: 18px; margin: 12px 0 14px; }
.sheet td, .sheet th { padding: 6px 8px; border-bottom: 1px solid rgba(90,60,20,.2); text-align: left; }
.sheet td.n, .sheet th.n { text-align: right; }
.sheet-actions { display: flex; justify-content: center; }
.sheet .btn { color: #2a1d07; background: linear-gradient(#f0d48f, #b8924a); border-color: #b8924a; }
.sheet .btn.primary { font-weight: 700; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal.open { animation: fade .25s ease; }

@media (max-width: 760px) {
  .table { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto 1fr; padding: 14px; margin: 0 6px; }
  .seat-top { grid-column: 1 / 3; grid-row: 1; }
  .seat-left { grid-column: 1; grid-row: 2; }
  .seat-right { grid-column: 2; grid-row: 2; }
  .center { grid-column: 1 / 3; grid-row: 3; }
  .brand { font-size: 19px; }
  .fan { width: 96px; }
}
