:root {
  --bg-0: #0a0a0a;
  --bg-1: #111111;
  --bg-2: #1a1a1a;
  --bg-3: #1f1f1f;
  --text-0: #f2f2f2;
  --text-1: #cdcdcd;
  --text-2: #9a9a9a;
  --line-0: #2a2a2a;
  --line-1: #3a3a3a;
  --accent-0: #e6e6e6;
  --danger: #dd6b6b;
  --ok: #9dd69b;
  --radius: 14px;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 15% 10%, #171717 0%, #0b0b0b 50%, #070707 100%);
  color: var(--text-0);
  font-family: "IBM Plex Sans", "Manrope", "Segoe UI", -apple-system, sans-serif;
}

#app {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-weight: 600;
}

p {
  margin: 0;
  color: var(--text-1);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  border: 1px solid var(--line-0);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #171717, #111111);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

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

.brand h1 {
  font-size: 1.2rem;
}

.brand p {
  font-size: 0.88rem;
  color: var(--text-2);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-1);
  border-radius: 10px;
  color: var(--accent-0);
  background: #151515;
  font-size: 0.8rem;
  letter-spacing: 0.12em;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: end;
}

.search-wrap,
.status-wrap {
  display: grid;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--text-2);
}

input,
select,
textarea,
button {
  font: inherit;
}

input,
select,
textarea {
  border: 1px solid var(--line-1);
  background: var(--bg-2);
  color: var(--text-0);
  border-radius: 10px;
  padding: 8px 10px;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent-0);
  outline-offset: 2px;
}

.btn {
  border: 1px solid var(--line-1);
  background: var(--bg-2);
  color: var(--text-0);
  border-radius: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: all 140ms ease;
}

.btn:hover {
  border-color: var(--accent-0);
}

.btn-primary {
  background: linear-gradient(180deg, #f0f0f0, #d5d5d5);
  color: #111;
  border-color: #d7d7d7;
}

.btn-ghost {
  background: transparent;
}

.library-controls {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--line-0);
  border-radius: 10px;
  overflow: hidden;
}

.segmented-btn {
  border: none;
  background: #121212;
  color: var(--text-1);
  padding: 8px 12px;
  cursor: pointer;
}

.segmented-btn.active {
  background: #202020;
  color: var(--text-0);
}

.hint {
  color: var(--text-2);
  font-size: 0.82rem;
}

.layout {
  margin-top: 12px;
  display: grid;
  grid-template-columns: minmax(320px, 40%) minmax(500px, 1fr);
  gap: 12px;
}

.panel {
  border: 1px solid var(--line-0);
  border-radius: var(--radius);
  background: linear-gradient(180deg, #141414, #101010);
  min-height: 500px;
  box-shadow: var(--shadow);
}

.panel-library {
  padding: 14px;
}

.state-message {
  border: 1px dashed var(--line-1);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  color: var(--text-1);
}

.bookshelf-view {
  display: grid;
  gap: 12px;
}

.shelf {
  border: 1px solid var(--line-0);
  border-radius: 10px;
  padding: 10px 10px 6px;
  background: #0f0f0f;
}

.shelf-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: thin;
  padding-bottom: 6px;
}

.book-spine {
  min-width: 62px;
  height: 200px;
  border: 1px solid #313131;
  border-radius: 6px;
  padding: 8px 6px;
  display: flex;
  align-items: end;
  justify-content: center;
  background: linear-gradient(180deg, #2a2a2a, #161616);
  color: #f0f0f0;
  cursor: pointer;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  font-size: 0.7rem;
  font-family: "Cormorant Garamond", Georgia, serif;
  transition: transform 140ms ease, border-color 140ms ease;
}

.book-spine:hover {
  transform: translateY(-2px);
  border-color: #efefef;
}

.book-spine.active {
  border-color: #fafafa;
  background: linear-gradient(180deg, #3d3d3d, #222222);
}

.database-view table {
  width: 100%;
  border-collapse: collapse;
}

.database-view th,
.database-view td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line-0);
  font-size: 0.88rem;
}

.database-view th {
  position: sticky;
  top: 0;
  background: #131313;
  color: var(--text-1);
  z-index: 1;
}

.database-view tr:hover {
  background: #191919;
}

.database-view button.row-link {
  background: none;
  border: 1px solid var(--line-0);
  border-radius: 8px;
  color: var(--text-0);
  background: #181818;
  padding: 4px 8px;
  cursor: pointer;
  text-align: center;
}

.database-view button.value-link {
  width: 100%;
  background: #171717;
  border: 1px solid var(--line-0);
  border-radius: 8px;
  color: var(--text-0);
  cursor: pointer;
  padding: 5px 8px;
  text-align: left;
}

.database-view button.value-link:hover,
.database-view button.row-link:hover {
  border-color: var(--line-1);
}

.panel-workspace {
  padding: 14px;
}

.workspace-empty {
  height: 100%;
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--text-2);
}

.workspace-view {
  display: grid;
  gap: 12px;
}

.workspace-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.workspace-meta {
  color: var(--text-2);
}

.workspace-actions {
  display: flex;
  gap: 8px;
  align-items: start;
}

.workspace-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.card {
  border: 1px solid var(--line-0);
  border-radius: 12px;
  background: #121212;
  padding: 12px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.badge {
  border: 1px solid var(--line-1);
  border-radius: 999px;
  padding: 2px 9px;
  color: var(--text-1);
  font-size: 0.75rem;
}

.raw-content {
  border: 1px solid var(--line-0);
  border-radius: 10px;
  background: #0f0f0f;
  padding: 10px;
  max-height: 240px;
  overflow: auto;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.composer {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.composer label {
  color: var(--text-1);
  font-size: 0.84rem;
}

.composer textarea {
  min-height: 110px;
  resize: vertical;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.status-label {
  font-size: 0.78rem;
  color: var(--text-2);
}

.synth-summary {
  border: 1px solid var(--line-0);
  border-radius: 10px;
  padding: 10px;
  background: #0f0f0f;
  color: var(--text-0);
  line-height: 1.45;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  max-height: 380px;
  overflow: auto;
}

.run-history {
  max-height: 190px;
  overflow: auto;
  display: grid;
  gap: 6px;
}

.run-item {
  border: 1px solid var(--line-0);
  border-radius: 9px;
  padding: 8px;
  background: #101010;
  font-size: 0.84rem;
}

.run-item .ok {
  color: var(--ok);
}

.run-item .err {
  color: var(--danger);
}

.book-form-dialog {
  width: min(520px, 94vw);
  border: 1px solid var(--line-1);
  border-radius: 12px;
  background: #151515;
  color: var(--text-0);
  box-shadow: var(--shadow);
}

.book-form-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.book-form {
  display: grid;
  gap: 10px;
  padding: 14px;
}

.book-form-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.book-form-hint {
  font-size: 0.84rem;
}

.book-form-error {
  border: 1px solid #5a2d2d;
  background: #2a1414;
  color: #f3c7c7;
  border-radius: 9px;
  padding: 8px 10px;
  font-size: 0.84rem;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--text-1);
  font-size: 0.84rem;
}

.book-form-actions {
  display: flex;
  justify-content: flex-end;
}

.hidden {
  display: none !important;
}

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

  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
