:root {
  --bg: #0f172a;
  --panel: #111827;
  --card: #1f2937;
  --muted: #a8b6ce;
  --text: #f6f9ff;
  --accent: #9f65ff;
  --accent-2: #06b6d4;
  --border: #1f2937;
  --success: #22c55e;
  --danger: #ef4444;
  font-family: 'Manrope', 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; background: radial-gradient(circle at 20% 20%, #0b1222, #0f172a 45%), radial-gradient(circle at 80% 0%, #1b1f34, transparent 45%), var(--bg); min-height: 100vh; }

.page { max-width: 1200px; margin: 0 auto; padding: 24px; }
.top-bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; padding: 12px 16px; border-radius: 14px; background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08); backdrop-filter: blur(6px); }
.room-info { flex: 1; text-align: center; font-weight: 700; letter-spacing: 0.02em; color: var(--text); }
.room-visibility-line {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-start;
  margin: 0 0 16px;
  padding: 0 24px;
  max-width: 1200px;
  width: 100%;
}
.room-visibility-line.hidden { display: none; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.timer { font-weight: 700; color: var(--accent); text-shadow: 0 0 12px rgba(159,101,255,0.45); }
.timer.critical { color: var(--danger); font-size: 24px; animation: pulse 1s infinite; }
.small { padding: 8px 12px; font-size: 14px; }

.panel { background: var(--panel); border: 1px solid rgba(255,255,255,0.06); border-radius: 18px; padding: 24px; }
.hidden { display: none; }
.hero { display: flex; justify-content: space-between; gap: 24px; align-items: center; margin-bottom: 20px; }
.hero h1 { margin: 8px 0 4px; font-size: 32px; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.05em; font-size: 12px; color: var(--accent-2); margin: 0; }
.lede { color: var(--muted); margin-top: 0; }

.card { background: var(--card); border-radius: 14px; padding: 16px; border: 1px solid rgba(255,255,255,0.05); box-shadow: 0 12px 40px rgba(0,0,0,0.25); }
.card h2, .card h3 { margin-top: 0; }
.room-visibility-line label {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--text);
  font-size: 13px;
}
.room-visibility-line input[type="checkbox"] { width: 18px; height: 18px; }
label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 14px; }
input, select, button, textarea { font: inherit; }
input, select, textarea { background: #0b1221; color: var(--text); border: 1px solid rgba(255,255,255,0.08); border-radius: 10px; padding: 10px 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); }
button { cursor: pointer; border: none; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; padding: 12px 14px; border-radius: 12px; font-weight: 700; }
button.secondary { background: none; border: 1px solid rgba(255,255,255,0.08); color: var(--text); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
code { font-family: 'JetBrains Mono', 'SFMono-Regular', ui-monospace, monospace; font-size: 13px; padding: 2px 6px; border-radius: 6px; background: rgba(255,255,255,0.08); display: inline-block; margin-top: 4px; }
#createForm button, #joinForm button { margin-top: 12px; width: 100%; }
#createForm input[name="roomName"] { width: min(220px, 100%); }
#joinForm input[name="roomName"] { width: min(220px, 100%); }
.lobby-card { display: flex; flex-direction: column; gap: 14px; }
.lobby-hero { display: flex; align-items: center; gap: 16px; }
.lobby-hero-art { flex: 0 0 auto; display: flex; align-items: center; }
.lobby-hero-copy { flex: 1; display: flex; align-items: center; }
.lobby-hero-copy h2 { margin: 0; }
.lobby-hero-img { width: 56px; height: 56px; border-radius: 18px; box-shadow: 0 8px 20px rgba(0,0,0,0.45); flex-shrink: 0; }
.lobby-options { display: flex; flex-wrap: wrap; gap: 16px; align-items: stretch; }
.option-card { background: rgba(15,23,42,0.7); border: 1px solid rgba(255,255,255,0.05); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; flex: 1 1 260px; }
.option-card h3 { margin: 0; }
.lobby-divider { align-self: center; border: 1px dashed rgba(255,255,255,0.08); border-radius: 999px; padding: 10px 14px; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; color: var(--muted); flex: 0 0 auto; display: flex; align-items: center; justify-content: center; min-width: 64px; }

.columns { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.main { display: flex; flex-direction: column; gap: 16px; }
.sidebar { display: flex; flex-direction: column; gap: 16px; }
.room-footer { margin-top: 12px; text-align: center; }
.room-footer button { font-size: 12px; }
.public-rooms-card { margin-top: 16px; }
#publicRoomsList { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
#publicRoomsList li { border: 1px solid rgba(255,255,255,0.05); border-radius: 12px; padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; background: rgba(15,23,42,0.65); }
.public-room-name { font-weight: 600; }
.public-room-count { color: var(--muted); font-size: 13px; }
.public-room-join { background: none; border: none; color: inherit; width: 100%; text-align: left; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0; font: inherit; cursor: pointer; }
.public-room-join:hover .public-room-name { color: var(--accent-2); }

#playersList { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
#playersList li { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,0.03); position: relative; overflow: hidden; }
.player-row { gap: 8px; }
.player-name { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.player-enter { animation: playerEnter 0.35s ease forwards; }
.player-leave { animation: playerLeave 0.35s ease forwards; pointer-events: none; }
.badge { background: rgba(159,101,255,0.12); color: var(--accent); padding: 2px 8px; border-radius: 999px; font-size: 12px; border: 1px solid rgba(159,101,255,0.6); }
.submitted { color: var(--success); font-size: 12px; }

.stage-card { padding: 18px; background: var(--card); border-radius: 14px; border: 1px solid rgba(255,255,255,0.05); box-shadow: 0 12px 40px rgba(0,0,0,0.25); }
.stage-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.letter { font-size: 48px; font-weight: 700; color: #f7ba3e; text-shadow: 0 0 16px rgba(247,186,62,0.45); }
.categories { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.category-label { font-size: 14px; color: #f1f5f9; font-weight: 600; margin-bottom: 4px; letter-spacing: 0.02em; }
.room-visibility-banner { font-size: 13px; color: var(--muted); margin: 4px 0 0; text-align: left; }
.room-visibility-banner.hidden { display: none; }
.room-visibility-inline { display: inline-flex; align-items: center; gap: 6px; justify-content: flex-start; width: 100%; }
.room-visibility-inline label { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.room-visibility-inline input[type="checkbox"] { width: 18px; height: 18px; }
.room-visibility-inline .visibility-message { margin: 0; color: var(--text); font-size: 13px; }

.voting-answers { display: grid; gap: 10px; }
.answer-card { padding: 12px; border-radius: 12px; background: rgba(255,255,255,0.04); display: flex; justify-content: space-between; align-items: center; gap: 10px; transition: background 0.2s ease, box-shadow 0.2s ease; }
.answer-card.pending-vote {
  background: rgba(51, 10, 19, 0.6);
  box-shadow: inset 0 0 0 2px rgba(248, 113, 113, 0.8), 0 0 18px rgba(248, 113, 113, 0.4);
}
.answer-card.duplicate { opacity: 0.55; text-decoration: line-through; }
.answer-card.is-self { opacity: 0.9; border: 1px solid rgba(159,101,255,0.4); box-shadow: 0 0 18px rgba(159,101,255,0.25); }
.answer-card.is-self .answer-content { position: relative; padding-top: 4px; }
.answer-card.is-self .answer-meta { background: rgba(159,101,255,0.12); padding: 6px 10px; border-radius: 12px; box-shadow: inset 0 0 0 1px rgba(159,101,255,0.2); }
.answer-card.is-self .score-badge { min-width: 70px; font-size: 20px; letter-spacing: 0.05em; }
.answer-content { display: flex; flex-direction: column; gap: 6px; }
.answer-text { font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.answer-owner { text-transform: uppercase; font-size: 11px; letter-spacing: 0.08em; color: var(--accent-2); }
.answer-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.score-label { text-transform: uppercase; font-size: 10px; letter-spacing: 0.08em; }
.score-badge { min-width: 48px; text-align: center; padding: 4px 10px; border-radius: 999px; font-weight: 700; display: inline-flex; justify-content: center; transition: transform 0.2s ease, background 0.2s ease, color 0.2s ease, box-shadow 0.2s ease; }
.score-badge.positive { background: rgba(34,197,94,0.18); color: var(--success); }
.score-badge.negative { background: rgba(239,68,68,0.18); color: var(--danger); }
.score-badge.score-up { transform: scale(1.15); box-shadow: 0 0 10px rgba(34,197,94,0.4); }
.score-badge.score-down { transform: scale(1.15); box-shadow: 0 0 10px rgba(239,68,68,0.4); }
.score-badge[data-self="1"] { background: rgba(255,255,255,0.12); color: #fff; }
.score-badge[data-self="1"].score-up { box-shadow: 0 0 20px rgba(34,197,94,0.5); }
.score-badge[data-self="1"].score-down { box-shadow: 0 0 20px rgba(239,68,68,0.5); }
.score-badge.own-score-pulse { animation: ownPulse 0.9s ease; }
.answer-actions { display: flex; gap: 6px; }
.answer-card.is-self .answer-actions { opacity: 0.5; }
.answer-actions button { padding: 8px 10px; border-radius: 10px; transition: transform 0.2s ease, box-shadow 0.2s ease; }
.answer-actions button.active { transform: scale(1.05); box-shadow: 0 0 0 2px rgba(255,255,255,0.35); }
.answer-actions .yes.active { box-shadow: 0 0 0 2px rgba(34,197,94,0.55); }
.answer-actions .no.active { box-shadow: 0 0 0 2px rgba(239,68,68,0.55); }
.answer-actions .yes { background: var(--success); }
.answer-actions .no { background: var(--danger); }

.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.pill { background: rgba(255,255,255,0.05); padding: 4px 8px; border-radius: 999px; font-size: 12px; color: var(--muted); }
.chat-log { min-height: 180px; max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 6px 0; }
.chat-line { display: flex; gap: 8px; }
.chat-name { color: var(--accent-2); font-weight: 600; font-size: 13px; }
.chat-text { color: var(--text); font-size: 13px; }
.chat-line.system {
  justify-content: center;
  font-style: italic;
  color: #fde68a;
}
.chat-line.system .chat-system {
  color: inherit;
  font-size: 13px;
}
.chat-form { display: flex; gap: 8px; margin-top: 8px; }
.chat-form input { flex: 1; }

.result-list { display: grid; gap: 8px; }
.result-item { display: flex; justify-content: space-between; padding: 10px 12px; border-radius: 10px; background: rgba(255,255,255,0.04); }
.winner-title {
  margin-bottom: 12px;
  font-weight: 600;
  font-size: 1.1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #f7c948;
}
.winner-title.tie {
  color: #ffed8a;
}
.result-item.first {
  background: rgba(255,215,0,0.25);
  color: #ffe680;
  border: 1px solid rgba(255,215,0,0.65);
  box-shadow: 0 0 22px rgba(255,215,0,0.35);
}
.result-item.second {
  background: rgba(208,214,230,0.18);
  color: #dfe6ff;
  border: 1px solid rgba(208,214,230,0.6);
  box-shadow: 0 0 14px rgba(208,214,230,0.2);
}
.result-item.third {
  background: rgba(139,69,19,0.32);
  color: #ffd1a0;
  border: 1px solid rgba(139,69,19,0.65);
  box-shadow: 0 0 14px rgba(139,69,19,0.3);
}
.result-item.first strong,
.result-item.second strong,
.result-item.third strong {
  color: inherit;
}

.note { color: var(--muted); font-size: 13px; }
.share-url { color: var(--text); margin: 6px 0; word-break: break-all; font-family: inherit; font-size: 14px; }

body.modal-open { overflow: hidden; }

.modal-root { position: fixed; inset: 0; display: none; align-items: center; justify-content: center; padding: 24px; background: rgba(2, 6, 23, 0.78); backdrop-filter: blur(6px); z-index: 2000; }
.modal-root.open { display: flex; }
.modal-surface { width: min(480px, 100%); background: var(--panel); border-radius: 18px; border: 1px solid rgba(255,255,255,0.12); box-shadow: 0 40px 120px rgba(0,0,0,0.55); padding: 20px; display: flex; flex-direction: column; gap: 12px; position: relative; }
.modal-surface[data-variant="danger"] { border-color: rgba(239,68,68,0.75); box-shadow: 0 40px 120px rgba(239,68,68,0.35); }
.modal-surface:focus { outline: none; }
.modal-header { display: flex; flex-direction: column; gap: 4px; }
.modal-header h3 { margin: 0; font-size: 20px; }
.modal-description { margin: 0; color: var(--muted); font-size: 14px; }
.modal-description:empty { display: none; }
.modal-body { font-size: 15px; color: var(--text); display: flex; flex-direction: column; gap: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(255,255,255,0.06);
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: none;
  color: var(--text);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  font-weight: 600;
  padding: 0;
}
.modal-close:hover { background: rgba(255,255,255,0.18); }
.copy-field { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.copy-field input { flex: 1; background: rgba(15,23,42,0.9); cursor: text; }
.copy-field button { white-space: nowrap; }
button.danger { background: var(--danger); }

@keyframes pulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes playerEnter {
  0% { opacity: 0; transform: translateX(12px); }
  100% { opacity: 1; transform: translateX(0); }
}

@keyframes playerLeave {
  0% { opacity: 1; transform: translateX(0); max-height: 52px; margin-bottom: 8px; }
  100% { opacity: 0; transform: translateX(-12px); max-height: 0; margin-bottom: 0; padding-top: 0; padding-bottom: 0; }
}

@media (max-width: 960px) {
  .columns { grid-template-columns: 1fr; }
  .top-bar { flex-direction: column; align-items: flex-start; gap: 6px; }
}

@media (max-width: 640px) {
  .room-info {
    text-align: center;
    width: 100%;
    background: rgba(15, 23, 42, 0.85);
    padding: 10px 14px;
    border-radius: 14px;
    margin-bottom: 6px;
    font-size: 18px;
    letter-spacing: 0.04em;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  }
}

@media (max-width: 720px) {
  .lobby-divider {
    flex-basis: 100%;
  }
}

.invite-link #createForm,
.invite-link #lobbyDivider,
.invite-link #joinRoomField {
  display: none !important;
}

button.link-button {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  padding: 4px 8px;
  border-radius: 6px;
  font-weight: 500;
}

button.link-button:hover {
  color: var(--text);
  background: rgba(255,255,255,0.03);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.results-enter .stage-card {
  animation: resultsPop 0.8s ease forwards;
}

.results-enter .result-item {
  opacity: 0;
  transform: translateY(12px);
  animation: resultRow 0.55s ease forwards;
}

.results-enter .result-item:nth-child(1) { animation-delay: 0.15s; }
.results-enter .result-item:nth-child(2) { animation-delay: 0.23s; }
.results-enter .result-item:nth-child(3) { animation-delay: 0.31s; }
.results-enter .result-item:nth-child(4) { animation-delay: 0.39s; }
.results-enter .result-item:nth-child(5) { animation-delay: 0.47s; }
.results-enter .result-item:nth-child(6) { animation-delay: 0.55s; }
.results-enter .result-item:nth-child(7) { animation-delay: 0.63s; }
.results-enter .result-item:nth-child(8) { animation-delay: 0.71s; }
.results-enter .result-item:nth-child(9) { animation-delay: 0.79s; }
.results-enter .result-item:nth-child(10) { animation-delay: 0.87s; }

.results-enter .letter {
  animation: glowPulse 1.2s ease forwards;
}

@keyframes resultsPop {
  0% { opacity: 0; transform: translateY(24px) scale(0.96); }
  60% { opacity: 1; transform: translateY(-4px) scale(1.02); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes resultRow {
  0% { opacity: 0; transform: translateY(12px); }
  100% { opacity: 1; transform: translateY(0); }
}

@keyframes glowPulse {
  0% { box-shadow: 0 0 0 rgba(247,186,62,0); }
  50% { box-shadow: 0 0 25px rgba(247,186,62,0.5); }
  100% { box-shadow: 0 0 0 rgba(247,186,62,0); }
}
.score-badge.own-score-pulse { animation: ownPulse 0.9s ease; }

@keyframes ownPulse {
  0% { transform: scale(1); box-shadow: 0 0 0 rgba(159,101,255,0); }
  40% { transform: scale(1.25); box-shadow: 0 0 25px rgba(159,101,255,0.6); }
  100% { transform: scale(1); box-shadow: 0 0 0 rgba(159,101,255,0); }
}
.voting-answers.entering .answer-card {
  opacity: 0;
  transform: translateX(8px);
  animation: voteIn 0.35s ease forwards;
}
.voting-answers.leaving .answer-card {
  animation: voteOut 0.25s ease forwards;
}

@keyframes voteIn {
  0% { opacity: 0; transform: translateX(12px); }
  100% { opacity: 1; transform: translateX(0); }
}

@keyframes voteOut {
  0% { opacity: 1; transform: translateX(0); }
  100% { opacity: 0; transform: translateX(-12px); }
}
