:root {
  --bg-1: #1a1f45;
  --bg-2: #0b0d20;
  --panel: rgba(255, 255, 255, 0.055);
  --panel-border: rgba(255, 255, 255, 0.09);
  --text: #eef0ff;
  --muted: #9ba1cc;
  --accent: #ffc940;
  --accent-ink: #2a2000;
  --good: #3ddc97;
  --bad: #ff5c72;
  --reveal: #4de2ff;
  --card: #fffdf8;
  --c-red: #e8364f;
  --c-green: #12a150;
  --c-purple: #7040d8;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Inter, system-ui, sans-serif;
  color: var(--text);
  background: radial-gradient(ellipse at 50% -10%, var(--bg-1), var(--bg-2) 70%) fixed;
  background-color: var(--bg-2);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: Fredoka, Inter, sans-serif; font-weight: 600; margin: 0 0 0.5rem; }
h3 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.12em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
#defs { position: absolute; width: 0; height: 0; }

/* ---------- logo ---------- */
.logo { display: inline-flex; gap: 0.1em; font-family: Fredoka, sans-serif; font-weight: 700; font-size: 1.8rem; text-decoration: none; letter-spacing: 0.02em; }
.logo span:nth-child(1) { color: var(--c-red); }
.logo span:nth-child(2) { color: #1fc46a; }
.logo span:nth-child(3) { color: #9469ff; }
.logo-big { font-size: clamp(4rem, 14vw, 7.5rem); line-height: 1; filter: drop-shadow(0 10px 30px rgba(0,0,0,.4)); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  font: 600 0.95rem Inter, sans-serif; border: 0; border-radius: 999px; cursor: pointer;
  padding: 0.65rem 1.2rem; color: var(--text); transition: transform .12s, background .2s, box-shadow .2s, opacity .2s;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 20px rgba(255, 201, 64, .25); }
.btn-primary:hover { background: #ffd666; }
.btn-ghost { background: rgba(77, 226, 255, 0.12); color: var(--reveal); border: 1px solid rgba(77, 226, 255, .35); }
.btn-ghost:hover { background: rgba(77, 226, 255, 0.2); }
.btn-ghost.active { background: var(--reveal); color: #04222b; }
.btn-subtle { background: rgba(255,255,255,.08); }
.btn-subtle:hover { background: rgba(255,255,255,.14); }
.btn-lg { font-size: 1.1rem; padding: 0.9rem 2rem; }
.btn-block { width: 100%; margin-top: 0.75rem; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---------- home ---------- */
#home { max-width: 960px; margin: 0 auto; padding: 4rem 16px 3rem; }
.hero { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 1.2rem; }
.tagline { font-size: 1.15rem; max-width: 34rem; color: var(--muted); line-height: 1.6; margin: 0; }
.tagline em { color: var(--text); font-style: normal; font-weight: 600; }
.hint-text { color: var(--muted); font-size: 0.85rem; margin: -0.4rem 0 0; }
.hero-cards { display: flex; gap: 14px; margin: 1rem 0; flex-wrap: wrap; justify-content: center; }
.hero-cards .card { width: 150px; cursor: default; }
.hero-cards .card:nth-child(1) { transform: rotate(-6deg) translateY(6px); }
.hero-cards .card:nth-child(3) { transform: rotate(6deg) translateY(6px); }
.rules { margin-top: 3.5rem; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 20px; padding: 1.6rem 2rem; }
.rules ol { margin: 0; padding-left: 1.2rem; line-height: 1.8; color: #d4d7f2; }

/* ---------- game layout ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 14px 24px; max-width: 1280px; margin: 0 auto; }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; }
.room-chip { font-size: 0.85rem; color: var(--muted); background: var(--panel); border: 1px solid var(--panel-border); padding: 0.4rem 0.8rem; border-radius: 999px; }
.room-chip b { color: var(--text); font-family: ui-monospace, monospace; letter-spacing: 0.05em; }

.layout { display: grid; grid-template-columns: 1fr 290px; gap: 24px; max-width: 1280px; margin: 0 auto; padding: 8px 24px 32px; align-items: start; }
.table { position: relative; display: flex; flex-direction: column; align-items: center; }

.board {
  display: grid; grid-template-rows: repeat(3, auto); grid-auto-flow: column;
  grid-auto-columns: minmax(0, 180px); gap: 16px; justify-content: center; width: 100%;
  padding: 24px; border-radius: 26px;
  background: radial-gradient(ellipse at center, rgba(255,255,255,.05), rgba(255,255,255,.015));
  border: 1px solid var(--panel-border);
  transition: filter .3s, opacity .3s;
}
.board.locked { filter: grayscale(.7) brightness(.7); pointer-events: none; }

/* ---------- cards ---------- */
.card {
  position: relative; aspect-ratio: 3 / 2; width: 100%;
  background: var(--card); border: 0; border-radius: var(--radius); padding: 0;
  display: flex; align-items: center; justify-content: center; gap: 7%;
  box-shadow: 0 1px 0 rgba(255,255,255,.6) inset, 0 6px 16px rgba(0,0,0,.35), 0 2px 4px rgba(0,0,0,.25);
  cursor: pointer; -webkit-tap-highlight-color: transparent;
  transition: transform .16s cubic-bezier(.3,.7,.4,1.4), box-shadow .2s;
}
.card .shape { height: 72%; width: auto; overflow: visible; }
.card:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(0,0,0,.4), 0 2px 4px rgba(0,0,0,.25); }
.card:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
.card.selected {
  transform: translateY(-6px) scale(1.03);
  box-shadow: 0 0 0 4px var(--accent), 0 14px 30px rgba(255, 201, 64, .35);
}
.card.revealed { animation: reveal-pulse 1.6s ease-in-out infinite; }
.card.revealed.selected { animation: none; }
.card.enter { animation: deal .45s cubic-bezier(.2,.8,.3,1.2) both; }
.card.wrong { animation: shake .45s; box-shadow: 0 0 0 4px var(--bad), 0 10px 24px rgba(255,92,114,.4); }
.card.found { box-shadow: 0 0 0 4px var(--good), 0 10px 30px rgba(61,220,151,.5); }

@keyframes deal {
  from { opacity: 0; transform: translateY(-24px) rotateX(50deg) scale(.85); }
  to { opacity: 1; transform: none; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); } 40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); } 80% { transform: translateX(3px); }
}
@keyframes reveal-pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--reveal), 0 0 14px rgba(77,226,255,.35); }
  50% { box-shadow: 0 0 0 5px var(--reveal), 0 0 34px rgba(77,226,255,.7); }
}

.mini-row { display: flex; gap: 8px; }
.mini-row .card { width: 33%; cursor: default; border-radius: 8px; gap: 6%; box-shadow: 0 3px 8px rgba(0,0,0,.3); }
.mini-row .card:hover { transform: none; }
.mini-row .card .shape { height: 70%; }

.lock-banner {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  background: rgba(20, 10, 20, .9); border: 1px solid var(--bad); color: #ffd0d6;
  padding: 0.8rem 1.4rem; border-radius: 999px; font-weight: 600; white-space: nowrap; box-shadow: 0 10px 40px rgba(0,0,0,.5);
}

/* ---------- sidebar ---------- */
.sidebar { display: flex; flex-direction: column; gap: 14px; }
.panel { background: var(--panel); border: 1px solid var(--panel-border); border-radius: 18px; padding: 16px 18px; backdrop-filter: blur(6px); }
.players { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.player { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-radius: 10px; transition: background .3s; }
.player.flash { animation: flash 1.2s; }
@keyframes flash { 0% { background: rgba(61,220,151,.35); } 100% { background: transparent; } }
.avatar { position: relative; flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font: 700 0.95rem Fredoka, sans-serif; color: #10131f; }
.avatar::after { content: ''; position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%; background: #5b6085; border: 2px solid #15183a; }
.player.online .avatar::after { background: var(--good); }
.player:not(.online) { opacity: .55; }
.pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.pname .you { color: var(--muted); font-weight: 400; font-size: 0.8rem; margin-left: 4px; }
.badge { font-size: 0.72rem; padding: 2px 7px; border-radius: 999px; font-weight: 600; }
.badge.vote { background: rgba(77,226,255,.15); color: var(--reveal); }
.badge.lock { background: rgba(255,92,114,.15); color: var(--bad); }
.score { font: 700 1.25rem Fredoka, sans-serif; min-width: 1.6rem; text-align: right; }

.vote-meter, .deck-meter { height: 6px; border-radius: 99px; background: rgba(255,255,255,.08); overflow: hidden; margin-top: 8px; }
#vote-bar { height: 100%; width: 0; background: var(--reveal); transition: width .3s; }
#deck-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--c-red), #1fc46a, #9469ff); transition: width .4s; }
.deck-row { display: flex; justify-content: space-between; align-items: baseline; }
.deck-row h3 { margin: 0; }
#reveal-text { margin: 0; line-height: 1.45; }

/* ---------- dialogs & overlays ---------- */
.dialog {
  border: 1px solid var(--panel-border); border-radius: 22px; padding: 28px; width: min(360px, calc(100vw - 32px));
  background: #181c3d; color: var(--text); box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.dialog::backdrop { background: rgba(5, 6, 18, .7); backdrop-filter: blur(4px); }
.dialog form { display: flex; flex-direction: column; gap: 0.5rem; }
.dialog .logo { justify-content: center; margin-bottom: 0.25rem; }
.dialog h2 { text-align: center; }
.dialog input {
  font: 500 1rem Inter, sans-serif; color: var(--text); background: rgba(255,255,255,.07);
  border: 1px solid var(--panel-border); border-radius: 12px; padding: 0.75rem 0.9rem; width: 100%;
}
.dialog input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.overlay { position: fixed; inset: 0; background: rgba(5, 6, 18, .75); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 20; padding: 16px; animation: fade .3s; }
.overlay-card { background: #181c3d; border: 1px solid var(--panel-border); border-radius: 26px; padding: 32px; width: min(400px, 100%); text-align: center; box-shadow: 0 30px 80px rgba(0,0,0,.6); animation: pop .4s cubic-bezier(.2,.8,.3,1.3); }
.trophy { font-size: 3.5rem; }
.standings { list-style: none; padding: 0; margin: 1rem 0 1.5rem; text-align: left; }
.standings li { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 12px; }
.standings li:first-child { background: rgba(255, 201, 64, .12); }
.standings .rank { width: 1.4rem; color: var(--muted); font-weight: 600; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.9) translateY(10px); } }

.center-view { min-height: 100vh; display: grid; place-items: center; padding: 16px; text-align: center; }
.narrow { max-width: 380px; padding: 28px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; z-index: 30; pointer-events: none; width: calc(100% - 32px); }
.toast {
  display: flex; align-items: center; gap: 12px; background: #23285a; border: 1px solid var(--panel-border);
  padding: 10px 16px; border-radius: 16px; box-shadow: 0 12px 30px rgba(0,0,0,.45); font-weight: 500;
  animation: toast-in .35s cubic-bezier(.2,.8,.3,1.2); max-width: 100%;
}
.toast.good { border-color: rgba(61,220,151,.5); }
.toast.leaving { animation: toast-out .3s forwards; }
.toast .mini-row { width: 150px; flex: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(16px) scale(.95); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(10px); } }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 4px 16px 24px; }
  .sidebar { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
}
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .room-chip { display: none; }
  .board { grid-template-rows: none; grid-auto-flow: row; grid-template-columns: repeat(3, 1fr); grid-auto-columns: auto; gap: 8px; padding: 10px; border-radius: 18px; }
  .card { border-radius: 9px; }
  .card.selected { box-shadow: 0 0 0 3px var(--accent), 0 8px 18px rgba(255, 201, 64, .35); }
  .hero-cards .card { width: 100px; }
  #home { padding-top: 2.5rem; }
  .rules { padding: 1.2rem 1.2rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
