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

:root {
  --bg: #0d0d0f;
  --surface: #16181c;
  --surface2: #1e2028;
  --border: #2a2d36;
  --accent: #c8a05a;
  --accent2: #7b5ea7;
  --text: #e8e0d0;
  --text-dim: #8a8070;
  --dm-color: #c8a05a;
  --p1-color: #5a9ec8;
  --p2-color: #7bc87b;
  --danger: #c85a5a;
  --success: #5ac87b;
  --radius: 8px;
  --font: 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── LOBBY ── */
#lobby {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 2rem;
  gap: 2rem;
}

.lobby-title {
  font-size: 3rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--accent);
  text-shadow: 0 0 40px #c8a05a44;
  font-family: var(--font-mono);
}

.lobby-subtitle {
  color: var(--text-dim);
  font-size: 0.95rem;
  margin-top: -1rem;
}

.lobby-cards {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem 2rem;
  min-width: 300px;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.card h2 {
  font-size: 1.1rem;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

/* ── FORM ELEMENTS ── */
label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.25rem;
}

input, select, textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

select option { background: var(--surface); }

btn, .btn {
  display: inline-block;
  padding: 0.6rem 1.25rem;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: var(--font);
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: #0d0d0f;
}

.btn-primary:hover:not(:disabled) { opacity: 0.88; }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) { border-color: var(--accent); }

.btn-ready {
  background: var(--success);
  color: #0d0d0f;
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.scenario-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 200px;
  overflow-y: auto;
}

.scenario-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.scenario-item:hover { border-color: var(--accent); }
.scenario-item.selected { border-color: var(--accent); background: #c8a05a11; }
.scenario-item .sc-name { font-size: 0.9rem; }
.scenario-item .sc-desc { font-size: 0.75rem; color: var(--text-dim); margin-top: 0.15rem; }

.password-reveal {
  background: var(--surface2);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.password-reveal .code { font-family: var(--font-mono); font-size: 1.4rem; color: var(--accent); letter-spacing: 0.1em; }
.password-reveal .pass { font-family: var(--font-mono); font-size: 1.2rem; color: var(--p2-color); margin-top: 0.25rem; }
.password-reveal small { color: var(--text-dim); font-size: 0.75rem; display: block; margin-top: 0.5rem; }

/* ── GAME SCREEN ── */
#game {
  display: none;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

#game.active { display: flex; }

.game-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-shrink: 0;
}

.game-header .room-code {
  font-family: var(--font-mono);
  color: var(--accent);
  font-size: 0.85rem;
}

.player-badges {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.badge {
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-p1 { background: #5a9ec822; color: var(--p1-color); border: 1px solid var(--p1-color); }
.badge-p2 { background: #7bc87b22; color: var(--p2-color); border: 1px solid var(--p2-color); }
.badge-offline { opacity: 0.4; }

/* Scene image */
.scene-image-wrap {
  width: 100%;
  flex-shrink: 0;
  background: #000;
  position: relative;
  max-height: 30vh;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scene-image-wrap img {
  width: 100%;
  object-fit: cover;
  max-height: 30vh;
  display: block;
}

.scene-placeholder {
  width: 100%;
  height: 160px;
  background: linear-gradient(135deg, #16181c 0%, #1e2028 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.image-loading {
  position: absolute;
  bottom: 0.5rem;
  right: 0.75rem;
  background: #0008;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  color: var(--text-dim);
  display: none;
}

/* Main game area */
.game-body {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 0;
}

/* Narrative panel */
.narrative-panel {
  flex: 1.5;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  min-width: 0;
}

.narrative-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.msg {
  max-width: 100%;
  line-height: 1.6;
}

.msg-dm {
  color: var(--dm-color);
  font-size: 0.95rem;
  white-space: pre-wrap;
}

.msg-dm .msg-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.25rem;
  opacity: 0.6;
}

.msg-p1 .msg-label { color: var(--p1-color); }
.msg-p2 .msg-label { color: var(--p2-color); }

.msg-system {
  color: var(--text-dim);
  font-size: 0.8rem;
  font-style: italic;
  text-align: center;
}

.msg-p1 { color: var(--p1-color); }
.msg-p2 { color: var(--p2-color); }

.thinking-dots::after {
  content: '●●●';
  animation: blink 1.2s infinite;
  font-size: 0.8rem;
}

@keyframes blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 1; }
}

/* Player panels */
.players-panel {
  width: 320px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.player-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.player-panel:last-child { border-bottom: none; }

.player-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.dot-p1 { background: var(--p1-color); }
.dot-p2 { background: var(--p2-color); }
.dot-offline { background: var(--text-dim); }

.other-action-preview {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  min-height: 2.5rem;
  flex: 1;
  font-style: italic;
}

.my-panel {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

textarea.action-input {
  flex: 1;
  resize: none;
  min-height: 80px;
  font-size: 0.9rem;
  line-height: 1.5;
}

.dice-row {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.btn-dice {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-dim);
  padding: 0.3rem 0.6rem;
  font-size: 0.8rem;
  cursor: pointer;
  font-family: var(--font-mono);
  transition: border-color 0.15s, color 0.15s;
}

.btn-dice:hover { border-color: var(--accent); color: var(--accent); }

.ready-status {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: center;
  padding: 0.25rem;
}

.ready-status.both-ready { color: var(--success); }

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 1.25rem;
  font-size: 0.9rem;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
}

.toast.show { opacity: 1; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Utils */
.hidden { display: none !important; }
.text-dim { color: var(--text-dim); }
.mt-05 { margin-top: 0.5rem; }
.gap-05 { gap: 0.5rem; }

/* Upload area */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.upload-area:hover, .upload-area.drag { border-color: var(--accent); color: var(--accent); }

.upload-area input[type=file] {
  display: none;
}

@media (max-width: 700px) {
  .game-body { flex-direction: column; }
  .players-panel { width: 100%; flex-direction: row; border-top: 1px solid var(--border); }
  .player-panel { border-right: 1px solid var(--border); border-bottom: none; }
  .player-panel:last-child { border-right: none; }
  .narrative-panel { border-right: none; }
}
