* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --felt: #1d5c3a;
  --felt-dark: #14432a;
  --ink: #f2efe6;
  --accent: #f5c542;
  --danger: #d84343;
  --card-red: #c0392b;
  --card-black: #1d2733;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: radial-gradient(ellipse at 50% 30%, var(--felt) 0%, var(--felt-dark) 100%);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
}

.hidden { display: none !important; }

.screen {
  width: 100%;
  max-width: 560px;
  padding: 24px 16px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

h1 { font-size: 2.4rem; margin-top: 8vh; text-shadow: 0 2px 8px rgba(0,0,0,.4); }
h2 { font-size: 1.5rem; }
h3 { align-self: flex-start; margin-top: 6px; }
.tagline { opacity: .8; margin-bottom: 12px; }
.hint { opacity: .7; font-size: .85rem; text-align: center; }
.code { color: var(--accent); letter-spacing: .2em; font-family: ui-monospace, Menlo, monospace; }

input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.25);
  color: var(--ink);
  font-size: 1.05rem;
  outline: none;
}
input:focus { border-color: var(--accent); }
#codeInput { text-transform: uppercase; letter-spacing: .3em; font-family: ui-monospace, Menlo, monospace; }

button {
  border: none;
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  background: var(--accent);
  color: #3a2c00;
  transition: transform .05s, filter .15s;
}
button:active { transform: scale(.97); }
button:disabled { filter: grayscale(.7) brightness(.7); cursor: default; }
button.big { width: 100%; padding: 15px; font-size: 1.15rem; }
button.ghost { background: transparent; color: var(--ink); border: 2px solid rgba(255,255,255,.3); }

.joinrow { display: flex; gap: 10px; width: 100%; }
.joinrow input { flex: 1; }
.btnrow { display: flex; gap: 10px; width: 100%; margin-top: 8px; }
.btnrow .big { flex: 1; }

/* lobby settings */
#settings { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.setgroup { margin-top: 4px; font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; opacity: .6; }
.setting {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0,0,0,.2);
  border-radius: 10px;
  padding: 9px 12px;
}
.setting input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--accent); flex: none; }
.setting select { padding: 4px 8px; border-radius: 6px; font-size: 1rem; }
.setting .lbl { font-weight: 700; }
.setting .desc { font-size: .8rem; opacity: .75; }
.setting .text { display: flex; flex-direction: column; }

/* player chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; width: 100%; }
.chip {
  background: rgba(0,0,0,.3);
  border: 2px solid transparent;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: .95rem;
  display: flex;
  gap: 8px;
  align-items: center;
}
.chip.turn { border-color: var(--accent); box-shadow: 0 0 12px rgba(245,197,66,.5); }
.chip.gone { opacity: .45; }
.chip.out { opacity: .6; text-decoration: line-through; }
.chip .count { background: rgba(255,255,255,.15); border-radius: 999px; padding: 1px 8px; font-weight: 700; }
.chip .host { color: var(--accent); }

/* table + pile */
#table {
  position: relative;
  width: 100%;
  height: 250px;
  background: rgba(0,0,0,.18);
  border: 3px solid rgba(0,0,0,.25);
  border-radius: 18px;
  overflow: hidden;
}
#table.flash { animation: flash .5s; }
@keyframes flash {
  0% { box-shadow: inset 0 0 0 6px var(--accent); }
  100% { box-shadow: inset 0 0 0 0 transparent; }
}

#challengeBar {
  position: absolute;
  top: 0; left: 0; right: 0;
  text-align: center;
  padding: 7px;
  background: rgba(216,67,67,.85);
  font-weight: 700;
  z-index: 5;
  font-size: .95rem;
}

#pile {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
#pileCount {
  position: absolute;
  bottom: 8px; right: 14px;
  font-size: .85rem;
  opacity: .75;
}

.card {
  position: absolute;
  width: 74px;
  height: 104px;
  background: #faf7ef;
  border-radius: 9px;
  border: 1px solid #999;
  box-shadow: 0 3px 8px rgba(0,0,0,.35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--card-black);
}
.card.red { color: var(--card-red); }
.card .rank { font-size: 1.7rem; line-height: 1; }
.card .suit { font-size: 1.5rem; }
.card.back {
  background: repeating-linear-gradient(45deg, #7a2c2c, #7a2c2c 6px, #5e1f1f 6px, #5e1f1f 12px);
  border-color: #40403f;
}
.card.joker .rank { font-size: 2.2rem; }
.card.top-card { animation: land .15s ease-out; }
@keyframes land {
  from { transform: scale(1.25) translateY(-18px); opacity: .4; }
}

/* controls */
#controls { display: flex; gap: 12px; width: 100%; }
button.action {
  flex: 1;
  padding: 20px 10px;
  font-size: 1.3rem;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
button.action.slap { background: var(--danger); color: #fff; }
#handCount { font-size: .8rem; font-weight: 400; opacity: .85; }
.keys { font-size: .75rem; opacity: .55; }
button.linkish {
  background: none;
  color: var(--ink);
  padding: 0;
  font-size: inherit;
  font-weight: 400;
  text-decoration: underline;
}

/* log */
#log {
  width: 100%;
  height: 150px;
  overflow-y: auto;
  background: rgba(0,0,0,.25);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: .85rem;
  line-height: 1.5;
}
#log .ev { opacity: .9; }
#log .ev.slapEv { color: var(--accent); font-weight: 700; }

/* stats */
.statsbox { width: 100%; overflow-x: auto; }
.statsbox table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(0,0,0,.25);
  border-radius: 10px;
  overflow: hidden;
  font-size: .85rem;
}
.statsbox th, .statsbox td {
  padding: 6px 8px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.statsbox th { background: rgba(0,0,0,.25); font-size: .8rem; }
.statsbox .pname { text-align: left; font-weight: 700; }
.statsbox .score { font-weight: 800; color: var(--accent); }
#botRow button { flex: 1; }
.statsbox tr:last-child td { border-bottom: none; }

/* game over overlay */
#gameover {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
#gameover .panel {
  background: var(--felt-dark);
  border: 3px solid var(--accent);
  border-radius: 16px;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: center;
  width: min(580px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
}

/* after-game analysis chart (dark chart surface, dataviz reference palette) */
#chart { width: 100%; }
.chartcard {
  position: relative;
  background: #1a1a19;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;
  padding: 12px 14px 10px;
}
.charttitle { color: #ffffff; font-size: .9rem; font-weight: 700; margin-bottom: 6px; }
.chartsub { color: #898781; font-weight: 400; font-size: .75rem; }
.chartcard svg { width: 100%; height: auto; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 6px; }
.legend .lg { display: flex; align-items: center; gap: 6px; color: #c3c2b7; font-size: .8rem; }
.legend i, .charttip i {
  width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none;
}
.legend i.dash, .charttip i.dash {
  background: none; height: 0; border-top: 2px dashed #898781; border-radius: 0; width: 12px;
}
.charttip {
  position: absolute;
  background: #0d0d0d;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: .78rem;
  color: #c3c2b7;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  z-index: 10;
  white-space: nowrap;
}
.charttip b { color: #ffffff; }
.charttip span { display: flex; align-items: center; gap: 6px; }
#winnerText { font-size: 1.5rem; font-weight: 800; text-align: center; }

/* toast + banner */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.85);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: .9rem;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}
#banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--danger);
  color: #fff;
  text-align: center;
  padding: 6px;
  font-size: .85rem;
  z-index: 100;
}
