/* ── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-void:    #0a0a0c;
  --bg-deep:    #111115;
  --bg-surface: #1a1a22;
  --bg-raised:  #22222e;
  --border:     #2e2e3e;
  --border-dim: #1e1e28;

  --gold-bright: #c9a84c;
  --gold-dim:    #7a6230;
  --gold-faint:  #3a2e18;

  --blood:       #8b1a1a;
  --blood-dim:   #4a0f0f;
  --ash:         #6b6b7a;
  --ash-bright:  #9b9baa;
  --text-main:   #d4d4cc;
  --text-dim:    #888880;
  --text-bright: #eeeedc;

  --player1:     var(--gold-bright);
  --player2:     #c47c3a;

  --font-serif:  'Georgia', 'Times New Roman', serif;
  --font-mono:   'Courier New', monospace;

  --radius:      4px;
  --radius-lg:   8px;
}

html, body {
  height: 100%;
  background: var(--bg-void);
  color: var(--text-main);
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* ── Layout ─────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 800px;
  margin: 0 auto;
  border-left: 1px solid var(--border-dim);
  border-right: 1px solid var(--border-dim);
}

/* ── Header ─────────────────────────────────────────────── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-deep);
  border-bottom: 1px solid var(--gold-dim);
  flex-shrink: 0;
}

#game-title {
  font-size: 1.1rem;
  font-weight: normal;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-bright);
  text-shadow: 0 0 12px rgba(201, 168, 76, 0.3);
}

#reset-btn {
  background: none;
  border: 1px solid var(--blood-dim);
  color: var(--ash);
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-family: var(--font-serif);
  transition: all 0.2s;
}
#reset-btn:hover {
  border-color: var(--blood);
  color: var(--text-main);
}

/* ── Player Selector ────────────────────────────────────── */
#player-bar {
  display: flex;
  gap: 1px;
  background: var(--border-dim);
  flex-shrink: 0;
}

.player-btn {
  flex: 1;
  padding: 8px;
  background: var(--bg-surface);
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--ash);
  font-family: var(--font-serif);
  font-size: 0.85rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.2s;
}
.player-btn:hover {
  background: var(--bg-raised);
  color: var(--text-main);
}
.player-btn.active[data-player="Knight"] {
  background: var(--gold-faint);
  color: var(--gold-bright);
  border-bottom: 2px solid var(--gold-bright);
}
.player-btn.active[data-player="Squire"] {
  background: #2a1a0a;
  color: var(--player2);
  border-bottom: 2px solid var(--player2);
}

/* ── Chat Log ───────────────────────────────────────────── */
#chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

#chat-log::-webkit-scrollbar { width: 4px; }
#chat-log::-webkit-scrollbar-track { background: transparent; }
#chat-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ── Messages ───────────────────────────────────────────── */
.message {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  gap: 4px;
}

.message-label {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ash);
  padding-left: 2px;
}

.message-content {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 0.95rem;
  line-height: 1.65;
}

/* GM messages — left aligned */
.gm-message { align-self: flex-start; }
.gm-message .message-label { color: var(--ash); }
.gm-message .message-content {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold-dim);
  color: var(--text-main);
}

/* Player messages — right aligned */
.player-message {
  align-self: flex-end;
  align-items: flex-end;
}
.player-message .message-content {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-bright);
}
.player-message[data-player="Knight"] .message-label { color: var(--player1); }
.player-message[data-player="Knight"] .message-content {
  border-right: 3px solid var(--gold-dim);
}
.player-message[data-player="Squire"] .message-label { color: var(--player2); }
.player-message[data-player="Squire"] .message-content {
  border-right: 3px solid #6b3a1a;
}

/* Markdown in GM messages */
.message-content p { margin-bottom: 0.5em; }
.message-content p:last-child { margin-bottom: 0; }
.message-content em { color: var(--ash-bright); font-style: italic; }
.message-content strong { color: var(--gold-bright); }
.message-content ul, .message-content ol { padding-left: 1.4em; margin-bottom: 0.5em; }
.message-content li { margin-bottom: 0.2em; }
.message-content code {
  background: var(--bg-void);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.85em;
}
.message-content hr { border: none; border-top: 1px solid var(--border); margin: 0.8em 0; }
.message-content blockquote {
  border-left: 3px solid var(--gold-dim);
  padding-left: 12px;
  color: var(--ash-bright);
  font-style: italic;
  margin: 0.5em 0;
}
.message-content h1,
.message-content h2,
.message-content h3 {
  color: var(--gold-bright);
  font-size: 1em;
  margin: 0.6em 0 0.3em;
}

/* Streaming cursor */
.streaming-cursor::after {
  content: '\25CA';
  animation: blink 0.8s step-end infinite;
  color: var(--gold-dim);
  margin-left: 2px;
}
@keyframes blink { 50% { opacity: 0; } }

/* Error state */
.error-message .message-content {
  border-left-color: var(--blood);
  color: #cc7777;
}

/* ── Input Area ─────────────────────────────────────────── */
#input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-deep);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  align-items: flex-end;
}

#message-input {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-main);
  font-family: var(--font-serif);
  font-size: 0.95rem;
  padding: 10px 14px;
  resize: none;
  min-height: 44px;
  max-height: 140px;
  line-height: 1.5;
  transition: border-color 0.2s;
}
#message-input:focus {
  outline: none;
  border-color: var(--gold-dim);
}
#message-input::placeholder {
  color: var(--text-dim);
  font-style: italic;
}

#send-btn {
  background: var(--gold-faint);
  border: 1px solid var(--gold-dim);
  color: var(--gold-bright);
  padding: 10px 18px;
  border-radius: var(--radius-lg);
  font-family: var(--font-serif);
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  min-height: 44px;
  transition: all 0.2s;
  white-space: nowrap;
}
#send-btn:hover {
  background: #3a2e18;
  border-color: var(--gold-bright);
}
#send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 480px) {
  #game-title { font-size: 0.95rem; }
  .message { max-width: 95%; }
  #chat-log { padding: 12px; gap: 12px; }
  #input-area { padding: 10px 12px; }
}
