@import url('https://fonts.googleapis.com/css2?family=Courier+Prime:ital,wght@0,400;0,700;1,400&display=swap');

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

:root {
  --bg: #0d0d0d;
  --surface: #141414;
  --surface2: #1c1c1c;
  --border: #2a2620;
  --accent: #c9a84c;
  --accent-dim: #8a6c2a;
  --text: #e8e0d0;
  --text-dim: #7a7060;
  --text-muted: #4a4438;
  --error: #c04040;
  --success: #4a8c4a;
  --font: 'Courier Prime', 'Courier New', monospace;
  --max-w: 480px;
}

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

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

#app {
  width: 100%;
  max-width: var(--max-w);
  min-height: 100%;
  position: relative;
  display: flex;
  flex-direction: column;
}

/* ── Screens ── */

.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  min-height: 100vh;
}

.screen.active {
  display: flex;
}

/* ── Loading ── */

#screen-loading {
  justify-content: center;
  align-items: center;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: var(--text-dim);
  font-size: 14px;
  letter-spacing: 0.1em;
}

/* ── Age Gate ── */

#screen-age-gate {
  justify-content: center;
  align-items: center;
  padding: 32px 24px;
}

.age-gate-content {
  max-width: 380px;
  text-align: center;
}

.age-gate-title {
  font-size: 13px;
  letter-spacing: 0.4em;
  color: var(--error);
  margin-bottom: 24px;
  font-weight: 700;
}

.age-gate-message {
  font-size: 15px;
  color: var(--text-dim);
  line-height: 1.7;
  margin-bottom: 40px;
}

.age-gate-buttons {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Outside Hours ── */

#screen-outside-hours {
  justify-content: center;
  align-items: center;
  padding: 32px 24px;
  text-align: center;
}

.outside-hours-title {
  font-size: 13px;
  letter-spacing: 0.4em;
  color: var(--accent-dim);
  margin-bottom: 20px;
  font-weight: 400;
}

.outside-hours-message {
  font-size: 15px;
  color: var(--text-dim);
  line-height: 1.7;
  max-width: 340px;
  margin-bottom: 40px;
}

.countdown {
  font-size: 40px;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: 8px;
}

.countdown-label {
  font-size: 12px;
  letter-spacing: 0.3em;
  color: var(--text-muted);
  text-transform: lowercase;
}

/* ── Chat Screen ── */

#screen-chat {
  padding: 0;
  height: 100vh;
  overflow: hidden;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.npc-name {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
  margin-bottom: 2px;
}

.npc-title {
  font-size: 12px;
  color: var(--accent);
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.npc-location {
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.clue-counter {
  font-size: 13px;
  color: var(--text-dim);
  white-space: nowrap;
  padding-top: 2px;
}

.clue-counter.found {
  animation: clue-flash 0.6s ease;
}

@keyframes clue-flash {
  0%, 100% { color: var(--text-dim); }
  50% { color: var(--accent); }
}

/* ── Message List ── */

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  -webkit-overflow-scrolling: touch;
}

.message-list::-webkit-scrollbar {
  width: 4px;
}

.message-list::-webkit-scrollbar-track {
  background: transparent;
}

.message-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.msg {
  max-width: 88%;
  line-height: 1.65;
  font-size: 15px;
}

.msg-user {
  align-self: flex-end;
  color: var(--text-dim);
  border-right: 2px solid var(--accent-dim);
  padding-right: 12px;
  text-align: right;
}

.msg-npc {
  align-self: flex-start;
  color: var(--text);
}

.msg-npc .msg-sender {
  display: block;
  font-size: 11px;
  color: var(--accent);
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

/* ── Status Bars ── */

.ending-warning {
  text-align: center;
  font-size: 12px;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  padding: 8px 18px;
  font-style: italic;
  flex-shrink: 0;
}

.ending-warning.hidden { display: none; }

.chat-ended {
  text-align: center;
  font-size: 13px;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-ended.hidden { display: none; }

/* ── Chat Input ── */

.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.message-input {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  padding: 10px 14px;
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 120px;
  transition: border-color 0.15s;
}

.message-input:focus {
  border-color: var(--accent-dim);
}

.message-input::placeholder {
  color: var(--text-muted);
}

.message-input:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.send-btn {
  background: var(--accent);
  color: var(--bg);
  border: none;
  border-radius: 4px;
  width: 44px;
  height: 44px;
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-btn:hover:not(:disabled) {
  background: #d9b85c;
}

.send-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ── Typing indicator ── */

.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 6px 0;
}

.typing-indicator span {
  width: 5px;
  height: 5px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typing-bounce 1.2s ease-in-out infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Game Complete ── */

#screen-game-complete {
  justify-content: center;
  align-items: center;
  padding: 32px 24px;
}

.game-complete-content {
  max-width: 380px;
  text-align: center;
}

.game-complete-title {
  font-size: 13px;
  letter-spacing: 0.35em;
  color: var(--accent);
  margin-bottom: 24px;
  font-weight: 400;
}

.game-complete-hint {
  font-size: 15px;
  color: var(--text-dim);
  line-height: 1.7;
  margin-bottom: 36px;
  font-style: italic;
}

.password-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.password-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--font);
  font-size: 18px;
  padding: 14px 18px;
  text-align: center;
  letter-spacing: 0.15em;
  outline: none;
  text-transform: uppercase;
  transition: border-color 0.15s;
}

.password-input:focus {
  border-color: var(--accent-dim);
}

.password-error {
  font-size: 13px;
  color: var(--error);
  letter-spacing: 0.05em;
}

.password-error.hidden { display: none; }

/* ── Win Screen ── */

#screen-win {
  justify-content: center;
  align-items: center;
  padding: 32px 24px;
  text-align: center;
  position: relative;
}

.win-content {
  max-width: 380px;
  position: relative;
  z-index: 1;
}

.win-title {
  font-size: 13px;
  letter-spacing: 0.4em;
  color: var(--accent);
  margin-bottom: 28px;
  font-weight: 400;
}

.win-message {
  font-size: 15px;
  color: var(--text-dim);
  line-height: 1.8;
  font-style: italic;
}

#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}

/* ── Buttons ── */

.btn {
  padding: 14px 24px;
  font-family: var(--font);
  font-size: 14px;
  letter-spacing: 0.1em;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  min-height: 44px;
}

.btn-primary {
  background: var(--accent);
  color: var(--bg);
}

.btn-primary:hover {
  background: #d9b85c;
}

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

.btn-secondary:hover {
  color: var(--text-dim);
  border-color: var(--text-muted);
}

/* ── Toast ── */

.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  font-size: 14px;
  padding: 10px 20px;
  border-radius: 4px;
  letter-spacing: 0.05em;
  white-space: nowrap;
  z-index: 100;
  animation: toast-in 0.25s ease;
}

.toast.hidden {
  display: none;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── Error state ── */

.error-screen {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 32px 24px;
  text-align: center;
}

.error-screen p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.7;
  max-width: 320px;
}

/* ── Clue word chips ── */

.clue-word-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  justify-content: flex-end;
}

.clue-chip {
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--accent);
  border: 1px solid var(--accent-dim);
  border-radius: 2px;
  padding: 2px 6px;
  background: transparent;
  white-space: nowrap;
}

.clue-chip-new {
  animation: chip-appear 0.5s ease;
}

@keyframes chip-appear {
  from { opacity: 0; transform: translateY(-4px) scale(0.9); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
