:root {
  --bg: #121212;
  --surface: #1e1e1e;
  --primary: #6366f1;
  --text: #ffffff;
  --text-dim: #a1a1aa;
  --success: #22c55e;
  --gold: #fbbf24;
  --danger: #ef4444;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Screen Management */
.screen {
  display: none;
  height: 100%;
  width: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.screen.active {
  display: flex;
}
.screen.no-padding {
  padding: 0;
}

/* Inputs & Buttons */
.input-group {
  width: 100%;
  max-width: 300px;
  margin-bottom: 15px;
}
input {
  width: 100%;
  padding: 15px;
  background: var(--surface);
  border: 1px solid #333;
  color: white;
  border-radius: 8px;
  font-size: 16px;
  outline: none;
}
input:disabled {
  background: #151515;
  color: #555;
  cursor: not-allowed;
}

button {
  width: 100%;
  max-width: 300px;
  padding: 15px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: bold;
  font-size: 16px;
  cursor: pointer;
  transition: opacity 0.2s;
}
button:disabled {
  background: #333;
  color: #777;
  cursor: not-allowed;
}
button:active {
  opacity: 0.8;
}

.btn-secondary {
  background: #333;
  color: #ccc;
  width: auto;
  padding: 8px 15px;
  font-size: 14px;
  margin: 0;
}

/* Lobby */
.lobby-header {
  width: 100%;
  max-width: 400px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 40px;
}
.room-display {
  display: flex;
  flex-direction: column;
  align-items: center;
}
.room-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 2px;
  font-weight: bold;
}
#lobby-room-code {
  font-size: 3.5rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  font-family: monospace;
}

#player-list {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 30px;
  flex-grow: 1;
  overflow-y: auto;
}
.player-card {
  background: var(--surface);
  padding: 15px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid #333;
}
.admin-badge {
  color: var(--gold);
  font-size: 1.2rem;
}
input#gameId {
  text-transform: uppercase;
}

/* Game UI */
#game-ui {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}
#top-bar {
  padding: 10px 15px;
  background: var(--surface);
  text-align: center;
  border-bottom: 1px solid #333;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
#secret-word {
  font-size: 1.5rem;
  font-weight: bold;
  letter-spacing: 3px;
  font-family: monospace;
}
#role-text {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
}

/* --- CANVAS AREA (MODIFIED FOR ASPECT RATIO) --- */
#canvas-wrapper {
  flex-grow: 1;
  position: relative;
  background: #0a0a0a; /* Dark background to show letterboxing */
  overflow: hidden;
  display: flex; /* Added to help center content if needed */
  align-items: center;
  justify-content: center;
}
#canvas-container {
  width: 100%;
  height: 100%;
  /* Flexbox centers the canvas element within the container */
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}
#canvas-container.locked {
  cursor: not-allowed;
  opacity: 0.8;
}

canvas {
  display: block;
  background-color: #ffffff;
  /* Add a distinct border or shadow so users know where the board ends */
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

/* The Clear Button */
#btn-clear {
  position: absolute;
  top: 10px;
  right: 10px;
  width: auto;
  padding: 8px 15px;
  background: var(--danger);
  font-size: 12px;
  display: none;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
  z-index: 10;
}

/* Chat */
#chat-container {
  height: 35%;
  min-height: 180px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  border-top: 1px solid #333;
}
#messages {
  flex-grow: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
}
.msg-system {
  color: var(--gold);
  font-style: italic;
  font-size: 0.9em;
}
.msg-chat {
  color: var(--text);
}
.msg-correct {
  color: var(--success);
  font-weight: bold;
}
.msg-danger {
  color: var(--danger);
  font-weight: bold;
}

#chat-form {
  display: flex;
  border-top: 1px solid #333;
}
#chat-form input {
  border-radius: 0;
  border: none;
  background: #252525;
}
#chat-form button {
  width: auto;
  border-radius: 0;
  padding: 0 25px;
}

/* Overlay */
#overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
  backdrop-filter: blur(5px);
}
.hidden {
  display: none !important;
}
.overlay-content {
  background: var(--surface);
  padding: 30px;
  border-radius: 16px;
  text-align: center;
  width: 90%;
  max-width: 400px;
  border: 2px solid var(--primary);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  animation: popIn 0.3s ease-out;
}
#overlay-title {
  font-size: 2.5rem;
  margin-bottom: 10px;
  color: var(--success);
}
#overlay-word-reveal {
  font-size: 1.5rem;
  margin: 20px 0;
  color: white;
  font-family: monospace;
}
#overlay-msg {
  color: var(--text-dim);
}
#game-title {
  margin-bottom: 20px;
}

@keyframes popIn {
  from {
    transform: scale(0.8);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
