:root {
  --bg: #14141c;
  --bg-2: #1c1c28;
  --fg: #eaeaea;
  --fg-muted: #8a8aa0;
  --accent: #64a0ff;
  --accent-2: #9bff9b;
  --error: #ff8888;
  --slot: #2a3a2a;
  --slot-border: #5a7a5a;
  --keyword: #64a0ff;
  --success: #3a5a3a;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif;
  min-height: 100vh;
}

.appbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid #2a2a3a;
  position: sticky; top: 0; z-index: 10;
}
.appbar .brand { font-weight: 600; }
.appbar .progress { flex: 1; color: var(--fg-muted); font-size: 13px; }
.appbar .ref-toggle {
  background: transparent; color: var(--fg); border: 1px solid #3a3a4a;
  padding: 6px 12px; border-radius: var(--radius); cursor: pointer;
}
.appbar .ref-toggle:hover { background: #252535; }

#main {
  max-width: 760px; margin: 0 auto; padding: 16px;
  display: flex; flex-direction: column; gap: 16px;
}

/* Dialogue bubbles */
.dialogue-stream { display: flex; flex-direction: column; gap: 10px; }
.bubble {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 10px 12px; background: var(--bg-2); border-radius: var(--radius);
  max-width: 92%;
}
.bubble.client { align-self: flex-start; border-left: 3px solid var(--accent); }
.bubble.boss   { align-self: flex-start; border-left: 3px solid #c97; }
.bubble.hint   { align-self: flex-start; border-left: 3px solid var(--error); background: #2a1e1e; }
.bubble.success{ align-self: flex-start; border-left: 3px solid var(--accent-2); background: #1e2a1e; }
.bubble .speaker { font-weight: 600; color: var(--fg-muted); font-size: 12px; letter-spacing: 0.5px; }
.bubble .text { margin-top: 2px; }

/* Puzzle */
.puzzle-area { background: var(--bg-2); padding: 16px; border-radius: var(--radius); }
.puzzle-header { font-size: 12px; color: var(--fg-muted); letter-spacing: 1px; margin-bottom: 10px; }
.query {
  font-family: 'SF Mono', ui-monospace, Consolas, monospace;
  font-size: 14px; line-height: 2;
  white-space: pre-wrap;
}
.token.keyword { color: var(--keyword); font-weight: 600; }
.token.text    { color: var(--fg); }
.blank select {
  background: var(--slot); color: var(--accent-2); border: 1px solid var(--slot-border);
  padding: 2px 8px; border-radius: 4px; font-family: inherit; font-size: inherit;
}
.run-btn {
  margin-top: 14px; padding: 8px 18px; background: var(--success); color: #cff0cf;
  border: none; border-radius: var(--radius); font-weight: 600; cursor: pointer;
}
.run-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.run-btn:hover:not(:disabled) { background: #4a6a4a; }
.next-btn {
  margin-top: 14px; padding: 8px 18px; background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius); font-weight: 600; cursor: pointer;
}

/* Results */
.results-area { background: var(--bg-2); padding: 10px 16px; border-radius: var(--radius); min-height: 60px; }
.results-area:empty::before { content: "Results appear here after you run your query."; color: var(--fg-muted); font-style: italic; }
.results-table { width: 100%; border-collapse: collapse; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.results-table th, .results-table td { padding: 4px 8px; border-bottom: 1px solid #2a2a3a; text-align: left; }
.results-table th { color: var(--fg-muted); font-weight: 500; letter-spacing: 0.5px; }

/* Reference drawer */
.ref-drawer {
  position: fixed; top: 0; right: -420px; width: 420px; height: 100vh;
  background: var(--bg-2); border-left: 1px solid #2a2a3a;
  transition: right 0.2s ease; z-index: 20; display: flex; flex-direction: column;
}
.ref-drawer[aria-hidden="false"] { right: 0; }
.ref-drawer header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid #2a2a3a; }
.ref-drawer h2 { margin: 0; font-size: 16px; }
.ref-drawer #ref-close { background: transparent; color: var(--fg); border: none; font-size: 22px; cursor: pointer; }
.ref-nav { padding: 8px 16px; border-bottom: 1px solid #2a2a3a; display: flex; flex-wrap: wrap; gap: 6px; }
.ref-nav button {
  background: #252535; color: var(--fg); border: 1px solid #3a3a4a; padding: 4px 10px; border-radius: 4px; font-size: 12px; cursor: pointer;
}
.ref-nav button[aria-current="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.ref-content { padding: 16px; overflow-y: auto; }
.ref-content pre { background: #0f0f16; padding: 8px; border-radius: 4px; overflow-x: auto; }
.ref-content code { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }

/* Responsive: reference drawer fills screen on narrow */
@media (max-width: 600px) {
  .ref-drawer { width: 100vw; right: -100vw; }
}

/* Word-bank mode */
.slot {
  display: inline-block;
  min-width: 60px;
  padding: 2px 10px;
  margin: 0 2px;
  border-radius: 4px;
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  transition: background 0.1s;
}
.slot.empty {
  background: transparent;
  color: var(--fg-muted);
  border: 1px dashed var(--slot-border);
}
.slot.filled {
  background: var(--slot);
  color: var(--accent-2);
  border: 1px solid var(--slot-border);
}
.slot.filled:hover { background: #364a36; }

/* Typing mode */
.typed-input {
  display: inline-block;
  min-width: 60px;
  padding: 2px 8px;
  margin: 0 2px;
  border-radius: 4px;
  font-family: inherit;
  font-size: inherit;
  background: var(--slot);
  color: var(--accent-2);
  border: 1px solid var(--slot-border);
}
.typed-input::placeholder {
  color: var(--fg-muted);
  font-style: italic;
}
.typed-input:focus {
  outline: none;
  background: #364a36;
  border-color: var(--accent-2);
}

.word-bank {
  margin-top: 18px;
  padding: 10px 12px;
  background: #0f0f16;
  border-radius: 4px;
}
.word-bank-label {
  font-size: 10px;
  letter-spacing: 1.5px;
  color: var(--fg-muted);
  margin-bottom: 8px;
}
.word-bank-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.word-bank-chip {
  background: #2a2a3f;
  color: #c8c8e6;
  border: 1px solid #3a3a55;
  padding: 3px 10px;
  border-radius: 12px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.1s, transform 0.05s;
}
.word-bank-chip:hover { background: #3a3a55; }
.word-bank-chip:active { transform: scale(0.97); }
