:root {
  --bg: #f7f4ee;
  --bg-raised: #ffffff;
  --bg-hover: #efeae1;
  --line: #e4ddd0;
  --line-strong: #d3cbbd;
  --ink: #1c1914;
  --muted: #6b6558;
  --faint: #9a9386;
  --accent: #b8860b;
  --accent-dim: rgba(184, 134, 11, 0.12);
  --accent-line: rgba(184, 134, 11, 0.45);
  --ok: #4f7a3a;
  --chip: #f3efe6;
  --shadow: 0 18px 50px rgba(28, 25, 20, 0.12);
  --serif: "Noto Serif SC", "Songti SC", "Noto Serif CJK SC", serif;
  --mono: "IBM Plex Mono", "SFMono-Regular", ui-monospace, monospace;
  --radius: 999px;
  --pad: 18px;
  --sidebar: 232px;
  --detail: 420px;
  --detail-wide: 500px;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: 0.01em;
  -webkit-font-smoothing: antialiased;
}

body {
  background-image:
    radial-gradient(1200px 500px at 10% -10%, rgba(184, 134, 11, 0.08), transparent 50%),
    linear-gradient(180deg, #fffdf8 0%, var(--bg) 28%);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.app {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100%;
}

.app.has-detail {
  grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--detail);
}
.app.has-detail.wide-detail {
  grid-template-columns: var(--sidebar) minmax(0, 1fr) var(--detail-wide);
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 22px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 28px;
  background: rgba(255, 253, 248, 0.88);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.brand-mark {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-dim);
}

.brand-text { display: flex; flex-direction: column; }
.brand-name {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.08em;
}
.brand-sub {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.nav { display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font: inherit;
  font-size: 16px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.nav-item:hover { color: var(--ink); background: var(--bg-hover); }
.nav-item.is-active {
  color: var(--ink);
  background: var(--bg-raised);
  border-color: var(--line);
}
.nav-item:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--accent);
}
.nav-kicker {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
  width: 1.6em;
}

.filter-block { padding: 0 4px; }
.filter-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 10px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--chip);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 9px;
  border-radius: var(--radius);
  cursor: pointer;
  letter-spacing: 0.02em;
}
.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip.is-on {
  color: var(--ink);
  border-color: var(--accent-line);
  background: var(--accent-dim);
}
.chip:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--accent);
}

.sidebar-foot { margin-top: auto; }

.kbd-hint {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.kbd-hint:hover { color: var(--ink); border-color: var(--line-strong); }

.keys { display: inline-flex; gap: 4px; }
kbd {
  font-family: var(--mono);
  font-size: 10px;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--muted);
  padding: 1px 5px;
  border-radius: 4px;
  min-width: 1.4em;
  text-align: center;
}

.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 22px 12px;
  border-bottom: 1px solid var(--line);
}

.crumb {
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.sep, .muted { color: var(--faint); font-weight: 400; font-size: 14px; }
.sep { font-family: var(--mono); }

.search-inline input {
  width: min(280px, 36vw);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 12px;
  padding: 7px 10px;
  border-radius: var(--radius);
  outline: none;
}
.search-inline input::placeholder { color: var(--faint); }
.search-inline input:focus {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.stage { padding: 8px 10px 40px; }

.group-label {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
  padding: 16px 12px 6px;
}

.row {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 10px;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  border: 1px solid transparent;
}
button.row {
  width: 100%;
  background: transparent;
  font: inherit;
  text-align: left;
}
.row:hover {
  background: var(--bg-hover);
  border-color: var(--line);
}
.row:focus-visible {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
.row.is-open {
  background: var(--bg-raised);
  border-color: var(--line);
}

.row-name {
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-note {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pill {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 2px 7px;
  border-radius: var(--radius);
  background: var(--chip);
  white-space: nowrap;
}

.example-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--faint);
}

.empty {
  color: var(--muted);
  padding: 32px 14px;
  font-size: 14px;
}

.detail[hidden] { display: none !important; }
.detail {
  border-left: 1px solid var(--line);
  padding: 20px 20px 28px;
  background: var(--bg-raised);
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.detail-kicker {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}
.detail h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
}

.icon-btn, .btn-primary {
  appearance: none;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 11px;
}

.icon-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: var(--radius);
  padding: 5px 10px;
}
.icon-btn:hover { color: var(--ink); }

.btn-primary {
  border: 1px solid var(--accent-line);
  background: var(--accent-dim);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 8px 14px;
}
.btn-primary:hover { border-color: var(--accent); }
.btn-primary:focus-visible,
.icon-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 3px var(--accent);
}

.detail-summary {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
}

.detail-notes {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
}

.detail-notes[hidden],
.file-list[hidden],
.prompt-body[hidden],
.detail-preview[hidden] { display: none !important; }

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.file-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.file-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.file-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.file-name {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-body {
  flex: none;
  max-height: 42vh;
}

.prompt-body {
  margin: 0;
  flex: 1;
  overflow: auto;
  background: #faf8f3;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  color: var(--ink);
}

.var {
  color: var(--accent);
  background: var(--accent-dim);
  border-radius: 4px;
  padding: 0 3px;
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.copy-status {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ok);
  min-height: 1em;
}

.palette-root[hidden] { display: none !important; }
.palette-root {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: start center;
  padding-top: 12vh;
}
.palette-scrim {
  position: absolute;
  inset: 0;
  background: rgba(28, 25, 20, 0.28);
}
.palette {
  position: relative;
  width: min(560px, calc(100vw - 32px));
  background: var(--bg-raised);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.palette-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.palette-bar input {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 16px;
  outline: none;
}
.palette-bar input::placeholder { color: var(--faint); }

.palette-list { max-height: 360px; overflow: auto; padding: 6px; }
.palette-item {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.palette-item.is-active,
.palette-item:hover {
  background: var(--bg-hover);
  border-color: var(--line);
}
.palette-kind {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
  letter-spacing: 0.08em;
}
.palette-title { font-size: 14px; }
.palette-sub {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.palette-foot {
  display: flex;
  gap: 14px;
  padding: 8px 14px 10px;
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 10px;
  color: var(--faint);
}

@media (max-width: 880px) {
  .app, .app.has-detail, .app.has-detail.wide-detail {
    grid-template-columns: 1fr;
  }
  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    gap: 16px;
    padding-bottom: 12px;
  }
  .nav { flex-direction: row; }
  .sidebar-foot { display: none; }
  .row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .detail {
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

.row.row-component {
  grid-template-columns: 88px minmax(0, 1fr) auto;
  align-items: center;
}

.row-thumb {
  width: 88px;
  height: 56px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f3efe6;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.row-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.row-thumb-runtime {
  flex-direction: column;
  gap: 2px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
}

.row-thumb-runtime strong {
  color: var(--accent);
  font-size: 11px;
}

.row-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-preview {
  flex: none;
}

.preview-image {
  display: block;
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #f3efe6;
}

.preview-frame {
  display: block;
  width: 100%;
  height: 220px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #f3efe6;
}

@media (max-width: 880px) {
  .row.row-component {
    grid-template-columns: 88px minmax(0, 1fr);
  }
  .row.row-component .row-meta {
    grid-column: 2;
  }
}
