* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --felt: #7a1f2b;
  --felt-dark: #4a1119;
  --ink: #1c2321;
  --paper: #fdfdf8;
  --red: #c0392b;
  --gold: #f4c542;
  --shadow: 0 2px 6px rgba(0,0,0,.4);
}

html, body { height: 100%; }
body {
  font-family: "Avenir Next", "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(ellipse at 50% 30%, var(--felt), var(--felt-dark) 75%);
  color: #f7f2ef;
  min-height: 100vh;
}

.screen {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 40px;
  text-align: center;
}
.screen.wide { max-width: 940px; text-align: initial; padding-top: 10px; }

h1 { font-size: 2.4rem; letter-spacing: .04em; text-shadow: var(--shadow); margin-bottom: 4px; }
.tagline { opacity: .85; margin-bottom: 20px; }

.panel {
  background: rgba(0,0,0,.3);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 14px;
  padding: 20px;
  text-align: left;
  box-shadow: var(--shadow);
}
.panel h2 { font-size: 1.15rem; margin-bottom: 10px; }

label { display: block; font-size: .85rem; opacity: .9; margin-bottom: 12px; }
label.inline { display: inline-block; margin: 0; }
input, select {
  display: block; width: 100%; margin-top: 4px;
  padding: 10px 12px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.94); color: var(--ink); font-size: 1rem;
}
label.inline select { width: auto; display: inline-block; }

button {
  font: inherit; padding: 10px 18px; border-radius: 8px;
  border: 1px solid rgba(255,255,255,.3);
  background: rgba(255,255,255,.14); color: #fff; cursor: pointer;
  transition: background .15s, transform .05s;
}
button:hover:not(:disabled) { background: rgba(255,255,255,.25); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--gold); border-color: transparent; color: #4a3300; font-weight: 700; }
button.primary:hover:not(:disabled) { background: #ffd65e; }
button.linkish { background: none; border: none; text-decoration: underline; opacity: .75; }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }
.divider {
  display: flex; align-items: center; gap: 10px;
  font-size: .75rem; text-transform: uppercase; letter-spacing: .12em;
  opacity: .7; margin: 18px 0 12px;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: rgba(255,255,255,.25); }
.hint { font-size: .8rem; opacity: .72; margin: 8px 0 14px; }

.rules { margin-top: 22px; text-align: left; font-size: .85rem; opacity: .88; }
.rules summary { cursor: pointer; text-align: center; }
.rules ul { margin: 10px 0 0 20px; display: grid; gap: 6px; }

#lobby-list { list-style: none; margin: 6px 0 8px; }
#lobby-list li { padding: 8px 12px; border-radius: 8px; background: rgba(255,255,255,.09); margin-bottom: 6px; }
#lobby-list li .you { color: var(--gold); font-weight: 700; }

/* ---------- cards ---------- */
.card {
  width: 58px; height: 82px; border-radius: 7px;
  background: var(--paper); color: var(--ink);
  box-shadow: var(--shadow); position: relative;
  display: inline-flex; flex-direction: column; justify-content: space-between;
  padding: 4px 5px; font-weight: 700; user-select: none; flex-shrink: 0; overflow: hidden;
}
.card .tl { font-size: .95rem; line-height: 1.05; text-align: left; }
.card .mid { font-size: 1.5rem; text-align: center; }
.card .br { font-size: .95rem; line-height: 1.05; text-align: right; transform: rotate(180deg); }
.card.red { color: var(--red); }
.card.back {
  background: repeating-linear-gradient(45deg, #8e3540 0 6px, #6d2732 6px 12px);
  border: 3px solid #e9e9e2; overflow: visible;
}
.card.mini { width: 30px; height: 44px; border-radius: 5px; padding: 2px 3px; }
.card.mini .tl { font-size: .6rem; }
.card.mini .mid { font-size: .8rem; }
.card.mini .br { display: none; }

.card.clickable { cursor: pointer; }
.card.clickable:hover { transform: translateY(-4px); }
.card.selected { outline: 3px solid var(--gold); transform: translateY(-12px); }
.card, .card.selected { transition: transform .12s, outline-color .12s; }

.cardrow { display: flex; gap: 6px; flex-wrap: wrap; align-items: flex-end; min-height: 88px; padding: 4px 0; }
.cardrow.center { justify-content: center; }

.count-badge {
  position: absolute; top: -8px; right: -8px;
  background: var(--gold); color: #4a3300;
  font-size: .72rem; font-weight: 800;
  border-radius: 999px; min-width: 20px; height: 20px;
  display: flex; align-items: center; justify-content: center; padding: 0 5px;
  box-shadow: var(--shadow);
}

/* ---------- opponents ---------- */
#opponents { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; padding: 8px 0; }
.opp {
  background: rgba(0,0,0,.26); border: 2px solid transparent; border-radius: 12px;
  padding: 10px 12px; min-width: 150px; text-align: center;
}
.opp.active { border-color: var(--gold); box-shadow: 0 0 14px rgba(244,197,66,.45); }
.opp.out { opacity: .6; }
.opp-name { font-weight: 700; margin-bottom: 6px; }
.opp-name .tag { font-size: .7rem; opacity: .8; font-weight: 400; }
.opp-row { display: flex; gap: 3px; justify-content: center; min-height: 46px; }

/* ---------- centre ---------- */
#table-center {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 16px 0; min-height: 130px;
}
#combo-label { font-size: .95rem; font-weight: 700; opacity: .9; min-height: 1.3em; }
#pile { min-height: 88px; }
#pile:empty::after {
  content: "—"; opacity: .35; font-size: 2rem;
}

/* ---------- my area ---------- */
#my-area { background: rgba(0,0,0,.26); border-radius: 14px; padding: 14px 18px; margin-top: 6px; }
#status-line { font-weight: 700; min-height: 1.4em; margin-bottom: 8px; }
#status-line.urgent { color: var(--gold); }
.zone-label { font-size: .65rem; text-transform: uppercase; letter-spacing: .12em; opacity: .6; display: block; }
#action-bar { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; min-height: 44px; align-items: center; }
.sel-note { font-size: .82rem; opacity: .8; }

/* ---------- log ---------- */
#log-panel {
  margin-top: 12px; background: rgba(0,0,0,.3); border-radius: 10px;
  padding: 10px 14px; max-height: 120px; overflow-y: auto; font-size: .8rem;
}
#log div { padding: 1.5px 0; opacity: .85; }
#log div:last-child { opacity: 1; font-weight: 600; }

/* ---------- league ---------- */
.league-panel { margin-top: 16px; }
.league-panel h3, #over-league h3 { font-size: 1rem; margin-bottom: 8px; }
.league-panel h3 em, #over-league h3 em { color: var(--gold); font-style: normal; }
.league-table { width: 100%; border-collapse: collapse; font-size: .88rem; margin: 4px 0 8px; }
.league-table th, .league-table td { padding: 6px 8px; text-align: left; border-bottom: 1px solid rgba(255,255,255,.12); }
.league-table th { font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; opacity: .65; }
.league-table td:nth-child(3), .league-table td:nth-child(4),
.league-table th:nth-child(3), .league-table th:nth-child(4) { text-align: right; }
#over-league { text-align: left; margin-bottom: 16px; }
#over-league .hint { margin-bottom: 0; }

/* ---------- footer ---------- */
footer { text-align: center; font-size: .75rem; opacity: .65; padding: 10px 12px 26px; }
footer a { color: var(--gold); }

/* ---------- modal & toast ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-box {
  background: #3a1620; border: 1px solid rgba(255,255,255,.2); border-radius: 14px;
  padding: 26px 30px; text-align: center; max-width: 380px; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}
.modal-box h2 { margin-bottom: 10px; }
#over-body { margin-bottom: 16px; }
#over-body ol { text-align: left; margin: 8px 0 0 24px; display: grid; gap: 4px; }

#toast {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  background: var(--red); color: #fff; padding: 10px 20px; border-radius: 10px;
  font-weight: 600; z-index: 100; box-shadow: var(--shadow); max-width: 90vw;
}

@media (max-width: 640px) {
  .card { width: 44px; height: 63px; }
  .card .mid { font-size: 1.05rem; }
  .card .tl, .card .br { font-size: .8rem; }
  .cardrow { min-height: 68px; gap: 4px; }
}
