/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0a0a0f;
  --surface: #14141f;
  --surface2: #1e1e2e;
  --text: #e0e0e8;
  --text-dim: #8888a0;
  --accent: #7c6ff7;
  --accent-glow: rgba(124, 111, 247, 0.3);
  --success: #4caf50;
  --warning: #ff9800;
  --danger: #f44336;
  --radius: 8px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'Courier New', monospace;
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: var(--font); }
input, select, textarea { font-family: var(--font); }

/* ===== LAYOUT ===== */
.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.page { min-height: 100vh; display: flex; flex-direction: column; }
.page-header {
  text-align: center;
  padding: 2rem 1rem 1rem;
}
.page-header h1 {
  font-size: 2rem;
  letter-spacing: 0.05em;
}
.page-header .subtitle {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

/* ===== LANDING PAGE ===== */
.landing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-top: 2rem;
}

.room-card {
  background: var(--surface);
  border: 1px solid #2a2a3a;
  border-radius: var(--radius);
  padding: 1.5rem;
  transition: transform 0.2s, border-color 0.2s;
  display: flex;
  flex-direction: column;
}
.room-card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
}
.room-card h3 { font-size: 1.15rem; margin-bottom: 0.25rem; }
.room-card .room-subtitle { color: var(--text-dim); font-size: 0.85rem; margin-bottom: 0.75rem; }
.room-card .room-desc { font-size: 0.9rem; flex: 1; margin-bottom: 1rem; }
.room-card .room-link {
  display: inline-block;
  padding: 0.5rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.85rem;
  text-align: center;
}
.room-card .room-link:hover { text-decoration: none; opacity: 0.9; }

.control-card {
  background: linear-gradient(135deg, var(--surface), var(--surface2));
  border: 2px solid var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
}

/* ===== ROOM THEMES ===== */
.theme-clocktower {
  --room-accent: #cd7f32;
  --room-accent-glow: rgba(205, 127, 50, 0.3);
  --room-bg: #1a1408;
  --room-surface: #2a2010;
}
.theme-greenhouse {
  --room-accent: #4caf50;
  --room-accent-glow: rgba(76, 175, 80, 0.3);
  --room-bg: #081a08;
  --room-surface: #102a10;
}
.theme-observatory {
  --room-accent: #5c6bc0;
  --room-accent-glow: rgba(92, 107, 192, 0.3);
  --room-bg: #080818;
  --room-surface: #101028;
}
.theme-submersible {
  --room-accent: #0097a7;
  --room-accent-glow: rgba(0, 151, 167, 0.3);
  --room-bg: #081418;
  --room-surface: #0e2028;
}

[class*="theme-"] {
  background: var(--room-bg);
}
[class*="theme-"] .room-header {
  border-bottom: 2px solid var(--room-accent);
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
[class*="theme-"] .room-header h1 {
  font-size: 1.4rem;
  color: var(--room-accent);
}

/* ===== CONNECTION BAR ===== */
.connection-bar {
  background: var(--surface);
  border-bottom: 1px solid #2a2a3a;
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.connection-bar label { font-size: 0.85rem; color: var(--text-dim); }
.connection-bar input {
  background: var(--bg);
  border: 1px solid #3a3a4a;
  color: var(--text);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  font-size: 1rem;
  width: 8em;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-family: var(--mono);
}
.connection-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--danger);
}
.status-dot.connected { background: var(--success); }
.status-dot.connecting { background: var(--warning); animation: pulse 1s infinite; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1.25rem;
  border: 1px solid #3a3a4a;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.15s, border-color 0.15s;
}
.btn:hover { background: var(--surface2); border-color: #5a5a6a; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { opacity: 0.9; }
.btn-success { background: var(--success); border-color: var(--success); color: #fff; }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #000; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.btn-block { width: 100%; justify-content: center; }

/* ===== CONTROL ROOM ===== */
.session-display {
  text-align: center;
  padding: 1.5rem;
  background: var(--surface);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}
.session-code {
  font-family: var(--mono);
  font-size: 3rem;
  font-weight: bold;
  letter-spacing: 0.3em;
  color: var(--accent);
  text-shadow: 0 0 15px var(--accent-glow);
}
.session-label {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
}

.control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.status-card {
  background: var(--surface);
  border: 1px solid #2a2a3a;
  border-radius: var(--radius);
  padding: 1rem;
}
.status-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid #2a2a3a;
}
.status-card-header h3 { font-size: 1rem; }
.status-card .status-badge {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 1rem;
  font-weight: 600;
}

.badge-waiting { background: #333; color: var(--text-dim); }
.badge-active { background: rgba(76,175,80,0.2); color: var(--success); }
.badge-paused { background: rgba(255,152,0,0.2); color: var(--warning); }
.badge-completed { background: rgba(124,111,247,0.2); color: var(--accent); }
.badge-disconnected { background: rgba(244,67,54,0.2); color: var(--danger); }

.progress-bar {
  height: 6px;
  background: #2a2a3a;
  border-radius: 3px;
  overflow: hidden;
  margin: 0.5rem 0;
}
.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.3s;
}

.timer-display {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: bold;
}

.game-controls {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

/* ===== HINT PANEL ===== */
.hint-panel {
  background: var(--surface);
  border: 1px solid #2a2a3a;
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1.25rem;
}
.hint-panel h3 { font-size: 1rem; margin-bottom: 0.75rem; }

.hint-request {
  background: var(--surface2);
  border: 1px solid #3a3a4a;
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.hint-request .room-name { font-weight: 600; color: var(--warning); }
.hint-actions { display: flex; gap: 0.5rem; }

.hint-compose {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.hint-compose select,
.hint-compose input {
  flex: 1;
  background: var(--bg);
  border: 1px solid #3a3a4a;
  color: var(--text);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
}

/* ===== EVENT LOG ===== */
.event-log {
  background: var(--surface);
  border: 1px solid #2a2a3a;
  border-radius: var(--radius);
  max-height: 300px;
  overflow-y: auto;
}
.event-log-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #2a2a3a;
  font-weight: 600;
  font-size: 0.9rem;
  position: sticky;
  top: 0;
  background: var(--surface);
}
.event-entry {
  padding: 0.4rem 1rem;
  border-bottom: 1px solid #1a1a2a;
  font-size: 0.8rem;
  display: flex;
  gap: 0.75rem;
}
.event-entry:last-child { border-bottom: none; }
.event-time { color: var(--text-dim); font-family: var(--mono); white-space: nowrap; }
.event-room { color: var(--accent); font-weight: 600; min-width: 5em; }
.event-msg { flex: 1; }

/* ===== PUZZLE AREA ===== */
.puzzle-container {
  flex: 1;
  padding: 1.5rem;
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
}
.puzzle-card {
  background: var(--room-surface, var(--surface));
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
}
.puzzle-card h2 {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
  color: var(--room-accent, var(--accent));
}
.puzzle-card .flavor-text {
  color: var(--text-dim);
  font-style: italic;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.puzzle-card .puzzle-body { margin-bottom: 1rem; }

.puzzle-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
.puzzle-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid #3a3a4a;
  color: var(--text);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: var(--mono);
  text-transform: uppercase;
}
.puzzle-input:focus { outline: none; border-color: var(--room-accent, var(--accent)); }

.puzzle-feedback {
  margin-top: 0.75rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  display: none;
}
.puzzle-feedback.correct {
  display: block;
  background: rgba(76,175,80,0.15);
  color: var(--success);
  border: 1px solid rgba(76,175,80,0.3);
}
.puzzle-feedback.incorrect {
  display: block;
  background: rgba(244,67,54,0.15);
  color: var(--danger);
  border: 1px solid rgba(244,67,54,0.3);
}

.puzzle-locked {
  text-align: center;
  color: var(--text-dim);
  padding: 2rem;
  font-size: 0.95rem;
}

.puzzle-solved-badge {
  display: inline-block;
  background: rgba(76,175,80,0.2);
  color: var(--success);
  padding: 0.2rem 0.75rem;
  border-radius: 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  margin-left: 0.5rem;
}

/* ===== PUZZLE PROGRESS ===== */
.puzzle-progress {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--room-surface, var(--surface));
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.puzzle-pip {
  width: 2rem; height: 2rem;
  border-radius: 50%;
  background: #2a2a3a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  transition: background 0.3s;
}
.puzzle-pip.active {
  background: var(--room-accent, var(--accent));
  color: #fff;
  box-shadow: 0 0 10px var(--room-accent-glow, var(--accent-glow));
}
.puzzle-pip.solved { background: var(--success); color: #fff; }

/* ===== HINT REQUEST (room side) ===== */
.room-hint-bar {
  padding: 0.75rem 1.5rem;
  background: var(--room-surface, var(--surface));
  border-top: 1px solid rgba(255,255,255,0.05);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.hint-message {
  background: rgba(255,152,0,0.1);
  border: 1px solid rgba(255,152,0,0.3);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  color: var(--warning);
  font-size: 0.9rem;
  animation: slideDown 0.3s ease;
}

/* ===== WAITING / COMPLETION SCREENS ===== */
.waiting-screen, .complete-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}
.waiting-screen h2, .complete-screen h2 {
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
}
.waiting-screen p { color: var(--text-dim); }
.complete-screen .time-result {
  font-family: var(--mono);
  font-size: 2.5rem;
  font-weight: bold;
  color: var(--success);
  margin: 1rem 0;
}

/* ===== SLIDER PUZZLE ===== */
.slider-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.slider-row label { min-width: 8em; font-size: 0.9rem; }
.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--room-accent, var(--accent));
}
.slider-row .slider-val {
  font-family: var(--mono);
  font-weight: bold;
  min-width: 2em;
  text-align: center;
}

/* ===== GRID PUZZLE ===== */
.bit-grid {
  display: inline-grid;
  gap: 2px;
  margin: 0.5rem 0;
}
.bit-cell {
  width: 40px; height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-weight: bold;
  font-size: 1rem;
  border: 1px solid #3a3a4a;
  border-radius: 4px;
  background: var(--surface2);
  cursor: pointer;
  transition: background 0.15s;
}
.bit-cell:hover { background: #2e2e4e; }
.bit-cell.toggled {
  background: var(--room-accent, var(--accent));
  color: #fff;
}

/* ===== DRAG-DROP (valve sort) ===== */
.valve-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0.75rem 0;
}
.valve-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  background: var(--surface2);
  border: 1px solid #3a3a4a;
  border-radius: var(--radius);
  cursor: grab;
  user-select: none;
}
.valve-item:active { cursor: grabbing; }
.valve-item .valve-label { font-weight: 600; min-width: 1.5em; }
.valve-item .valve-pressure { font-family: var(--mono); color: var(--text-dim); }
.valve-item.dragging { opacity: 0.4; }
.valve-item.drag-over { border-color: var(--room-accent, var(--accent)); background: rgba(0,151,167,0.1); }

/* ===== MANUAL SIGNALING MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  display: none;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid #3a3a4a;
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
.modal h3 { margin-bottom: 1rem; }
.modal textarea {
  width: 100%;
  min-height: 100px;
  background: var(--bg);
  border: 1px solid #3a3a4a;
  color: var(--text);
  border-radius: var(--radius);
  padding: 0.5rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  resize: vertical;
}
.modal .btn-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  justify-content: flex-end;
}

/* ===== ANIMATIONS ===== */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.fade-in { animation: fadeIn 0.3s ease; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: #3a3a4a; border-radius: 3px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .control-grid { grid-template-columns: 1fr; }
  .landing-grid { grid-template-columns: 1fr; }
  .session-code { font-size: 2rem; }
  .connection-bar { flex-direction: column; align-items: stretch; }
  .game-controls { flex-direction: column; }
  .timer-display { font-size: 1.2rem; }
}
