*,
*::before,
*::after {
  box-sizing: border-box;
}

:root {
  --bg: #f3f3f6;
  --bg-panel: #ffffff;
  --border-subtle: #dedee6;
  --accent: #4b7bec;
  --accent-soft: rgba(75, 123, 236, 0.15);
  --text-main: #1f2933;
  --text-muted: #6b7280;
  --danger: #e74c3c;
  --radius-panel: 12px;
  --radius-button: 999px;
  --shadow-soft: 0 8px 20px rgba(15, 23, 42, 0.08);
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--text-main);
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Top bar */

.top-bar {
  background: #ffffff;
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
  position: sticky;
  top: 0;
  z-index: 20;
}

.top-bar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
}

.top-bar-main {
  gap: 16px;
}

.top-left,
.top-center,
.top-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  font-weight: 700;
  font-size: 1.1rem;
}

.lobby-code {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.round-info {
  font-size: 0.95rem;
}

.word-hint {
  font-family: ui-monospace, Menlo, Monaco, "SF Mono", monospace;
  letter-spacing: 4px;
  background: var(--accent-soft);
  padding: 4px 10px;
  border-radius: 999px;
}

.timer {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: #fafafa;
  font-size: 0.85rem;
}

.timer-value {
  font-weight: 700;
}

.icon-button {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px;
}

.top-bar-status {
  border-top: 1px solid var(--border-subtle);
  background: #fafafe;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Main layout */

.main-layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) 320px;
  gap: 12px;
  padding: 12px;
  flex: 1;
  min-height: 0;
}

/* Panels and sidebars */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

/* Make the players panel take most of the left column height */
.players-panel {
  flex: 1;
  min-height: 0;
}

.tools-panel {
  flex: 0 0 auto;
}

.panel {
  background: var(--bg-panel);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-subtle);
  padding: 10px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.panel-header h2 {
  font-size: 0.95rem;
  margin: 0;
}

.player-count {
  font-size: 0.8rem;
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
}

/* Player list */

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.player-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-radius: 8px;
  font-size: 0.85rem;
}

.player-item.current {
  background: var(--accent-soft);
}

.player-item.guessed {
  background: rgba(34, 197, 94, 0.10); /* soft green background */
}

.player-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}

.player-info {
  display: flex;
  flex-direction: column;
}

.player-name {
  font-weight: 600;
}

.player-score {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.player-guess-status {
  margin-left: auto;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
}

/* Tools */

.tools-panel {
  font-size: 0.85rem;
}

.tools-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tool-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tool-button {
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  padding: 4px 8px;
  background: #fafafa;
  cursor: pointer;
  font-size: 0.9rem;
}

.tool-button.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

.tool-button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.brush-size-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brush-size-row label {
  font-size: 0.8rem;
  white-space: nowrap;
}

.brush-size-row input[type="range"] {
  flex: 1;
}

.color-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.color-swatch {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}

.color-swatch.active {
  border-color: #111827;
}

.tools-note {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Avatar panel */

.avatar-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.avatar-preview {
  width: 120px;
  height: 120px;
}

.avatar-svg {
  width: 100%;
  height: 100%;
}

.avatar-head {
  fill: #ffd9c0;
  stroke: #111827;
  stroke-width: 4;
}

.avatar-eye {
  fill: #111827;
}

.avatar-mouth,
.avatar-body,
.avatar-leg,
.avatar-arm {
  fill: none;
  stroke: #111827;
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Canvas */

.canvas-area {
  min-height: 0;
}

.canvas-wrapper {
  background: var(--bg-panel);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-soft);
  border: 1px solid var(--border-subtle);
  padding: 8px;
  height: 100%;
  display: flex;
  flex-direction: column;
}

#draw-canvas {
  flex: 1;
  display: block;
  width: 100%;
  max-width: 100%;
  border-radius: 10px;
  border: 2px dashed #d1d5db;
  background: #ffffff;
}

/* Overlay (lobby / game over) */

.canvas-overlay {
  position: relative;
  margin-top: 8px;
}

.lobby-card {
  background: #111827;
  color: #e5e7eb;
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}

.lobby-card h1 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 1.2rem;
}

.hint-text {
  margin-top: 8px;
  font-size: 0.8rem;
  color: #d1d5db;
}

/* Chat */

.chat-panel {
  min-height: 0;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  font-size: 0.85rem;
}

.chat-message {
  margin-bottom: 6px;
}

.chat-meta {
  font-weight: 600;
  margin-right: 4px;
}

.chat-system {
  font-style: italic;
  color: var(--text-muted);
}

.chat-input-row {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.chat-input-row input {
  flex: 1;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  padding: 6px 10px;
  font-size: 0.85rem;
}

/* Buttons */

.button {
  border-radius: var(--radius-button);
  padding: 8px 14px;
  border: none;
  font-size: 0.9rem;
  cursor: pointer;
  font-weight: 600;
}

.button.primary {
  background: var(--accent);
  color: #ffffff;
}

.button.secondary {
  background: #f3f4f6;
  color: #111827;
}

.button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Mobile tabs */

.mobile-tabs {
  display: none;
  gap: 4px;
  padding: 6px 8px 0;
}

.mobile-tab-button {
  flex: 1;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  padding: 6px 10px;
  font-size: 0.85rem;
  background: #f9fafb;
  cursor: pointer;
}

.mobile-tab-button.active {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
}

/* Responsive behavior */

@media (max-width: 960px) {
  .main-layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto auto;
  }

  .sidebar-left,
  .sidebar-right {
    order: 2;
  }

  .canvas-area {
    order: 1;
  }

  .canvas-area {
    max-width: 100%;
    overflow: hidden;
  }

  .sidebar-right {
    margin-top: 8px;
  }

  .mobile-tabs {
    display: flex;
  }

  /* Only show one side panel at a time on mobile */
  .sidebar-left,
  .sidebar-right {
    display: none;
  }

  .sidebar-left.active,
  .sidebar-right.active {
    display: flex;
  }

  /* On mobile, show tools above players in the left sidebar */
  #players-panel .tools-panel {
    order: 0;
  }

  #players-panel .players-panel {
    order: 1;
  }
}

@media (max-width: 600px) {
  .top-bar-main {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .top-left,
  .top-center,
  .top-right {
    width: 100%;
    justify-content: space-between;
  }

  .word-hint {
    margin-left: auto;
  }

  .top-bar-status {
    font-size: 0.8rem;
  }
}

/* Join overlay modal */
.join-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex; /* Visible by default; JS will hide it after join */
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.6);
}

.join-card {
  max-width: 420px;
  width: 100%;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.45);
  padding: 20px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.join-card h1 {
  margin: 0 0 8px 0;
  font-size: 1.3rem;
}

.join-label {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 4px;
  display: block;
}

.join-input {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  padding: 8px 12px;
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.join-avatar-section {
  border-radius: 12px;
  border: 1px dashed var(--border-subtle);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  background: #f9fafb;
}

.join-avatar-section h2 {
  margin: 0;
  font-size: 0.95rem;
}

.join-avatar-preview {
  width: 100px;
  height: 100px;
}

.join-subtext {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 4px 0 0 0;
  text-align: center;
}

@media (max-width: 600px) {
  .join-card {
    max-width: 100%;
    border-radius: 12px;
    padding: 16px 14px 14px;
  }
}

/* Podium / Game Results Overlay */
.podium-overlay {
  position: fixed;
  inset: 0;
  display: none; /* JS toggles this */
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.7);
  z-index: 50;
}

.podium-card {
  background: #ffffff;
  border-radius: 12px;
  padding: 1.5rem 1.75rem 1.75rem;
  max-width: 520px;
  width: 90%;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.4);
  text-align: center;
}

.podium-title {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 700;
}

.podium-subtitle {
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
  color: #6b7280;
}

.podium-layout {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.podium-slot {
  flex: 1;
  border-radius: 0.75rem 0.75rem 0 0;
  padding: 0.5rem 0.4rem;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  color: #111827;
}

.podium-first {
  height: 150px;
  background: linear-gradient(180deg, #facc15, #eab308);
}

.podium-second {
  height: 120px;
  background: linear-gradient(180deg, #e5e7eb, #d1d5db);
}

.podium-third {
  height: 100px;
  background: linear-gradient(180deg, #fed7aa, #f97316);
}

.podium-place {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.podium-name {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.15rem;
  word-break: break-word;
}

.podium-score {
  font-size: 0.8rem;
  opacity: 0.9;
}

@media (max-width: 640px) {
  .podium-card {
    padding: 1.25rem 1.25rem 1.5rem;
  }

  .podium-layout {
    gap: 0.5rem;
  }

  .podium-first {
    height: 130px;
  }

  .podium-second {
    height: 110px;
  }

  .podium-third {
    height: 90px;
  }
}

/* Game settings overlay modal */
.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.7);
}

.settings-card {
  width: 100%;
  max-width: 460px;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.45);
  padding: 20px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.settings-card h1 {
  margin: 0 0 8px 0;
  font-size: 1.4rem;
}

.settings-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-field label {
  font-size: 0.9rem;
  font-weight: 600;
}

.settings-hint {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.settings-field input[type="number"],
.settings-field textarea {
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  padding: 8px 10px;
  font-size: 0.9rem;
}

.settings-field textarea {
  resize: vertical;
  min-height: 80px;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

@media (max-width: 600px) {
  .settings-card {
    max-width: 100%;
    border-radius: 12px;
    padding: 16px 14px 14px;
  }
}