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

:root {
  --felt: #1d6b3c;
  --felt-dark: #14512c;
  --ink: #1c2321;
  --paper: #fdfdf8;
  --red: #c0392b;
  --gold: #f4c542;
  --shadow: 0 2px 6px rgba(0,0,0,.35);
}

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: #f2f5f0;
  min-height: 100vh;
}

.screen {
  max-width: 480px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  text-align: center;
}
.screen.wide { max-width: 900px; 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,.28);
  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,.92);
  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; margin-top: 12px; }

.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: .7; margin: 8px 0 14px; }

.rules { margin-top: 22px; text-align: left; font-size: .85rem; opacity: .85; }
.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, #35548e 0 6px, #2a4373 6px 12px);
  border: 3px solid #e9e9e2;
  overflow: visible; /* backs carry the count badge, which sits outside the card */
}
.card.mini { width: 34px; height: 48px; border-radius: 5px; padding: 2px 3px; }
.card.mini .tl { font-size: .68rem; }
.card.mini .mid { font-size: .85rem; }
.card.mini .br { display: none; }

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

.cardrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; min-height: 86px; padding: 4px 0; }

.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,.24);
  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: .55; }
.opp-name { font-weight: 700; margin-bottom: 6px; }
.opp-name .tag { font-size: .7rem; opacity: .75; font-weight: 400; }
.opp-row { display: flex; gap: 4px; justify-content: center; margin-top: 5px; min-height: 50px; }
.opp-zone-label { font-size: .62rem; text-transform: uppercase; letter-spacing: .1em; opacity: .6; margin-top: 6px; }
.opp .done { font-size: .85rem; color: var(--gold); margin-top: 8px; }

/* ---------- centre ---------- */
#table-center { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 14px 0; }
.pile-area { display: flex; gap: 34px; align-items: flex-end; }
.pile-slot { text-align: center; position: relative; }
.stack { position: relative; width: 62px; height: 86px; margin: 0 auto; }
.stack .card { position: absolute; top: 0; left: 0; }
.stack .card:nth-child(2) { transform: translate(7px, -2px) rotate(4deg); }
.stack .card:nth-child(3) { transform: translate(14px, -4px) rotate(8deg); }
.stack .card:nth-child(4) { transform: translate(21px, -6px) rotate(12deg); }
.stack.empty { border: 2px dashed rgba(255,255,255,.3); border-radius: 7px; }
.pile-label { font-size: .75rem; opacity: .8; margin-top: 8px; }
.burn-mark { font-size: 2.6rem; line-height: 86px; text-align: center; }
#constraint-badge {
  background: var(--red); color: #fff; font-weight: 800;
  padding: 6px 16px; border-radius: 999px; letter-spacing: .05em;
  box-shadow: var(--shadow);
  animation: pop .25s ease-out;
}
@keyframes pop { from { transform: scale(.6); opacity: 0; } }

/* ---------- my area ---------- */
#my-area {
  background: rgba(0,0,0,.24);
  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); }
.table-rows { display: flex; gap: 28px; flex-wrap: wrap; }
.zone { position: relative; }
.zone-label { font-size: .65rem; text-transform: uppercase; letter-spacing: .12em; opacity: .6; display: block; }
.hand-zone { margin-top: 6px; }
#action-bar { display: flex; gap: 10px; margin-top: 10px; flex-wrap: wrap; min-height: 44px; }

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

/* ---------- modals & 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: #24352b;
  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; }
.modal-box p { margin-bottom: 16px; opacity: .9; }
.modal-box .row { margin-top: 8px; }
#over-body { margin-bottom: 16px; }
#over-body ol { text-align: left; margin: 8px 0 0 24px; }

/* ---------- 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; }
.league-table tr:first-child + tr td { font-weight: 700; }
#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); }

#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: 46px; height: 66px; }
  .card .mid { font-size: 1.1rem; }
  .cardrow { min-height: 70px; gap: 5px; }
  .stack { width: 50px; height: 70px; }
  .pile-area { gap: 18px; }
  .table-rows { gap: 14px; }
}
