:root {
  --bg: #1b1740;
  --bg2: #2a2168;
  --panel: rgba(255, 255, 255, 0.07);
  --panel-b: rgba(255, 255, 255, 0.12);
  --ink: #f6f4ff;
  --muted: #b3acd9;
  --accent: #ff5d73;
  --accent2: #ffc83d;
  --good: #33d17a;
  --bad: #ff5d5d;
  --card-ink: #1b1740;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(8, 5, 30, 0.45);
  font-family: 'Fredoka', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(circle at 15% 10%, rgba(255, 93, 115, 0.18), transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(255, 200, 61, 0.14), transparent 45%),
    radial-gradient(circle at 50% 50%, var(--bg2), var(--bg) 70%);
  background-attachment: fixed;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button { font: inherit; color: inherit; }
input { font: inherit; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.error { color: #ff8a9a; min-height: 1.2em; margin: 0.5rem 0 0; font-size: 0.95rem; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid var(--panel-b);
  background: rgba(255, 255, 255, 0.1);
  padding: 0.7rem 1.1rem;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.08s, background 0.15s, opacity 0.15s;
}
.btn:hover { background: rgba(255, 255, 255, 0.17); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #ff8a5c); border-color: transparent; color: #fff; box-shadow: 0 6px 18px rgba(255, 93, 115, 0.35); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.big { width: 100%; padding: 0.95rem 1.2rem; font-size: 1.1rem; }
.btn.sm { padding: 0.4rem 0.75rem; font-size: 0.9rem; border-radius: 10px; }

input {
  width: 100%;
  padding: 0.8rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--panel-b);
  background: rgba(0, 0, 0, 0.25);
  color: var(--ink);
  outline: none;
}
input:focus { border-color: var(--accent2); box-shadow: 0 0 0 3px rgba(255, 200, 61, 0.2); }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-b);
  border-radius: var(--radius);
  padding: 1.25rem;
  backdrop-filter: blur(6px);
}
.panel h2 { margin: 0 0 0.75rem; font-size: 1.15rem; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; }

/* ---------- screens ---------- */
.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }

.brand { font-weight: 700; font-size: 1.4rem; letter-spacing: 0.5px; }
.brand span, .logo h1 span { color: var(--accent2); }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.8rem 1.25rem;
}

/* ---------- home ---------- */
.home-wrap { max-width: 440px; margin: 0 auto; padding: 5vh 16px 2rem; }
.logo { text-align: center; margin-bottom: 1.5rem; }
.logo h1 { font-size: 3rem; margin: 0.5rem 0 0.25rem; letter-spacing: 1px; }
.logo .tag { color: var(--muted); margin: 0; }
.logo-card { width: 150px; margin: 0 auto; animation: spin 24s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.home-panel { display: grid; gap: 0.9rem; }
.field span { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 0.35rem; }
.or { text-align: center; color: var(--muted); font-size: 0.9rem; position: relative; }
.or::before { content: ''; position: absolute; left: 0; right: 0; top: 50%; border-top: 1px solid var(--panel-b); }
.or span { position: relative; background: #251e5a; padding: 0 0.6rem; border-radius: 6px; }
.join-row { display: flex; gap: 0.5rem; }
.join-row input { text-transform: uppercase; letter-spacing: 4px; font-weight: 600; text-align: center; }
.foot { text-align: center; color: var(--muted); font-size: 0.85rem; margin-top: 1.5rem; }

/* ---------- lobby ---------- */
.lobby-grid {
  display: grid; gap: 1rem; padding: 0 1.25rem 1.5rem;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 1.4fr) minmax(240px, 1fr);
  max-width: 1300px; margin: 0 auto;
}
.room-code { font-size: 2.8rem; font-weight: 700; letter-spacing: 8px; color: var(--accent2); margin: 0.1rem 0 0.6rem; }
.code-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.player-list { list-style: none; padding: 0; margin: 0.6rem 0 0; display: grid; gap: 0.4rem; }
.player-list li {
  display: flex; align-items: center; gap: 0.5rem;
  background: rgba(0, 0, 0, 0.18); padding: 0.5rem 0.65rem; border-radius: 12px;
}
.player-list li.offline { opacity: 0.55; }
.player-list .av { font-size: 1.4rem; }
.player-list .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-list em { color: var(--muted); font-style: normal; font-size: 0.85em; }
.badge { font-size: 0.75rem; padding: 0.1rem 0.5rem; border-radius: 99px; background: rgba(255, 255, 255, 0.12); }
.badge.host { background: var(--accent2); color: #3a2a00; font-weight: 600; }
.badge.off { background: rgba(255, 93, 93, 0.25); }
.kick { border: 0; background: transparent; cursor: pointer; opacity: 0.5; padding: 0.2rem 0.4rem; }
.kick:hover { opacity: 1; color: var(--bad); }

.mode-list { display: grid; gap: 0.6rem; margin-bottom: 1rem; }
.mode {
  display: flex; gap: 0.8rem; align-items: center; text-align: left;
  border: 2px solid transparent; background: rgba(0, 0, 0, 0.2);
  padding: 0.75rem 0.9rem; border-radius: 14px; cursor: pointer;
}
.mode:disabled { cursor: default; }
.mode:not(:disabled):hover { background: rgba(255, 255, 255, 0.08); }
.mode.sel { border-color: var(--accent2); background: rgba(255, 200, 61, 0.1); }
.mode .mi { font-size: 1.9rem; }
.mode .mt { display: grid; gap: 0.15rem; }
.mode small { color: var(--muted); line-height: 1.3; }
.rounds-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; padding: 0 0.3rem; }
.stepper { display: flex; align-items: center; gap: 0.6rem; }
.stepper b { min-width: 1.5rem; text-align: center; font-size: 1.2rem; }

.chat-panel { display: flex; flex-direction: column; max-height: 70vh; }
.chat-log { flex: 1; overflow-y: auto; display: grid; align-content: start; gap: 0.35rem; min-height: 180px; margin-bottom: 0.6rem; }
.msg { background: rgba(0, 0, 0, 0.18); padding: 0.4rem 0.6rem; border-radius: 10px; word-break: break-word; }
.msg b { color: var(--accent2); margin-right: 0.3rem; }
.msg.sys { background: rgba(255, 93, 115, 0.2); }
.chat-form { display: flex; gap: 0.4rem; }
.chat-form input { padding: 0.5rem 0.75rem; }

/* ---------- cards ---------- */
.card-holder { width: 100%; aspect-ratio: 1; }
.card {
  position: relative; width: 100%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff, var(--tint, #fff) 75%);
  box-shadow: var(--shadow), inset 0 0 0 4px rgba(27, 23, 64, 0.08), inset 0 0 0 7px #fff, inset 0 0 0 9px rgba(27, 23, 64, 0.06);
  container-type: inline-size;
  user-select: none;
}
.card.empty {
  background: rgba(255, 255, 255, 0.05); box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.15);
  display: grid; place-items: center; color: var(--muted); font-size: 1rem;
}
.card.pop { animation: pop 0.28s ease-out; }
@keyframes pop { from { transform: scale(0.85) rotate(-8deg); opacity: 0.4; } to { transform: none; opacity: 1; } }
.sym {
  position: absolute; border: 0; background: transparent; padding: 0; line-height: 1;
  cursor: default; font-family: 'Apple Color Emoji', 'Segoe UI Emoji', 'Noto Color Emoji', sans-serif;
  touch-action: manipulation; border-radius: 50%;
}
.card.clickable .sym { cursor: pointer; transition: filter 0.1s; }
.card.clickable:not(.disabled) .sym:hover { filter: drop-shadow(0 0 6px rgba(255, 93, 115, 0.9)); }
.card.disabled .sym { cursor: not-allowed; }
.sym.picked { filter: drop-shadow(0 0 8px rgba(255, 200, 61, 1)) !important; }
.sym.wrong { filter: drop-shadow(0 0 8px rgba(255, 60, 60, 1)) grayscale(0.5) !important; }

/* ---------- game ---------- */
#screen-game.active { display: grid; grid-template-columns: 1fr 230px; grid-template-rows: auto 1fr; min-height: 100vh; }
.game-top { grid-column: 1 / -1; }
.game-info { display: flex; gap: 0.75rem; align-items: baseline; flex-wrap: wrap; justify-content: center; }
.game-info b { font-size: 1.15rem; }
.top-actions { display: flex; gap: 0.4rem; }

.table { display: flex; flex-direction: column; gap: 1rem; padding: 0.5rem 1.25rem 1.5rem; min-width: 0; }
.opponents {
  display: grid; gap: 0.75rem; justify-content: center;
  grid-template-columns: repeat(auto-fit, minmax(96px, 124px));
}
.opponents.targets { grid-template-columns: repeat(auto-fit, minmax(130px, 170px)); }
.opponents.targets[data-n="1"], .opponents.targets[data-n="2"] { grid-template-columns: repeat(auto-fit, minmax(170px, 230px)); }
.opp { background: var(--panel); border: 1px solid var(--panel-b); border-radius: 16px; padding: 0.45rem 0.55rem 0.6rem; transition: box-shadow 0.2s, opacity 0.2s; }
.opp-head { display: flex; align-items: center; gap: 0.3rem; margin-bottom: 0.35rem; font-size: 0.85rem; }
.opp-head .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opp-head .cnt { background: rgba(0, 0, 0, 0.3); border-radius: 99px; padding: 0 0.5rem; font-weight: 600; }
.opp.offline { opacity: 0.45; }
.opp.frozen { box-shadow: 0 0 0 2px rgba(120, 200, 255, 0.7); }
.opp.frozen .opp-head .nm::after { content: ' ❄'; }
.opp.flash, .me-slot.flash { animation: flash 0.6s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 rgba(255, 200, 61, 0.9); } 100% { box-shadow: 0 0 0 16px rgba(255, 200, 61, 0); } }

.middle { display: flex; justify-content: center; align-items: flex-start; gap: clamp(1rem, 4vw, 3rem); flex-wrap: wrap; }
.slot { position: relative; display: flex; flex-direction: column; align-items: center; gap: 0.5rem; border-radius: 24px; padding: 0.5rem; }
.slot-label { font-weight: 600; color: var(--muted); font-size: 0.95rem; }
.card-holder.big { width: clamp(220px, 30vw, 340px); }
.me-slot .slot-label { color: var(--accent2); }
.mode-hotpotato .center-slot { display: none; }
.mode-poisoned .me-slot .card-holder.big { width: clamp(150px, 18vw, 210px); }
.mode-hotpotato .me-slot .card-holder.big { width: clamp(220px, 28vw, 320px); }
.lock {
  position: absolute; inset: 0; display: grid; place-items: center; border-radius: 24px;
  background: rgba(140, 200, 255, 0.18); backdrop-filter: blur(1px); pointer-events: none;
}
.lock span { background: #1f5f99; color: #fff; padding: 0.4rem 0.8rem; border-radius: 99px; font-weight: 600; }
.locked .center-slot .card, .locked .opp .card { filter: saturate(0.4); }
.shake { animation: shake 0.4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.instruction { text-align: center; color: var(--muted); max-width: 640px; margin: 0 auto; line-height: 1.4; }
.instruction b { color: var(--ink); }

.scoreboard { padding: 0.5rem 1rem 1rem 0; }
.scoreboard h3 { margin: 0.5rem 0 0.6rem; font-size: 1rem; }
.scoreboard h3 small { color: var(--muted); font-weight: 400; }
.sb-row { display: flex; align-items: center; gap: 0.45rem; padding: 0.4rem 0.55rem; border-radius: 10px; margin-bottom: 0.3rem; background: rgba(0, 0, 0, 0.18); font-size: 0.95rem; }
.sb-row.me { background: rgba(255, 200, 61, 0.15); }
.sb-row.offline { opacity: 0.5; }
.sb-row .rk { color: var(--muted); width: 1.1rem; }
.sb-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* toasts */
.toast-zone { position: fixed; top: 64px; left: 50%; transform: translateX(-50%); display: grid; gap: 0.4rem; z-index: 30; pointer-events: none; width: min(420px, calc(100vw - 32px)); }
.toast { background: rgba(20, 16, 50, 0.92); border: 1px solid var(--panel-b); padding: 0.55rem 0.9rem; border-radius: 12px; text-align: center; box-shadow: var(--shadow); animation: tin 0.2s ease-out; transition: opacity 0.4s, transform 0.4s; }
.toast.good { border-color: var(--good); }
.toast.bad { border-color: var(--bad); }
.toast.warn { border-color: var(--accent2); }
.toast.info { border-color: #7cc4ff; }
.toast.out { opacity: 0; transform: translateY(-6px); }
.toast .ts { font-size: 1.3rem; vertical-align: middle; }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } }

/* overlay */
.overlay { position: fixed; inset: 0; background: rgba(10, 8, 30, 0.72); display: grid; place-items: center; z-index: 40; padding: 16px; }
.overlay-box { background: #2a2266; border: 1px solid var(--panel-b); border-radius: 22px; padding: 1.5rem 1.75rem; width: min(480px, 100%); text-align: center; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto; }
.overlay-box h2 { margin: 0.25rem 0 0.5rem; }
.ov-emoji { font-size: 3rem; }
.countdown { background: transparent; border: 0; box-shadow: none; }
.cd-mode { font-size: 1.4rem; color: var(--accent2); font-weight: 600; }
.cd-num { font-size: 7rem; font-weight: 700; line-height: 1.1; animation: pop 0.3s; }
.cd-hint { color: var(--muted); max-width: 420px; margin: 0 auto; }
.cd-hint b { color: var(--ink); }
.rank { list-style: none; padding: 0; margin: 1rem 0; display: grid; gap: 0.35rem; text-align: left; }
.rank li { display: flex; gap: 0.6rem; align-items: center; padding: 0.5rem 0.75rem; border-radius: 12px; background: rgba(0, 0, 0, 0.2); }
.rank li.me { background: rgba(255, 200, 61, 0.16); }
.rank .pl { width: 1.8rem; text-align: center; font-size: 1.2rem; }
.rank .nm { flex: 1; }
.rank small { color: var(--muted); }
.ov-actions { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }

/* ---------- responsive ---------- */
@media (max-width: 1050px) {
  .lobby-grid { grid-template-columns: 1fr 1fr; }
  .chat-panel { grid-column: 1 / -1; max-height: 320px; }
}
@media (max-width: 820px) {
  #screen-game.active { grid-template-columns: 1fr; }
  .scoreboard { padding: 0 1rem 1.5rem; }
  .game-info .muted { display: none; }
}
@media (max-width: 640px) {
  .lobby-grid { grid-template-columns: 1fr; padding: 0 16px 1.5rem; }
  .topbar { padding: 0.6rem 16px; }
  .table { padding: 0.25rem 16px 1rem; gap: 0.75rem; }
  .brand.small { font-size: 1.1rem; }
  .card-holder.big { width: min(42vw, 260px); }
  .middle { gap: 0.5rem; flex-wrap: nowrap; }
  .opponents { grid-template-columns: repeat(auto-fit, minmax(72px, 92px)); gap: 0.5rem; }
  .opponents.targets { grid-template-columns: repeat(auto-fit, minmax(118px, 150px)); }
  .opp { padding: 0.35rem; }
  .opp-head { font-size: 0.75rem; }
  .logo h1 { font-size: 2.4rem; }
  /* target modes: keep your card / the centre card pinned while you scan opponents */
  .mode-hotpotato .middle, .mode-poisoned .middle {
    order: -1; position: sticky; top: 0; z-index: 5; padding: 0.4rem 0;
    background: linear-gradient(rgba(27, 23, 64, 0.97) 85%, rgba(27, 23, 64, 0));
  }
  .mode-hotpotato .me-slot .card-holder.big { width: min(44vw, 200px); }
  .mode-poisoned .center-slot .card-holder.big { width: min(40vw, 190px); }
  .mode-poisoned .me-slot .card-holder.big { width: min(24vw, 110px); }
  .slot { padding: 0.25rem; gap: 0.3rem; }
  .slot-label { font-size: 0.8rem; text-align: center; }
  .room-code { font-size: 2.2rem; }
}
