:root {
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #2b2b2b;
  --muted: #6b6b6b;
  --accent: #5b4a9e;
  --accent-dark: #48397f;
  --line: #e4e1d8;
  --ok: #1f8a4c;
  --warn: #b7791f;
  --err: #b3392f;
  --code-bg: #f1efe8;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 6px 18px rgba(0, 0, 0, 0.05);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: linear-gradient(120deg, #3b2f63, #5b4a9e 60%, #6f5bb5);
  color: #fff;
  box-shadow: var(--shadow);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand .logo {
  font-size: 30px;
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.3px;
}

.brand .tagline {
  margin: 0;
  font-size: 12.5px;
  opacity: 0.85;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ---------- status pill ---------- */
.pill {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  white-space: nowrap;
}

.pill.ok {
  background: var(--ok);
}

.pill.warn {
  background: var(--warn);
}

.pill.err {
  background: var(--err);
}

/* ---------- db-not-ready banner ---------- */
.db-banner {
  margin: 14px 22px 0;
  background: #fff7e8;
  border: 1px solid #eccf8f;
  border-left: 4px solid var(--warn);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
}

.db-banner-title {
  font-weight: 700;
  color: #7a5b1c;
  font-size: 15px;
}

.db-banner-steps {
  margin: 8px 0 4px;
  padding-left: 20px;
  font-size: 13.5px;
}

.db-banner-steps li {
  margin: 3px 0;
}

.db-banner-steps code {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12.5px;
}

.db-banner-progress {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.db-banner-log {
  width: 100%;
  background: #232136;
  color: #e0def4;
  border-radius: 8px;
  padding: 10px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 11.5px;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 22px 0;
}

.tab {
  border: 1px solid transparent;
  background: transparent;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 8px 8px 0 0;
  cursor: pointer;
}

.tab:hover {
  color: var(--ink);
  background: rgba(91, 74, 158, 0.08);
}

.tab.active {
  color: var(--accent-dark);
  background: var(--panel);
  border-color: var(--line);
  border-bottom-color: var(--panel);
}

/* ---------- panels ---------- */
main {
  padding: 0 22px 30px;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
  animation: fade 0.15s ease;
}

@keyframes fade {
  from {
    opacity: 0;
    transform: translateY(3px);
  }

  to {
    opacity: 1;
  }
}

.hint {
  background: #efeafb;
  border: 1px solid #dcd3f3;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 14px 0;
  font-size: 13.5px;
  color: #3a3160;
}

.hint code,
.foot code,
.muted code,
.prompt-preview code {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12.5px;
}

/* ---------- forms ---------- */
.tool-form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.form-row>label {
  flex: 1 1 200px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: #444;
}

label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: var(--ink);
}

input,
select {
  border: 1px solid #d5d2c8;
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  background: #fff;
  color: var(--ink);
  width: 100%;
}

input:focus,
select:focus {
  outline: 2px solid rgba(91, 74, 158, 0.35);
  border-color: var(--accent);
}

input[type="checkbox"] {
  width: auto;
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  align-self: flex-start;
}

.btn:hover {
  background: #f4f2ec;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-dark);
}

.btn-warn {
  background: #b7791f;
  border-color: #b7791f;
  color: #fff;
}

.btn-warn:hover {
  background: #96631a;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: #fff;
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.15);
}

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

/* ---------- results ---------- */
.results {
  margin-top: 16px;
}

.results>.empty {
  color: var(--muted);
  font-style: italic;
  padding: 8px 2px;
}

/* verse cards */
.vcard {
  margin-bottom: 12px;
}

.vcard .vref {
  font-weight: 700;
  color: var(--accent-dark);
  font-size: 13.5px;
  margin-bottom: 3px;
}

.vcard .vtrans {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
}

.vcard .vtext {
  font-size: 15px;
}

.vcard .vtext.small {
  font-size: 14px;
  color: #444;
}

.vcard .vorig {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 14px;
  color: #005;
}

/* tables */
table.data {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 13.5px;
}

table.data th,
table.data td {
  text-align: left;
  padding: 8px 11px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

table.data th {
  background: #f1efe8;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #555;
}

table.data tr:last-child td {
  border-bottom: none;
}

table.data tr:hover td {
  background: #faf9f5;
}

.snip b {
  color: var(--accent-dark);
  background: #ece7fb;
  border-radius: 3px;
  padding: 0 2px;
}

/* orig word display */
.owords {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 18px;
}

.oword .osurface {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 15px;
  color: #002;
}

.oword .ostrongs {
  font-size: 11.5px;
  color: var(--accent-dark);
  font-weight: 600;
}

.oword .omorph {
  font-size: 11.5px;
  color: #777;
}

.oword .olemma {
  font-size: 12px;
  color: #96530f;
}

.oword .odef {
  font-size: 12px;
  color: #666;
}

.overv {
  font-weight: 700;
  color: var(--accent-dark);
  margin: 12px 0 6px;
}

/* stats / list */
.statgrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.statcard {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.statcard .snum {
  font-size: 24px;
  font-weight: 700;
  color: var(--accent-dark);
}

.statcard .slabel {
  font-size: 12.5px;
  color: var(--muted);
}

.notes {
  color: #7a5b1c;
  font-size: 12.5px;
  margin-top: 8px;
}

.notes div::before {
  content: "ℹ ";
}

.build-out {
  background: #232136;
  color: #e0def4;
  border-radius: 8px;
  padding: 12px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  max-height: 50vh;
  overflow: auto;
  white-space: pre-wrap;
}

/* ---------- AI panel ---------- */
.ai-panel {
  margin-top: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.ai-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.ai-title {
  font-weight: 700;
  color: var(--accent-dark);
}

.ai-instr {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  flex: 1 1 260px;
  font-weight: 500;
}

.ai-out {
  white-space: pre-wrap;
  font-size: 14px;
  border-top: 1px dashed var(--line);
  padding-top: 12px;
  max-height: 60vh;
  overflow: auto;
}

.ai-cursor {
  color: var(--accent);
  animation: blink 1s step-start infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.ai-error {
  border-top: 1px dashed var(--line);
  padding-top: 10px;
  color: var(--err);
}

/* ---------- modal ---------- */
dialog.modal {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(560px, 92vw);
}

.modal-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

dialog::backdrop {
  background: rgba(20, 16, 40, 0.45);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
}

.modal-foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.prompt-preview pre {
  background: #232136;
  color: #e0def4;
  border-radius: 8px;
  padding: 12px;
  font-size: 11.5px;
  max-height: 40vh;
  overflow: auto;
  white-space: pre-wrap;
}

.prompt-preview summary {
  cursor: pointer;
  color: var(--accent-dark);
  font-weight: 600;
  font-size: 13px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 12.5px;
}

.foot {
  text-align: center;
  padding: 18px 22px 26px;
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .tab {
    white-space: nowrap;
  }
}