@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Work+Sans:wght@300;400;600;700&display=swap');

:root {
  --bg-0: #0b111a;
  --bg-1: #101827;
  --bg-2: #0f1f3a;
  --card: rgba(17, 26, 43, 0.85);
  --card-strong: rgba(27, 40, 64, 0.95);
  --stroke: rgba(148, 163, 184, 0.25);
  --text: #e6edf7;
  --muted: #9aa8c7;
  --accent: #f97316;
  --accent-2: #38bdf8;
  --accent-3: #a855f7;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --shadow: 0 25px 60px rgba(5, 8, 20, 0.45);
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

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

body {
  min-height: 100vh;
  font-family: 'Work Sans', sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 15% 10%, rgba(56, 189, 248, 0.25), transparent 50%),
              radial-gradient(circle at 85% 15%, rgba(168, 85, 247, 0.18), transparent 45%),
              radial-gradient(circle at 50% 90%, rgba(249, 115, 22, 0.18), transparent 55%),
              linear-gradient(160deg, var(--bg-0), var(--bg-2));
  background-attachment: fixed;
}

a {
  color: inherit;
  text-decoration: none;
}

.muted {
  color: var(--muted);
}

img {
  max-width: 100%;
  display: block;
}

.page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container {
  width: min(1120px, 92vw);
  margin: 0 auto;
  padding: 0 0 80px;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 28px 0 20px;
}

.logo {
  display: flex;
  gap: 10px;
  align-items: center;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  box-shadow: 0 12px 22px rgba(5, 8, 20, 0.35);
}

.logo-badge {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), var(--accent-3));
  display: grid;
  place-items: center;
  box-shadow: 0 12px 22px rgba(248, 113, 113, 0.25);
  font-weight: 700;
  color: #0c111b;
}

.nav-links {
  display: flex;
  gap: 18px;
  font-size: 0.95rem;
  color: var(--muted);
}

.nav-links a:hover {
  color: var(--text);
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.lang-select-wrap {
  display: flex;
  align-items: center;
}

.lang-select {
  background: rgba(17, 26, 43, 0.7);
  border: 1px solid var(--stroke);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.9rem;
}

.lang-select:focus {
  outline: 2px solid rgba(56, 189, 248, 0.6);
  outline-offset: 2px;
}

.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;
}

.text-link {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1px solid rgba(249, 115, 22, 0.5);
  padding-bottom: 2px;
}

.text-link:hover {
  color: #fb923c;
  border-bottom-color: rgba(251, 146, 60, 0.8);
}

.hero {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 28px;
  align-items: center;
  margin-top: 24px;
}

.hero-card {
  background: var(--card);
  border: 1px solid var(--stroke);
  padding: 32px;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.hero-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at top right, rgba(56, 189, 248, 0.2), transparent 60%);
  pointer-events: none;
}

.hero h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(2.2rem, 3.5vw, 3.4rem);
  line-height: 1.05;
  margin-bottom: 16px;
}

.hero p {
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.6;
  margin-bottom: 22px;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.button {
  border: 1px solid transparent;
  padding: 12px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  background: linear-gradient(135deg, var(--accent), #fb923c);
  color: #111827;
}

.button.secondary {
  background: transparent;
  border-color: rgba(148, 163, 184, 0.4);
  color: var(--text);
}

.button.ghost {
  background: rgba(15, 23, 42, 0.4);
  border-color: rgba(148, 163, 184, 0.2);
  color: var(--text);
}

.button:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px rgba(249, 115, 22, 0.25);
}

.section {
  margin-top: 60px;
}

.section h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(1.6rem, 2vw, 2.2rem);
  margin-bottom: 16px;
}

h3 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.35rem;
  margin-bottom: 12px;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 18px;
}

.mode-select {
  margin-top: 18px;
  display: grid;
  gap: 14px;
}

.mode-card {
  text-align: left;
  cursor: pointer;
  width: 100%;
  border: 1px solid var(--stroke);
  background: var(--card);
  color: var(--text);
}

.mode-card .badge {
  align-self: flex-start;
}

.mode-card.selected {
  border-color: rgba(249, 115, 22, 0.75);
  box-shadow: 0 18px 36px rgba(249, 115, 22, 0.3);
  transform: translateY(-4px);
  background: linear-gradient(135deg, rgba(249, 115, 22, 0.12), rgba(17, 26, 43, 0.9));
}

.mode-card.selected .card-title {
  color: #fdba74;
}

.mode-card:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.reveal-meta {
  margin-bottom: 14px;
  font-weight: 600;
  color: var(--muted);
}

.reveal-view {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  align-items: start;
}

.reveal-left img {
  width: 100%;
  border-radius: var(--radius-md);
  display: block;
}

.reveal-right {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 65vh;
  overflow-y: auto;
  padding-right: 6px;
}

.chat-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 90%;
}

.chat-row.right {
  align-self: flex-end;
  text-align: right;
}

.chat-row.left {
  align-self: flex-start;
  text-align: left;
}

.chat-name {
  font-size: 0.8rem;
  color: var(--muted);
}

.chat-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  background: rgba(56, 189, 248, 0.18);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: var(--text);
}

.chat-row.right .chat-bubble {
  background: rgba(249, 115, 22, 0.18);
  border-color: rgba(249, 115, 22, 0.3);
}

.chat-bubble.image {
  padding: 8px;
}

.chat-bubble.image img {
  width: min(360px, 70vw);
  border-radius: 12px;
  display: block;
}

.reveal-entry {
  opacity: 0;
  transform: translateY(8px);
  animation: revealPop 0.45s ease forwards;
}

@keyframes revealPop {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.card {
  background: var(--card);
  border: 1px solid var(--stroke);
  padding: 20px;
  border-radius: var(--radius-lg);
  transition: transform 0.2s ease, border 0.2s ease;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-media {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  border: 1px solid rgba(148, 163, 184, 0.2);
  background: rgba(15, 23, 42, 0.4);
  object-fit: cover;
  display: block;
}

.card:hover {
  transform: translateY(-4px);
  border-color: rgba(56, 189, 248, 0.45);
}

.card-title {
  font-weight: 600;
  font-size: 1.05rem;
}

.card p {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: rgba(56, 189, 248, 0.18);
  color: var(--accent-2);
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.pill {
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.35);
  color: var(--text);
}

.pill.host {
  border-color: rgba(249, 115, 22, 0.6);
  color: #fed7aa;
}

.footer {
  margin-top: auto;
  padding: 32px 0 40px;
  color: var(--muted);
  font-size: 0.9rem;
}

.footer-links {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.page-header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 20px 0 30px;
}

.page-header h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: clamp(2rem, 3vw, 2.8rem);
}

.page-header p {
  color: var(--muted);
  max-width: 720px;
}

.panel {
  background: var(--card-strong);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow);
}

.form-grid {
  display: grid;
  gap: 14px;
}

.input {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(148, 163, 184, 0.25);
  color: var(--text);
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
}

.input:focus {
  outline: 2px solid rgba(56, 189, 248, 0.5);
  border-color: rgba(56, 189, 248, 0.5);
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
}

.notice {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: #bbf7d0;
  font-size: 0.9rem;
}

.notice.warn {
  background: rgba(249, 115, 22, 0.12);
  border-color: rgba(249, 115, 22, 0.3);
  color: #fed7aa;
}

.memorize-preview {
  margin: 12px 0 10px;
  padding: 10px;
}

.memorize-preview img {
  width: 100%;
  border-radius: var(--radius-sm);
  background: #ffffff;
}

.steps {
  display: grid;
  gap: 14px;
}

.step {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.2);
  padding: 14px;
  border-radius: var(--radius-md);
}

.step span {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  background: rgba(56, 189, 248, 0.2);
  display: grid;
  place-items: center;
  font-weight: 700;
}

.canvas-wrap {
  background: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: var(--radius-md);
  padding: 14px;
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
  background: #ffffff;
}

.canvas-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}

.canvas-controls label {
  font-size: 0.85rem;
  color: var(--muted);
}

.color-palette {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.color-swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid rgba(148, 163, 184, 0.4);
  background: var(--swatch, #f97316);
  cursor: pointer;
  padding: 0;
}

.color-swatch.selected {
  border-color: #ffffff;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.6);
}

body[data-game="painting"][data-page="play"] #room-panel,
body[data-game="painting"][data-page="play"] #lobby-panel {
  display: none;
}

body[data-game="painting"][data-page="play"] .container {
  width: min(1440px, 96vw);
}

.chip {
  border: 1px solid rgba(148, 163, 184, 0.35);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  background: rgba(15, 23, 42, 0.6);
}

.timer {
  font-weight: 700;
  color: var(--accent-2);
}

.live-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.live-timer {
  font-size: 1.7rem;
  font-weight: 700;
  color: var(--accent-2);
}

.live-hint {
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 220px;
}

.live-msg {
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
}

.role-card {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(148, 163, 184, 0.35);
  border-radius: var(--radius-md);
}

.role-card.role-spy {
  border-color: rgba(239, 68, 68, 0.6);
  box-shadow: 0 16px 36px rgba(239, 68, 68, 0.2);
}

.role-card.role-impostor {
  border-color: rgba(245, 158, 11, 0.6);
  box-shadow: 0 16px 36px rgba(245, 158, 11, 0.2);
}

.role-card.role-agent {
  border-color: rgba(56, 189, 248, 0.6);
  box-shadow: 0 16px 36px rgba(56, 189, 248, 0.2);
}

.role-line {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 8px;
}

.spy-chat-input {
  flex: 1;
  min-width: 220px;
}

.vote-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.vote-btn {
  width: 100%;
}

.vote-btn.active {
  border-color: rgba(249, 115, 22, 0.6);
  box-shadow: 0 10px 24px rgba(249, 115, 22, 0.2);
}

.result-card h4 {
  font-size: 1.25rem;
  margin-bottom: 10px;
}

.result-card p {
  margin-bottom: 6px;
  color: var(--muted);
}

body[data-game="painting"][data-page="play"] #phase-draw:not(.hide) {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 280px);
}

body[data-game="painting"][data-page="play"] #phase-draw .canvas-wrap {
  flex: 1;
  width: 100%;
  padding: 18px;
}

body[data-game="painting"][data-page="play"] #phase-draw canvas {
  width: 100%;
  min-height: min(72vh, 820px);
  max-height: calc(100vh - 320px);
  object-fit: contain;
}

body[data-game="painting"][data-page="play"] #phase-draw .draw-actions {
  margin-top: auto;
}

body[data-game="painting"][data-page="play"] #phase-draw .timer {
  display: none;
}

body[data-game="connect"][data-page="play"] #room-panel,
body[data-game="connect"][data-page="play"] #lobby-panel {
  display: none;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.score-card {
  background: rgba(15, 23, 42, 0.65);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: var(--radius-md);
  padding: 14px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.hero-logo {
  width: 72px;
  height: 72px;
  display: block;
  margin-bottom: 18px;
  border-radius: 20px;
  box-shadow: 0 16px 28px rgba(5, 8, 20, 0.35);
}

.score-card::before {
  content: '';
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--player-accent, var(--accent));
}

.score-card.active {
  border-color: rgba(56, 189, 248, 0.55);
}

.score-card.winner {
  border-color: rgba(34, 197, 94, 0.55);
}

.score-card-name {
  font-weight: 700;
  margin-bottom: 4px;
}

.score-card-meta {
  color: var(--muted);
  font-size: 0.82rem;
  min-height: 1rem;
}

.score-card-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 2rem;
  margin-top: 8px;
}

.connect-board-wrap {
  overflow: auto;
  padding: 16px;
}

.connect-board {
  display: grid;
  gap: 0;
  justify-content: start;
  align-items: center;
  min-width: max-content;
}

.connect-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e6edf7;
  justify-self: center;
  align-self: center;
}

.connect-line {
  border: 0;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: pointer;
  position: relative;
}

.connect-line:disabled {
  cursor: default;
}

.connect-line::after {
  content: '';
  display: block;
  background: rgba(148, 163, 184, 0.22);
  transition: background 0.2s ease, transform 0.2s ease;
}

.connect-line:not(:disabled):hover::after {
  background: rgba(56, 189, 248, 0.45);
  transform: scale(1.02);
}

.connect-line.claimed::after {
  background: var(--claim-color, var(--accent));
}

.connect-line-h {
  width: clamp(40px, 7vw, 64px);
  height: 18px;
}

.connect-line-h::after {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  margin: 5px 0;
}

.connect-line-v {
  width: 18px;
  height: clamp(40px, 7vw, 64px);
}

.connect-line-v::after {
  width: 8px;
  height: 100%;
  border-radius: 999px;
  margin: 0 5px;
}

.connect-box {
  width: clamp(40px, 7vw, 64px);
  height: clamp(40px, 7vw, 64px);
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  place-items: center;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  color: #0b111a;
}

.connect-box.claimed {
  background: color-mix(in srgb, var(--claim-color, var(--accent)) 78%, white 22%);
}

.timer-danger {
  color: var(--danger);
  animation: timerPulse 0.9s ease-in-out infinite;
}

@keyframes timerPulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.35;
  }
}

.hide {
  display: none;
}

html[dir="rtl"] body {
  direction: rtl;
}

html[dir="rtl"] .nav {
  flex-direction: row-reverse;
}

html[dir="rtl"] .nav-links {
  flex-direction: row-reverse;
}

@media (max-width: 720px) {
  .nav {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .nav-controls {
    width: 100%;
    justify-content: space-between;
  }

  .hero-actions {
    width: 100%;
  }
}
