:root {
  --bg: #0b1017;
  --panel: #131b26;
  --panel-2: #1a2431;
  --line: #24313f;
  --text: #e6edf5;
  --dim: #8fa2b7;
  --accent: #4fb3ff;
  --accent-2: #2f81f7;
  --good: #3ddc97;
  --warn: #ffb84d;
  --bad: #ff6b6b;
  --mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 700px at 15% -10%, #14243a 0%, var(--bg) 60%);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Inter, "Noto Sans", sans-serif;
  display: flex; flex-direction: column; min-height: 100%;
}
h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
h2 { font-size: 15px; margin: 0 0 12px; color: var(--dim); text-transform: uppercase; letter-spacing: .08em; }
h3 { font-size: 14px; margin: 18px 0 8px; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: .88em; background: #0e1721; padding: .1em .35em; border-radius: 4px; }
thin, .thin { color: var(--dim); font-weight: 400; }

/* ------------------------------- top bar ------------------------------- */
.topbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: rgba(11,16,23,.85); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 4px rgba(255,184,77,.15); }
.dot.ready { background: var(--good); box-shadow: 0 0 0 4px rgba(61,220,151,.15); }
.dot.busy { background: var(--accent); box-shadow: 0 0 0 4px rgba(79,179,255,.18); animation: pulse 1.2s infinite; }
.dot.down { background: var(--bad); box-shadow: 0 0 0 4px rgba(255,107,107,.15); }
@keyframes pulse { 50% { opacity: .35 } }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab {
  background: transparent; border: 1px solid transparent; color: var(--dim);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active { color: var(--text); background: var(--panel-2); border-color: var(--line); }
.topmeta { display: flex; gap: 8px; }
.badge {
  font-family: var(--mono); font-size: 11.5px; color: var(--dim);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px; white-space: nowrap;
}
.badge.link { text-decoration: none; }
.badge.link:hover { color: var(--accent); border-color: var(--accent); }

/* -------------------------------- layout ------------------------------- */
main { flex: 1; padding: 20px; max-width: 1400px; width: 100%; margin: 0 auto; }
.tab-panel { display: none; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.tab-panel.active { display: grid; }
#panel-history.active, #panel-api.active { grid-template-columns: 1fr; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; }
.panel.wide { max-width: 1100px; }
footer {
  padding: 14px 20px 22px; border-top: 1px solid var(--line); color: var(--dim);
  display: flex; gap: 16px; justify-content: space-between; flex-wrap: wrap; font-size: 12.5px;
}

/* --------------------------------- form -------------------------------- */
.row { margin-bottom: 14px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.label { display: flex; align-items: baseline; gap: 8px; font-size: 13px; color: var(--dim); margin-bottom: 6px; }
textarea, input[type="text"], input[type="number"], input[type="password"], select {
  width: 100%; background: #0e1721; color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 11px; font-size: 14.5px; font-family: inherit; resize: vertical;
}
textarea:focus, input:focus, select:focus { outline: none; border-color: var(--accent-2); }
input[type="file"] { color: var(--dim); font-size: 13px; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.hint { color: var(--dim); font-size: 12px; margin: 6px 0 0; }
.counter { margin-left: auto; font-family: var(--mono); font-size: 11.5px; }
.counter.over { color: var(--warn); }
.mini {
  background: var(--panel-2); color: var(--dim); border: 1px solid var(--line); border-radius: 7px;
  padding: 3px 9px; font-size: 12px; cursor: pointer; text-decoration: none; display: inline-block;
}
.mini:hover { color: var(--text); border-color: var(--accent); }
.mini.active { color: var(--text); border-color: var(--accent); background: #16283c; }
.subrow { display: flex; align-items: center; gap: 12px; margin: 8px 0; font-size: 13px; }
.check { color: var(--dim); display: flex; align-items: center; gap: 6px; }
.seg { display: inline-flex; background: #0e1721; border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 3px; }
.seg-btn { background: transparent; color: var(--dim); border: 0; padding: 7px 13px; border-radius: 7px; cursor: pointer; font-size: 13.5px; }
.seg-btn.active { background: var(--accent-2); color: #fff; }
.samples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.ref-only { display: none; }
body[data-mode="clone"] .ref-only, body[data-mode="direction"] .ref-only { display: block; }
body[data-mode="clone"] #presetRow, body[data-mode="clone"] #instructionRow { display: none; }
body[data-mode="design"] #instructionRow .label::after { content: ""; }

.primary {
  width: 100%; background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  color: #04121f; border: 0; border-radius: 10px; padding: 13px; font-size: 15.5px; font-weight: 650;
  cursor: pointer; letter-spacing: .2px;
}
.primary:disabled { opacity: .55; cursor: progress; }
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.error { color: var(--bad); font-size: 13px; white-space: pre-wrap; margin-top: 10px; font-family: var(--mono); }
.progress { display: flex; align-items: center; gap: 12px; margin-top: 12px; font-size: 13px; color: var(--dim); }
.bar { flex: 1; height: 6px; background: #0e1721; border-radius: 999px; overflow: hidden; }
.bar span { display: block; height: 100%; width: 30%; background: var(--accent); border-radius: 999px;
  animation: slide 1.6s ease-in-out infinite; }
@keyframes slide { 0% { transform: translateX(-100%) } 100% { transform: translateX(340%) } }

/* ------------------------------- results ------------------------------- */
.results { position: sticky; top: 74px; }
.results-body audio { width: 100%; }
.clip { border: 1px solid var(--line); border-radius: 12px; padding: 12px; margin-bottom: 12px; background: var(--panel-2); }
.clip .meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { font-family: var(--mono); font-size: 11.5px; color: var(--dim); background: #0e1721;
  border: 1px solid var(--line); border-radius: 6px; padding: 2px 7px; }
.chip b { color: var(--text); font-weight: 600; }
.clip .txt { font-size: 13.5px; color: var(--dim); margin: 8px 0 0; max-height: 4.6em; overflow: hidden; }
.clip .actions { display: flex; gap: 8px; margin-top: 10px; }
.spec { border-top: 1px solid var(--line); margin-top: 16px; padding-top: 4px; font-size: 13.5px; color: var(--dim); }
.spec ul { margin: 0; padding-left: 18px; }
.spec li { margin-bottom: 6px; }
.spec b { color: var(--text); }

/* ------------------------------- history ------------------------------- */
.hist-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
table.hist { width: 100%; border-collapse: collapse; font-size: 13px; }
table.hist th { text-align: left; color: var(--dim); font-weight: 500; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.hist td { padding: 8px; border-bottom: 1px solid #1a232f; vertical-align: top; }
table.hist tr:hover td { background: #16202c; }
table.hist td.audio { width: 320px; }
table.hist audio { width: 310px; height: 32px; }
td .txt { color: var(--dim); max-width: 420px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------- docs -------------------------------- */
.api-actions { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
pre.doc { background: #0b131c; border: 1px solid var(--line); border-radius: 12px; padding: 18px;
  overflow: auto; max-height: calc(100vh - 220px); font-family: var(--mono); font-size: 12.8px;
  line-height: 1.6; white-space: pre-wrap; color: #cfdae7; }

/* -------------------------------- modal -------------------------------- */
.modal { position: fixed; inset: 0; background: rgba(3,7,12,.72); display: flex; align-items: center;
  justify-content: center; z-index: 50; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(440px, 92vw); }
.modal-box.wide-box { width: min(760px, 94vw); max-height: 88vh; overflow: auto; }
.modal-box .label { margin-top: 12px; }
.modal-box input { margin: 0; }
.keys-head { display: flex; align-items: center; justify-content: space-between; }
.newkey { border: 1px solid var(--accent); border-radius: 10px; padding: 12px; background: #10202e; margin: 12px 0; }
.newkey textarea { font-family: var(--mono); font-size: 12.5px; color: var(--good); }
.curlhint { background: #0b131c; border: 1px solid var(--line); border-radius: 8px; padding: 10px;
  font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; color: #cfdae7; margin: 8px 0 0; }
#keysList table.hist td { font-size: 12.5px; }

@media (max-width: 1050px) {
  .tab-panel.active { grid-template-columns: 1fr; }
  .results { position: static; }
}
