:root {
  --bg: #0a0a0a;
  --surface: #141414;
  --surface-2: #181818;
  --border: #2a2a2a;
  --accent: #f97316;
  --accent-soft: rgba(249, 115, 22, 0.14);
  --text: #f5f5f5;
  --text-dim: #9a9a9a;
  --green: #22c55e;
  --amber: #eab308;
  --red: #ef4444;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Ambient glow for atmosphere on screen */
.glow {
  position: fixed;
  top: -260px;
  right: -180px;
  width: 620px;
  height: 620px;
  background: radial-gradient(circle, var(--accent-soft) 0%, transparent 68%);
  filter: blur(20px);
  pointer-events: none;
  z-index: 0;
}

.topbar, .layout, .footer { position: relative; z-index: 1; }

/* Top bar */
.topbar {
  max-width: 1100px;
  margin: 0 auto;
  padding: 28px 24px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.brand-mark {
  display: inline-flex;
  align-items: center;
}
.brand-mark img {
  height: 32px;
  width: auto;
  display: block;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name {
  font-family: "Bricolage Grotesque", sans-serif;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: -0.01em;
}
.brand-sub { color: var(--text-dim); font-size: 12.5px; }

/* Language toggle */
.lang-toggle {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}
.lang-btn {
  border: 0; background: transparent;
  color: var(--text-dim);
  font-family: inherit; font-size: 12.5px; font-weight: 600;
  padding: 6px 14px; border-radius: 999px;
  cursor: pointer; transition: all .18s ease;
}
.lang-btn.is-active { background: var(--accent); color: #0a0a0a; }

/* Layout */
.layout {
  max-width: 1100px;
  margin: 0 auto;
  padding: 18px 24px 8px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 18px;
  align-items: start;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

.card-title {
  margin: 0 0 18px;
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: 15px; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
  color: var(--text-dim);
}

/* Form */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px; font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.value-label { visibility: hidden; }

input[type="text"], textarea, select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit; font-size: 14px;
  padding: 10px 12px;
  transition: border-color .16s ease, box-shadow .16s ease;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; line-height: 1.45; }

.select-wrap { position: relative; }
.select-wrap::after {
  content: "";
  position: absolute; right: 14px; top: 50%;
  width: 7px; height: 7px;
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
select { appearance: none; cursor: pointer; }

.metric-grid {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 0 12px;
}

/* Health slider */
.slider-head { display: flex; align-items: center; justify-content: space-between; }
.health-pill {
  font-weight: 600; font-size: 12.5px;
  padding: 2px 12px; border-radius: 999px;
  color: #0a0a0a; background: var(--amber);
  min-width: 34px; text-align: center;
  transition: background .2s ease;
}
input[type="range"] {
  width: 100%; height: 6px; margin-top: 10px;
  -webkit-appearance: none; appearance: none;
  background: var(--border); border-radius: 999px; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--text); border: 3px solid var(--accent);
}
input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--text); border: 3px solid var(--accent);
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  border-radius: 10px; padding: 11px 16px;
  border: 1px solid transparent; cursor: pointer;
  transition: transform .08s ease, background .16s ease, border-color .16s ease, opacity .16s ease;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-block { width: 100%; margin-top: 6px; }
.btn-primary { background: var(--accent); color: #0a0a0a; }
.btn-primary:hover:not(:disabled) { background: #fb8534; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { border-color: #444; background: var(--surface-2); }
.play-icon { font-size: 10px; }

/* Spinner */
.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(10,10,10,.35);
  border-top-color: #0a0a0a;
  animation: spin .7s linear infinite;
}
.btn-ghost .spinner { border: 2px solid rgba(245,245,245,.3); border-top-color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }

/* Output states */
.empty-state {
  border: 1.5px dashed var(--border);
  border-radius: 12px;
  min-height: 220px;
  display: grid; place-items: center;
  color: var(--text-dim); font-size: 13.5px; text-align: center; padding: 20px;
}

.loading-state { display: flex; flex-direction: column; gap: 12px; padding: 6px 0; }
.skel {
  height: 16px; border-radius: 6px;
  background: linear-gradient(90deg, #1c1c1c 0%, #262626 50%, #1c1c1c 100%);
  background-size: 200% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}
.skel.short { width: 62%; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.script-box {
  font-size: 14.5px; line-height: 1.7; color: #e9e9e9;
  white-space: pre-wrap;
  border-left: 2px solid var(--accent);
  padding: 2px 0 2px 16px;
  margin-bottom: 18px;
}

/* Audio */
.audio-block { margin-bottom: 16px; }
.viz { width: 100%; display: block; opacity: .9; }
.progress {
  height: 5px; background: var(--border); border-radius: 999px;
  overflow: hidden; margin-top: 8px;
}
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width .08s linear; }
.time-row {
  display: flex; justify-content: space-between;
  font-size: 11px; color: var(--text-dim); margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.error-box {
  margin-top: 14px; padding: 10px 12px;
  background: rgba(239, 68, 68, .1);
  border: 1px solid rgba(239, 68, 68, .3);
  border-radius: 10px;
  color: #fca5a5; font-size: 13px;
}

.footer {
  max-width: 1100px; margin: 14px auto 30px;
  padding: 0 24px;
  color: var(--text-dim); font-size: 11.5px; text-align: center;
}

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { flex-direction: row; }
}

/* ---------- topbar right cluster ---------- */
.topbar-right { display: flex; align-items: center; gap: 10px; }

.keys-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); color: var(--text-dim);
  border: 1px solid var(--border); border-radius: 999px;
  font-family: inherit; font-size: 12px; font-weight: 600;
  padding: 7px 12px; cursor: pointer;
  transition: color .16s ease, border-color .16s ease;
}
.keys-btn:hover { color: var(--text); border-color: #444; }
.keys-btn-error { color: var(--red); border-color: rgba(239,68,68,.5); }

/* ---------- key gate ---------- */
.gate {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  padding: 32px 20px; overflow-y: auto;
}
.gate-hidden { display: none; }

.gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 30px;
  width: 100%; max-width: 460px;
}
.gate-head { display: flex; align-items: center; gap: 11px; margin-bottom: 14px; }
.gate-mark {
  width: 34px; height: 34px; flex-shrink: 0;
  display: grid; place-items: center;
  border-radius: 9px; color: var(--accent);
  background: var(--accent-soft); border: 1px solid rgba(249,115,22,.25);
}
.gate-title {
  margin: 0; font-family: "Bricolage Grotesque", sans-serif;
  font-size: 18px; font-weight: 600; letter-spacing: -0.01em;
}
.gate-intro {
  margin: 0 0 22px; font-size: 13px; line-height: 1.6; color: var(--text-dim);
}

.key-field { margin-bottom: 16px; }
.key-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11px; font-weight: 500; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px;
}
.key-label a { color: var(--accent); text-decoration: none; text-transform: none; letter-spacing: 0; font-size: 11px; }
.key-label a:hover { text-decoration: underline; }

.key-input-wrap {
  display: flex; align-items: center;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; overflow: hidden;
  transition: border-color .16s ease, box-shadow .16s ease;
}
.key-input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.key-input-wrap input {
  flex: 1; background: transparent; border: none; outline: none; box-shadow: none;
  color: var(--text); font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 13px; padding: 10px 12px; width: 100%;
}
.key-eye {
  background: none; border: none; cursor: pointer;
  color: var(--text-dim); padding: 0 12px; display: grid; place-items: center;
}
.key-eye:hover { color: var(--text); }
.key-hint { font-size: 11px; color: #555; margin-top: 5px; }

.key-note {
  display: flex; align-items: flex-start; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 18px;
  color: var(--text-dim); font-size: 12px; line-height: 1.5;
}
.key-note svg { color: var(--accent); flex-shrink: 0; margin-top: 2px; }

/* ---------- settings modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 1100;
  background: rgba(0,0,0,.72);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; overflow-y: auto;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 26px; width: 100%; max-width: 420px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-title { margin: 0; font-family: "Bricolage Grotesque", sans-serif; font-size: 16px; font-weight: 600; }
.modal-x { background: none; border: none; color: var(--text-dim); font-size: 22px; line-height: 1; cursor: pointer; padding: 0 4px; }
.modal-x:hover { color: var(--text); }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.modal-actions .btn-primary { flex: 1; }

.btn-danger { background: transparent; color: var(--red); border-color: rgba(239,68,68,.3); }
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,.1); border-color: rgba(239,68,68,.5); }

@media (max-width: 820px) {
  .topbar-right { gap: 8px; }
  .keys-btn span { display: none; }
  .keys-btn { padding: 7px 9px; }
}
