:root {
  --felt: #1b1714;
  --felt-2: #241f1b;
  --cream: #f6efe0;
  --cream-2: #efe5cf;
  --paper: #faf6ec;
  --gold: #b08a3e;
  --gold-2: #d6b46a;
  --maroon: #7a1f1f;
  --ink: #1d1a17;
  --muted: #7a6f60;
  --s0: #d0503c; --s1: #3a8fb7; --s2: #d9a536; --s3: #8e5bc0;
  --ratio: 1.3965;
  --radius: 6px;
  font-family: 'Crimson Pro', Georgia, serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--felt); color: var(--cream); }
body { background: radial-gradient(ellipse at 50% 40%, #2a241f 0%, var(--felt) 70%); font-size: 15px; overflow: hidden; }
button, input { font: inherit; }
[hidden] { display: none !important; }

/* buttons */
.btn { border: 1px solid #5b4c37; background: #2f2822; color: var(--cream); border-radius: 6px; padding: 4px 10px; cursor: pointer; line-height: 1.2; white-space: nowrap; }
.btn:hover { border-color: var(--gold); background: #3a3129; }
.btn.primary { background: var(--maroon); border-color: #a33a3a; color: #fff; }
.btn.primary:hover { background: #932828; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { border-color: #5b4c37; }
.btn.small { padding: 2px 7px; font-size: 13px; }
.btn.big { padding: 10px 16px; font-size: 18px; width: 100%; }
.btn.on { background: #2e5a3a; border-color: #4f9a62; }
.btn.danger { background: #5a1f1f; border-color: #9a3a3a; }
.btn:disabled { opacity: .45; cursor: default; }

/* lobby */
#lobby { min-height: 100%; display: grid; place-items: center; padding: 16px; overflow: auto; height: 100%; }
.lobby-card { width: min(440px, 100%); background: var(--cream); color: var(--ink); border-radius: 12px; padding: 28px 26px; border: 2px solid var(--gold); box-shadow: 0 20px 60px #0008; text-align: center; }
.lobby-crown { width: 56px; height: 56px; border-radius: 50%; }
.lobby-card h1 { font-family: Cinzel, serif; color: var(--maroon); margin: 6px 0 0; font-size: 34px; letter-spacing: .04em; }
.sub { margin: 2px 0 18px; color: var(--muted); }
.field { display: block; text-align: left; font-weight: 600; margin-bottom: 12px; }
.field input, .join-row input { display: block; width: 100%; margin-top: 4px; padding: 9px 11px; border: 1px solid #c9b88f; border-radius: 6px; background: #fff; color: var(--ink); font-size: 16px; }
.join-row { display: flex; gap: 8px; }
.join-row input { margin: 0; text-transform: uppercase; }
.join-row .btn, .lobby-card .btn:not(.primary) { background: var(--ink); }
.or { margin: 18px 0 10px; color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 10px; }
.or::before, .or::after { content: ''; flex: 1; border-top: 1px solid #d8c9a6; }
.fine { color: var(--muted); font-size: 13px; margin: 16px 0 0; }

/* table grid */
#table {
  height: 100vh; height: 100dvh; display: grid; gap: 6px; padding: 0 6px 0;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 1.2fr) minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto auto;
  grid-template-areas: "bar bar bar" "top top top" "left altar right" "me me me" "hand hand hand";
}
#bar { grid-area: bar; display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-bottom: 1px solid #3a3129; min-width: 0; }
.brand { font-family: Cinzel, serif; color: var(--gold-2); font-weight: 700; letter-spacing: .05em; white-space: nowrap; }
#invite b { font-family: Cinzel, serif; letter-spacing: .04em; color: var(--gold-2); }
#turn { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.turn-name { white-space: nowrap; font-weight: 700; }
.phase { font-size: 13px; padding: 2px 8px; border-radius: 999px; border: 1px solid #4a3f33; background: transparent; color: #cbbd9f; cursor: pointer; }
.phase.cur { background: var(--gold); color: var(--ink); border-color: var(--gold); font-weight: 700; }
#voice { display: flex; align-items: center; gap: 6px; }
.vchip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid #4a3f33; border-radius: 999px; padding: 2px 8px 2px 4px; font-size: 13px; cursor: pointer; background: transparent; color: var(--cream); white-space: nowrap; }
.vdot { width: 10px; height: 10px; border-radius: 50%; background: #6b6257; box-shadow: 0 0 0 0 transparent; transition: box-shadow .12s; }
.vchip.speaking .vdot, .speaking > .vdot { background: #5fd17f; box-shadow: 0 0 0 3px #5fd17f55; }
.vchip.muted .vdot { background: #a33; }
.bar-right { display: flex; gap: 4px; }

.seat-slot { min-width: 0; min-height: 0; }
#seat-top { grid-area: top; }
#seat-left { grid-area: left; overflow: auto; }
#seat-right { grid-area: right; overflow: auto; }
#seat-bottom { grid-area: me; }
#altar-wrap { grid-area: altar; min-height: 0; overflow: auto; }
#hand { grid-area: hand; }

/* mats */
.mat { --cw: clamp(38px, 3.6vw, 62px); background: var(--cream); color: var(--ink); border-radius: 10px; border: 2px solid var(--gold); padding: 4px 8px 6px; position: relative; height: 100%; }
.mat.me { --cw: clamp(54px, 5.3vw, 92px); height: auto; }
.mat.active { box-shadow: 0 0 0 3px var(--seat), 0 0 22px var(--seat); }
.mat-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 26px; }
.pname { font-family: Cinzel, serif; font-weight: 700; color: var(--maroon); display: inline-flex; align-items: center; gap: 6px; }
.pname::before { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--seat); flex: none; }
.pfac { color: var(--muted); font-style: italic; }
.chip { font-size: 13px; background: var(--cream-2); border: 1px solid #d8c9a6; border-radius: 999px; padding: 0 8px; white-space: nowrap; }
.chip b { color: var(--maroon); }
.chip.off { color: #a33; }
.head-spacer { flex: 1; }
.mat-head .btn { background: var(--ink); font-size: 13px; padding: 2px 8px; }
.mat-head .btn.on { background: #2e5a3a; }
.mat-body { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; margin-top: 2px; }
.mat.me .mat-body { flex-wrap: nowrap; overflow-x: auto; }
.seat-c0 { --seat: var(--s0); } .seat-c1 { --seat: var(--s1); } .seat-c2 { --seat: var(--s2); } .seat-c3 { --seat: var(--s3); }

.zone { border: 1.5px dashed var(--gold); border-radius: 8px; padding: 2px 4px 4px; background: var(--paper); min-width: calc(var(--cw) + 10px); position: relative; }
.zone > .zl { font-family: Cinzel, serif; font-size: 10px; letter-spacing: .06em; color: var(--maroon); font-weight: 700; display: flex; justify-content: space-between; gap: 6px; white-space: nowrap; }
.zone > .zl i { font-family: 'Crimson Pro', serif; font-style: normal; color: var(--muted); font-weight: 400; letter-spacing: 0; font-size: 12px; }
.zone .cards { display: flex; gap: 4px; min-height: calc(var(--cw) * var(--ratio)); align-items: flex-start; }
.zone.champions { flex: 1 1 auto; min-width: calc(var(--cw) * 3); background: #efe4c9; }
.zone.champions .cards { flex-wrap: wrap; }
.mat.me .zone.champions .cards { flex-wrap: nowrap; }
.zone.pacts .cards { flex-wrap: wrap; }
.zone.empty-hint .cards::after { content: attr(data-hint); color: #b3a68b; font-size: 12px; font-style: italic; align-self: center; padding: 0 4px; }
.zone.over, .pile.over { outline: 3px solid var(--seat, var(--gold)); outline-offset: 1px; background: #fff8e6; }
body.dragging .zone, body.dragging .pile { cursor: copy; }

.pile { width: calc(var(--cw) + 10px); border: 1.5px dashed var(--gold); border-radius: 8px; padding: 2px 4px 4px; background: var(--paper); position: relative; flex: none; }
.pile .slot { width: var(--cw); height: calc(var(--cw) * var(--ratio)); border-radius: var(--radius); background: #e9dfc8; position: relative; }
.pile .count { position: absolute; right: -4px; bottom: -4px; background: var(--ink); color: var(--cream); border-radius: 999px; font-size: 12px; padding: 0 6px; font-weight: 700; z-index: 2; border: 1px solid var(--gold); }
.pile .slot.clicky { cursor: pointer; }

/* cards */
.card { width: var(--cw); height: calc(var(--cw) * var(--ratio)); border-radius: var(--radius); position: relative; flex: none; cursor: grab; touch-action: none; user-select: none; transition: transform .15s; box-shadow: 0 1px 3px #0005; background: #2a2420; }
.card img { width: 100%; height: 100%; border-radius: var(--radius); display: block; pointer-events: none; }
.card.eng { transform: rotate(90deg) scale(.86); }
.zone.champions .card.eng, .zone.pacts .card.eng { margin: 0 calc(var(--cw) * .2); }
.card.facedown-own img { filter: brightness(.55) saturate(.6); }
.card.facedown-own::after { content: 'face down'; position: absolute; inset: auto 0 40% 0; text-align: center; font-size: 10px; color: #fff; text-shadow: 0 1px 2px #000; font-weight: 700; letter-spacing: .04em; }
.card.hidden { cursor: default; }
.card.ghost-src { opacity: .35; }
.badge { position: absolute; min-width: 20px; height: 20px; border-radius: 10px; font-size: 12px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; color: #fff; border: 1.5px solid #fff; box-shadow: 0 1px 3px #0008; z-index: 2; pointer-events: none; }
.badge.dmg { background: #b3261e; top: 18%; right: -5px; }
.badge.psn { background: #2f7d32; top: calc(18% + 23px); right: -5px; }
.card.eng .badge { transform: rotate(-90deg); }
#drag-ghost { position: fixed; z-index: 1000; pointer-events: none; width: 90px; height: calc(90px * var(--ratio)); border-radius: 6px; box-shadow: 0 12px 30px #000a; transform: translate(-50%, -50%) rotate(-4deg); }
#drag-ghost img { width: 100%; height: 100%; border-radius: 6px; }

/* tracker */
.tracker { width: auto; }
.tracker .slot { overflow: hidden; }
.tracker .dials { position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-evenly; align-items: center; background: #1d1a17bb; border-radius: var(--radius); }
.dial { display: flex; flex-direction: column; align-items: center; color: #fff; }
.dial .lab { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--gold-2); font-weight: 700; }
.dial .val { display: flex; align-items: center; gap: 3px; }
.dial .num { font-family: Cinzel, serif; font-size: calc(var(--cw) * .28); font-weight: 700; min-width: 1.1em; text-align: center; }
.dial button { width: 20px; height: 20px; padding: 0; border-radius: 50%; border: 1px solid var(--gold); background: #2f2822; color: #fff; cursor: pointer; font-size: 14px; line-height: 1; }
.dial button:hover { background: var(--maroon); }

/* altar */
.altar { background: var(--cream); color: var(--ink); border: 2px solid var(--gold); border-radius: 10px; padding: 6px 8px 8px; height: 100%; display: flex; flex-direction: column; gap: 6px; --cw: clamp(44px, 4.2vw, 76px); min-height: 0; }
.tracks { display: grid; grid-template-columns: auto repeat(6, minmax(0, 1fr)); gap: 2px 3px; align-items: center; font-size: 12px; }
.tracks .tname { font-weight: 700; display: flex; align-items: center; gap: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; padding-right: 4px; }
.tracks .tname::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--seat); flex: none; }
.tracks .first { font-size: 10px; border: 1px dashed var(--gold); border-radius: 50%; width: 18px; height: 18px; display: inline-grid; place-items: center; color: var(--muted); flex: none; }
.cell { border: 1px solid #c9b88f; background: #fff; border-radius: 4px; height: 26px; display: flex; align-items: center; justify-content: center; gap: 4px; position: relative; font-family: Cinzel, serif; font-weight: 700; color: #3a332b; padding: 0 2px; }
.cell small { font-family: 'Crimson Pro', serif; font-weight: 400; font-size: 10px; color: var(--muted); white-space: nowrap; overflow: hidden; }
.cell.crown { background: #f1e3c4; }
.cell.win { background: #ead6a8; border-color: var(--gold); }
.cell.clicky { cursor: pointer; }
.cell.clicky:hover { outline: 2px solid var(--seat); }
.cell.at { background: var(--seat); color: #fff; border-color: var(--seat); box-shadow: 0 0 0 2px #fff inset; }
.cell.at small { color: #fff; }
.tracks-head { display: contents; }
.tracks-head span { font-size: 10px; text-align: center; color: var(--muted); }
.altar-zones { display: flex; gap: 8px; flex: 1; min-height: 0; }
.zone.altar-z { flex: 0 0 auto; min-width: calc(var(--cw) * 1.6); display: flex; flex-direction: column; }
.zone.pool-z { flex: 1; display: flex; flex-direction: column; }
.zone.pool-z .cards { flex-wrap: wrap; }
.zone.altar-z .zl, .zone.pool-z .zl { font-size: 12px; }
.helper { font-size: 12px; color: var(--ink); margin-top: 4px; line-height: 1.25; }
.helper b { color: var(--maroon); }
.helper .note { color: var(--muted); font-size: 11px; font-style: italic; }
.zbtns { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.zbtns .btn { background: var(--ink); font-size: 12px; padding: 2px 7px; }

/* empty / picker */
.empty-seat { height: 100%; min-height: 70px; border: 2px dashed #4a3f33; border-radius: 10px; display: flex; align-items: center; justify-content: center; gap: 10px; color: #8d806c; flex-wrap: wrap; padding: 8px; }
.picker { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; padding: 6px 0; }
.picker button { border: 2px solid transparent; background: none; padding: 0; border-radius: 8px; cursor: pointer; width: clamp(80px, 8vw, 120px); text-align: center; color: var(--ink); font-size: 13px; font-weight: 700; }
.picker button:hover { border-color: var(--maroon); }
.picker img { width: 100%; border-radius: 6px; display: block; }
.picker-title { font-family: Cinzel, serif; color: var(--maroon); text-align: center; font-weight: 700; margin-top: 4px; }

/* hand */
#hand { padding: 0 8px 6px; --cw: clamp(64px, 6.2vw, 108px); min-height: 0; }
.hand-inner { display: flex; align-items: flex-end; gap: 10px; }
.hand-label { font-family: Cinzel, serif; color: var(--gold-2); font-size: 12px; writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; }
.hand-cards { display: flex; padding: 8px 6px 0; min-height: calc(var(--cw) * var(--ratio) + 8px); flex: 1; border-top: 1px dashed #5b4c37; border-radius: 8px 8px 0 0; overflow-x: auto; overflow-y: visible; }
.hand-cards .card { margin-right: calc(var(--overlap, 0px) * -1); }
.hand-cards .card:hover { transform: translateY(-8px); z-index: 3; }
.hand-cards:empty::after { content: 'Your hand is empty'; color: #6b6257; font-style: italic; align-self: center; }
.hand-cards.over { background: #3a312933; outline: 2px solid var(--gold); }

/* log */
#log { position: fixed; top: 46px; right: 6px; bottom: 6px; width: min(340px, calc(100vw - 12px)); background: #1f1a16f2; border: 1px solid #5b4c37; border-radius: 10px; display: flex; flex-direction: column; z-index: 50; box-shadow: 0 10px 40px #0009; }
.log-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-bottom: 1px solid #3a3129; }
#log-list { flex: 1; overflow-y: auto; padding: 6px 10px; font-size: 14px; line-height: 1.3; }
.le { padding: 3px 0; border-bottom: 1px solid #2c2620; }
.le.sys { color: var(--gold-2); }
.le.chat b { color: #9fd0ff; }
.le .cn { text-decoration: underline dotted; cursor: help; }
.le time { color: #6b6257; font-size: 11px; margin-right: 4px; }
#chat-form { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #3a3129; }
#chat-input { flex: 1; background: #2f2822; color: var(--cream); border: 1px solid #5b4c37; border-radius: 6px; padding: 5px 8px; }

/* menu, modal, preview, toast */
#menu { position: fixed; z-index: 300; background: #241f1b; border: 1px solid var(--gold); border-radius: 8px; padding: 4px; min-width: 210px; max-height: calc(100vh - 16px); overflow-y: auto; box-shadow: 0 12px 40px #000c; }
#menu .mt { font-family: Cinzel, serif; color: var(--gold-2); font-size: 13px; padding: 4px 8px 6px; border-bottom: 1px solid #3a3129; margin-bottom: 2px; }
#menu button { display: flex; width: 100%; justify-content: space-between; gap: 14px; text-align: left; background: none; border: 0; color: var(--cream); padding: 5px 8px; border-radius: 5px; cursor: pointer; font-size: 14px; }
#menu button:hover { background: var(--maroon); }
#menu button kbd { color: #9a8c76; font-family: inherit; font-size: 12px; }
#menu .sep { border-top: 1px solid #3a3129; margin: 3px 0; }
#menu .sub { color: #9a8c76; font-size: 12px; padding: 4px 8px 0; }
#menu .stepper { display: flex; align-items: center; gap: 6px; padding: 3px 8px; font-size: 14px; }
#menu .stepper span { flex: 1; }
#menu .stepper button { width: 28px; justify-content: center; border: 1px solid #5b4c37; padding: 2px; }
#modal { position: fixed; inset: 0; background: #000a; z-index: 200; display: grid; place-items: center; padding: 16px; }
.modal-box { background: var(--cream); color: var(--ink); border: 2px solid var(--gold); border-radius: 12px; width: min(980px, 100%); max-height: 90vh; display: flex; flex-direction: column; --cw: clamp(80px, 9vw, 120px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid #d8c9a6; font-family: Cinzel, serif; color: var(--maroon); }
.modal-head .btn { color: var(--ink); }
#modal-body { overflow-y: auto; padding: 12px; }
#modal-body .grid { display: flex; flex-wrap: wrap; gap: 8px; }
#modal-body .hint { color: var(--muted); margin: 0 0 10px; }
#modal-body .modal-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
#modal-body .modal-actions .btn { background: var(--ink); }
#modal-body .card { cursor: pointer; }
#preview { position: fixed; z-index: 400; pointer-events: none; width: min(340px, 40vw); }
#preview img { width: 100%; border-radius: 14px; box-shadow: 0 16px 50px #000d; display: block; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #241f1b; border: 1px solid var(--gold); padding: 8px 14px; border-radius: 8px; z-index: 500; box-shadow: 0 8px 30px #000a; }
#conn { position: fixed; top: 8px; left: 50%; transform: translateX(-50%); background: #7a1f1f; color: #fff; padding: 4px 12px; border-radius: 999px; z-index: 600; }
.reveal-pop { position: fixed; inset: 0; z-index: 450; display: grid; place-items: center; background: #0008; pointer-events: none; animation: fadeout 3.2s forwards; }
.reveal-pop div { text-align: center; color: var(--cream); font-family: Cinzel, serif; }
.reveal-pop img { width: min(320px, 60vw); border-radius: 14px; box-shadow: 0 16px 50px #000; display: block; margin: 8px auto 0; }
@keyframes fadeout { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

/* narrow screens: stack everything and let the page scroll */
@media (max-width: 900px) {
  body { overflow: auto; }
  #table { height: auto; min-height: 100vh; grid-template-columns: minmax(0, 1fr); grid-template-rows: none;
    grid-template-areas: "bar" "top" "left" "right" "altar" "me" "hand"; }
  #bar { flex-wrap: wrap; position: sticky; top: 0; background: var(--felt); z-index: 20; }
  .brand { display: none; }
  #turn { order: 5; flex-basis: 100%; }
  #hand { position: sticky; bottom: 0; background: var(--felt); z-index: 10; }
  .mat.me .mat-body { flex-wrap: wrap; }
  .mat.me .zone.champions .cards { flex-wrap: wrap; }
}

/* fixes */
.mat .vchip { color: var(--ink); border-color: #c9b88f; background: var(--cream-2); }
.mat .vchip.speaking { border-color: #3c9a57; }
.pile > .zl, .pile .zone-l { font-size: 9px !important; letter-spacing: .02em !important; text-overflow: ellipsis; overflow: hidden; }

/* lobby: learn to play */
.learn-row { display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap; margin: 18px 0 4px; padding-top: 14px; border-top: 1px solid #ddcfb2; }
.learn-row span { color: var(--muted); font-style: italic; }
.learn-row .btn { text-decoration: none; padding: 6px 14px; font-size: 16px; }
