/* Quest UI — light, card-based desktop layout. */

:root {
  --bg: #f3f4f7;
  --card: #ffffff;
  --line: #e2e4ea;
  --line-strong: #cdd0d9;
  --ink: #1d2129;
  --muted: #757b87;
  --accent: #5457c9;
  --accent-soft: #ecedfd;
  --err: #d3383f;
  --err-soft: #fdf1f1;
  --warn: #b97f14;
  --warn-soft: #fdf6e8;
  --ok: #2f9e63;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 22, 40, .05), 0 4px 16px rgba(20, 22, 40, .06);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-width: 1100px;
}

.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.spring { flex: 1; }
a { color: var(--accent); }
code {
  font-family: var(--mono);
  font-size: .92em;
  background: #f0f1f5;
  border-radius: 4px;
  padding: 0 4px;
}

/* Rich-text editor rendering of expandable blockquotes (collapsed by default, chevron toggles). */
.rt-area blockquote {
  margin: .4em 0;
  padding: .15em .7em;
  border-left: 3px solid var(--line-strong);
}
.rt-area blockquote[expandable] {
  border-left-color: var(--accent);
  position: relative;
  padding-right: 1.6em;
}
.rt-area blockquote[expandable]::after {
  content: "⌃";
  position: absolute;
  top: .05em;
  right: .5em;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.rt-area blockquote[expandable].rt-collapsed {
  max-height: 3.4em;
  overflow: hidden;
  -webkit-mask-image: linear-gradient(180deg, #000 55%, transparent);
          mask-image: linear-gradient(180deg, #000 55%, transparent);
}
.rt-area blockquote[expandable].rt-collapsed::after { content: "⌄"; }
textarea.inp-area { width: 100%; min-height: 5.5em; resize: vertical; line-height: 1.45; padding: 8px 10px; font: inherit; }

/* ---------------------------------- top bar ---------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 22px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar-left { display: flex; align-items: baseline; gap: 12px; }
.logo { font-size: 20px; align-self: center; }

#codename {
  font-size: 20px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 8px;
  outline: none;
  cursor: text;
  border: 1px dashed transparent;
}
#codename:hover { border-color: var(--line-strong); }
#codename:focus { border-color: var(--accent); background: var(--accent-soft); }

#lastEdited { font-size: 12px; }

.topbar-right { display: flex; gap: 10px; }

/* ---------------------------------- buttons ---------------------------------- */

.btn {
  font: inherit;
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
}
.btn:hover { background: #f6f7fb; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #4649b8; }
.btn-ghost { border-style: dashed; color: var(--muted); background: transparent; }
.btn-ghost:hover { color: var(--ink); background: #fbfbfe; }
.btn-icon { padding: 4px 9px; line-height: 1; border-radius: 7px; }
.btn-mini { padding: 2px 9px; font-size: 12px; border-radius: 7px; }
.btn-create { color: var(--accent); border-color: var(--accent); }
.btn-danger { color: #fff; background: var(--err); border-color: var(--err); }
.btn-danger:hover { background: #b92c33; }
.btn-danger-ghost { color: var(--err); }

.badge {
  display: inline-block;
  min-width: 18px;
  padding: 1px 5px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--err);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

/* ----------------------------------- cards ----------------------------------- */

main {
  max-width: 1400px;
  margin: 18px auto 60px;
  padding: 0 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  cursor: pointer;
  user-select: none;
}
.card-icon { font-size: 17px; }
.card-title { font-size: 15px; font-weight: 700; }
.chevron { color: var(--muted); font-size: 13px; }
.card-body { padding: 4px 18px 18px; border-top: 1px solid var(--line); }
.card.collapsed .card-body { display: none; }

.dot { width: 8px; height: 8px; border-radius: 50%; }
.dot.err { background: var(--err); }
.dot.wrn { background: var(--warn); }

.subhead { font-weight: 700; margin: 18px 0 10px; }

/* ---------------------------------- fields ---------------------------------- */

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 22px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 22px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.req { color: var(--err); }
.hint { font-size: 12px; color: var(--muted); }

.inp {
  font: inherit;
  color: var(--ink);
  background: #fbfbfd;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 6px 10px;
  outline: none;
  min-width: 0;
  width: 100%;
}
.inp:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px var(--accent-soft); }
.inp.mono { font-family: var(--mono); font-size: 13px; }
select.inp { width: auto; max-width: 22em; }
.picker { min-width: 12em; }

.inp.invalid, .rt.invalid, .file-box.invalid, [data-vpath].invalid {
  border-color: var(--err) !important;
  background: var(--err-soft);
}
.inp.warnf, .rt.warnf, .file-box.warnf, [data-vpath].warnf {
  border-color: var(--warn) !important;
  background: var(--warn-soft);
}
.flash { animation: flash 1.6s; }
@keyframes flash {
  0%, 60% { box-shadow: 0 0 0 4px rgba(84, 87, 201, .45); }
  100% { box-shadow: none; }
}

fieldset.smtp {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 16px 16px;
}
fieldset.smtp legend { font-size: 12px; color: var(--muted); padding: 0 6px; }

/* participants */
.npc-grid { display: flex; flex-wrap: wrap; gap: 14px; align-items: stretch; }
.npc-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #fcfcfe;
}
.npc-card .row { align-items: flex-end; }
.npc-card .field { flex: 1; }
.npc-add { align-self: center; margin: 8px; }

/* admin keyboard */
.kb-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fcfcfe;
}
.kb-row-label { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.kb-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 6px 8px;
  background: #fff;
}
#sec-adminKeyboard .card-body > .btn-ghost { margin-top: 12px; }

/* ---------------------------------- quest ---------------------------------- */

.quest {
  display: grid;
  grid-template-columns: 390px 1fr;
  height: calc(100vh - 92px);
  min-height: 540px;
  overflow: hidden;
}

.flow-col {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 14px;
  background: #f9f9fc;
  border-radius: var(--radius) 0 0 var(--radius);
}
.details-col { overflow-y: auto; padding: 16px 22px 26px; }

.flow-head { display: flex; justify-content: center; margin-bottom: 14px; }
.flow-search { margin-bottom: 14px; }
.flow-nomatch { text-align: center; padding: 20px 0; }
.flow-list { display: flex; flex-direction: column; align-items: stretch; }
.flow-gap { height: 14px; }

.pill-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 0 0 4px 12px; }
.pill {
  font-size: 11px;
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--accent-soft);
  color: #43469f;
  border: 1px solid #d6d8f6;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pill-warn { background: var(--warn-soft); color: var(--warn); border-color: #ecd9ac; }
.pill-via { background: #f1f2f6; color: var(--muted); border-color: var(--line); }
.pill-delay { background: #eef7f1; color: #22754a; border-color: #cfe8da; }

.chain-link { display: flex; align-items: center; gap: 8px; margin-left: 34px; height: 30px; }
.chain-line { width: 2px; height: 100%; background: var(--line-strong); }

.bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  background: #fff;
  padding: 9px 12px;
  cursor: pointer;
  transition: border-color .1s, box-shadow .1s;
  overflow: hidden;
}
.bubble:hover { border-color: var(--accent); }
.bubble.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: #fdfdff; }
.bubble.chained { margin-left: 22px; }
.bubble.has-errors { border-left: 4px solid var(--err); }
.bubble.has-warns { border-left: 4px solid var(--warn); }

.ord {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  background: #f0f1f5;
  border-radius: 6px;
  padding: 1px 6px;
  flex-shrink: 0;
}
.type-icon { flex-shrink: 0; }
.type-icon.big { font-size: 22px; }
.bubble-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bubble-icons { display: flex; gap: 6px; font-size: 11px; color: var(--muted); flex-shrink: 0; }
.vdot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.vdot.err { background: var(--err); }
.vdot.wrn { background: var(--warn); }

.chip-row { display: flex; flex-wrap: wrap; gap: 5px; margin: 5px 0 2px 30px; }
.chip-row.chained { margin-left: 52px; }
.pill-row.chained { margin-left: 34px; }
.chip {
  font-size: 11px;
  color: var(--muted);
  border: 1px dashed var(--line-strong);
  border-radius: 999px;
  padding: 2px 9px;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip:hover { color: var(--accent); border-color: var(--accent); }
.chip-missing { color: var(--err); border-color: var(--err); }
.chip-npc { border-style: dotted; }

.empty { text-align: center; margin-top: 12vh; color: var(--ink); }
.empty-icon { font-size: 42px; margin-bottom: 8px; }
.empty p { margin: 4px 0; }

/* ------------------------------- details panel ------------------------------- */

.details-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.name-input {
  font-size: 19px;
  font-weight: 700;
  border-color: transparent;
  background: transparent;
  flex: 1;
}
.name-input:hover { border-color: var(--line-strong); }
.name-bytes { font-size: 11px; white-space: nowrap; }
.name-bytes.over { color: var(--err); font-weight: 700; }
.ord-label { font-size: 12px; }

.dsec { margin: 18px 0; padding-top: 14px; border-top: 1px solid var(--line); }
.dsec-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 10px;
}

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.tab {
  font: inherit;
  font-size: 12.5px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
}
.tab:hover { border-color: var(--accent); }
.tab.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.trig-toggle.active { background: var(--accent); border-color: var(--accent); }

.tab-body { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }

.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.check.disabled { color: var(--muted); cursor: not-allowed; }
.markup-modes { gap: 18px; }

.kb-target { background: #f0f1f5; border-radius: 6px; padding: 3px 8px; font-size: 12px; }

.derived { margin-top: 12px; }
.derived-row {
  display: inline-flex;
  margin: 3px 6px 3px 0;
  font-size: 12.5px;
  border: 1px solid var(--line);
  background: #f9f9fc;
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
}
.derived-row:hover { border-color: var(--accent); color: var(--accent); }

.coords .map-link { font-size: 12px; white-space: nowrap; }
.counter-row { justify-content: flex-end; }
.counter { font-size: 11px; color: var(--muted); }
.counter.over { color: var(--err); font-weight: 700; }

.quiz-option .inp { flex: 1; }
/* Quiz editor uses the full panel width (question, options, reply picker) like the text editor. */
.quiz-fields, .quiz-fields .stack { align-self: stretch; align-items: stretch; }
.quiz-fields > .field, .quiz-fields .quiz-option { align-self: stretch; }
.quiz-fields select.inp { width: 100%; max-width: none; }

.details-footer { display: flex; gap: 10px; margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--line); }

/* file widget */
.file-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
  background: #fcfcfe;
}
.file-preview img, .file-preview video {
  max-width: 340px;
  max-height: 240px;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: block;
}
.file-preview audio { width: 340px; }
.file-meta { display: flex; gap: 10px; align-items: baseline; }
.file-name { font-size: 13px; font-weight: 600; }
.file-missing { color: var(--err); font-weight: 600; }

/* rich text editor */
.rt { border: 1px solid var(--line-strong); border-radius: 10px; background: #fff; overflow: hidden; }
.rt-toolbar {
  display: flex;
  gap: 2px;
  padding: 5px 7px;
  border-bottom: 1px solid var(--line);
  background: #f8f8fb;
  align-items: center;
}
.rt-btn {
  font: inherit;
  font-size: 12.5px;
  min-width: 28px;
  padding: 3px 7px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  color: var(--ink);
}
.rt-btn:hover { background: #ececf4; }
.rt-b { font-weight: 800; }
.rt-i { font-style: italic; }
.rt-u { text-decoration: underline; }
.rt-s { text-decoration: line-through; }
.rt-code { font-family: var(--mono); font-size: 11.5px; }
.rt-spring { flex: 1; }
.rt-src-toggle { color: var(--muted); font-size: 11px; }

.rt-area {
  min-height: 92px;
  max-height: 320px;
  overflow-y: auto;
  padding: 10px 12px;
  outline: none;
  white-space: pre-wrap;
  word-break: break-word;
}
.rt-area:empty::before { content: attr(data-placeholder); color: var(--muted); }
.rt-area code { background: #f0f1f5; }
.rt-area .tg-spoiler { background: repeating-linear-gradient(45deg, #e4e4ec, #e4e4ec 4px, #d5d5e2 4px, #d5d5e2 8px); border-radius: 3px; }
.rt-source { display: none; width: 100%; border: 0; outline: none; padding: 10px 12px; font-family: var(--mono); font-size: 12.5px; resize: vertical; }
.rt-source-mode .rt-area { display: none; }
.rt-source-mode .rt-source { display: block; }

/* ---------------------------------- modals ---------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(24, 26, 38, .42);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
}
.modal {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(15, 17, 32, .35);
  max-width: 680px;
  width: 100%;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-title { font-size: 16px; font-weight: 700; padding: 16px 20px 10px; }
.modal-body { padding: 0 20px 10px; overflow-y: auto; }
.modal-body p { margin-top: 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 20px 16px; }

.issue-list { display: flex; flex-direction: column; gap: 6px; }
.issue-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
}
.issue-row[onclick], .issue-row.error, .issue-row.warn { cursor: default; }
.issue-row:hover { background: #f7f7fb; }
.issue-row.error { border-left: 3px solid var(--err); }
.issue-row.warn { border-left: 3px solid var(--warn); }
.issue-icon { flex-shrink: 0; font-size: 12px; }
.issue-text { font-size: 13px; }

/* ---------------------------------- toasts ---------------------------------- */

#toast-root {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 95;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--ink);
  color: #fff;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .25s, transform .25s;
  max-width: 380px;
}
.toast.warn { background: #7a5310; }
.toast.show { opacity: 1; transform: none; }

/* misc */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d6d8e0; border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #c2c4cf; background-clip: content-box; border: 2px solid transparent; }
