:root {
  --bg0: #121820;
  --bg1: #1c2736;
  --ink: #f4f0e6;
  --muted: #9aa7b8;
  --accent: #f0a04b;
  --accent-ink: #1a140c;
  --line: rgba(244, 240, 230, 0.12);
  --panel: rgba(10, 16, 26, 0.72);
  --panel-solid: #182231;
  --ok: #7dbe8a;
  --err: #e07979;
  --shadow: 0 28px 70px rgba(0, 0, 0, 0.42);
  --radius: 20px;
  --font: "Sora", "Segoe UI", sans-serif;
  --display: "Literata", "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1100px 640px at 8% -8%, #3d5573 0%, transparent 55%),
    radial-gradient(900px 560px at 100% 0%, #6a4024 0%, transparent 48%),
    linear-gradient(165deg, var(--bg0), var(--bg1));
  background-attachment: fixed;
}

.shell {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2.4rem 0 3rem;
}

.header {
  margin-bottom: 1.6rem;
}

.brand {
  font-family: var(--display);
  font-size: clamp(2.6rem, 5.5vw, 3.6rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.tagline {
  margin: 0.6rem 0 0;
  color: var(--muted);
  font-size: 1.02rem;
  font-weight: 400;
  max-width: 40rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.85fr);
  gap: 1.1rem;
  align-items: start;
}

.workspace,
.history {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem 1.3rem 1.35rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.label {
  display: block;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.45rem;
  font-weight: 500;
}

textarea,
input[type="password"],
input[type="search"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font: inherit;
  padding: 0.9rem 1rem;
  outline: none;
  resize: vertical;
}

textarea:focus,
input:focus,
.picker-trigger:focus,
.format-btn:focus-visible,
.btn:focus-visible {
  border-color: rgba(240, 160, 75, 0.75);
  box-shadow: 0 0 0 3px rgba(240, 160, 75, 0.18);
  outline: none;
}

.controls {
  display: grid;
  grid-template-columns: 1.4fr 0.9fr auto auto;
  gap: 0.8rem;
  align-items: end;
  margin-top: 1rem;
}

.controls:has(.password-field:not(.hidden)) {
  grid-template-columns: 1.2fr 0.85fr auto 1fr auto;
}

.field { min-width: 0; }

.picker { position: relative; }

.picker-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font: inherit;
  padding: 0.85rem 0.95rem;
  cursor: pointer;
  text-align: left;
}

.caret {
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg) translate(-1px, -2px);
  flex-shrink: 0;
}

.picker-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  min-width: 260px;
  border: 1px solid rgba(26, 35, 50, 0.16);
  border-radius: 14px;
  background: #f6f1e6;
  color: #1a2332;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.3);
  padding: 0.45rem;
}

.picker-search {
  margin-bottom: 0.35rem;
  background: #fff;
  color: #1a2332;
  border-color: rgba(26, 35, 50, 0.14);
}

.picker-menu {
  margin: 0;
  padding: 0;
  list-style: none;
  max-height: 280px;
  overflow: auto;
}

.picker-menu.floating {
  position: absolute;
  z-index: 30;
  top: calc(100% + 0.35rem);
  left: 0;
  right: 0;
  border: 1px solid rgba(26, 35, 50, 0.16);
  border-radius: 14px;
  background: #f6f1e6;
  color: #1a2332;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.3);
  padding: 0.35rem;
}

.picker-option {
  padding: 0.62rem 0.75rem;
  border-radius: 9px;
  cursor: pointer;
  color: #1a2332;
  font-weight: 500;
  font-size: 0.95rem;
}

.picker-option:hover,
.picker-option:focus {
  background: rgba(240, 160, 75, 0.24);
  outline: none;
}

.picker-option.is-selected {
  background: #f0a04b;
  color: #1a140c;
}

.format-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.3rem;
  padding: 0.28rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
}

.format-btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 0.72rem 0.7rem;
  cursor: pointer;
}

.format-btn.is-active {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-weight: 600;
  padding: 0.9rem 1.35rem;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.15s ease, filter 0.15s ease;
}

.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.status {
  min-height: 1.4em;
  margin: 0.9rem 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.status.err { color: var(--err); }
.status.ok { color: var(--ok); }

.result {
  margin-top: 1.2rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
}

.audio-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-top: 0.85rem;
}

audio {
  width: min(100%, 420px);
  height: 42px;
}

.history {
  position: sticky;
  top: 1rem;
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  min-height: 420px;
}

.history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.history-title {
  margin: 0;
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.history-meta {
  color: var(--muted);
  font-size: 0.82rem;
}

.history-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  padding: 0.75rem 0.8rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.history-item:hover,
.history-item.is-active {
  border-color: rgba(240, 160, 75, 0.55);
  background: rgba(240, 160, 75, 0.08);
}

.history-item-top {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.history-item-title {
  color: var(--ink);
  font-weight: 500;
  font-size: 0.92rem;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.history-item audio {
  width: 100%;
  margin-top: 0.55rem;
  height: 36px;
}

.history-item-actions {
  display: flex;
  gap: 0.45rem;
  margin-top: 0.55rem;
}

.history-item-actions .btn-ghost {
  font-size: 0.8rem;
  padding: 0.45rem 0.75rem;
}

.footer {
  margin-top: 1rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.hidden { display: none !important; }

@media (max-width: 960px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .history {
    position: static;
    max-height: none;
    min-height: 0;
  }

  .controls,
  .controls:has(.password-field:not(.hidden)) {
    grid-template-columns: 1fr 1fr;
  }

  .btn { grid-column: 1 / -1; width: 100%; }
}

@media (max-width: 560px) {
  .controls,
  .controls:has(.password-field:not(.hidden)) {
    grid-template-columns: 1fr;
  }
}
