:root {
  color-scheme: light;
  --bg: #f4f2ee;
  --panel: #ffffff;
  --panel-soft: #f8f7f4;
  --ink: #20201f;
  --muted: #72716d;
  --line: #dedbd4;
  --line-strong: #c9c5bc;
  --accent: #6657e8;
  --accent-deep: #5143cb;
  --accent-soft: #eeebff;
  --danger: #b9473d;
  --danger-soft: #fff0ee;
  --success: #217a56;
  --shadow: 0 18px 50px rgba(38, 34, 27, 0.12);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --header-height: 66px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 12% -8%, rgba(102, 87, 232, 0.09), transparent 31rem),
    var(--bg);
}

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

button,
select,
input[type="checkbox"],
input[type="radio"] {
  cursor: pointer;
}

button:disabled,
select:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: 3px solid rgba(102, 87, 232, 0.26);
  outline-offset: 2px;
}

textarea {
  resize: vertical;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 24px;
  border-bottom: 1px solid rgba(202, 198, 190, 0.82);
  background: rgba(248, 247, 244, 0.9);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 760;
  letter-spacing: -0.02em;
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 7px 7px 7px 2px;
  background:
    linear-gradient(140deg, rgba(255,255,255,0.65), transparent 48%),
    var(--accent);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.32);
}

.header-actions,
.workbench-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-button,
.quiet-button,
.mini-button,
.icon-button,
.new-prompt-button,
.primary-button,
.secondary-button,
.danger-button {
  border: 0;
  border-radius: 10px;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease, transform 150ms ease, box-shadow 150ms ease;
}

.header-button {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  color: #4d4b47;
  background: transparent;
  font-size: 13px;
  font-weight: 680;
}

.header-button:hover {
  background: rgba(32, 32, 31, 0.055);
}

.header-button--accent {
  color: var(--accent-deep);
  background: var(--accent-soft);
}

.header-button--accent:hover {
  background: #e4e0ff;
}

.auth-button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.68);
}

.auth-button--strong {
  color: #fff;
  border-color: var(--ink);
  background: var(--ink);
}

.auth-button--strong:hover {
  background: #343432;
}

.sync-status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255,255,255,0.62);
  border: 1px solid rgba(222,219,212,0.9);
  font-size: 11px;
  white-space: nowrap;
}

.sync-status[data-state="syncing"] {
  color: var(--accent-deep);
  background: var(--accent-soft);
}

.sync-status[data-state="synced"] {
  color: var(--success);
  background: #edf8f2;
}

.sync-status[data-state="error"] {
  color: var(--danger);
  background: var(--danger-soft);
}

.user-button {
  width: 32px;
  min-width: 32px;
  height: 32px;
}

.icon-button {
  width: 36px;
  height: 36px;
  display: inline-grid;
  place-items: center;
  color: #55534f;
  background: transparent;
  font-weight: 800;
  letter-spacing: 1px;
}

.icon-button:hover {
  background: rgba(32, 32, 31, 0.06);
}

.main-layout {
  width: min(1480px, calc(100% - 32px));
  height: calc(100vh - var(--header-height) - 24px);
  min-height: 610px;
  margin: 12px auto;
  display: grid;
  grid-template-columns: minmax(340px, 0.82fr) minmax(500px, 1.18fr);
  gap: 12px;
}

.panel {
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(210, 206, 198, 0.9);
  border-radius: var(--radius-lg);
  background: rgba(255,255,255,0.9);
  box-shadow: 0 5px 18px rgba(49, 43, 33, 0.04);
  overflow: hidden;
}

.library-panel {
  display: flex;
  flex-direction: column;
  padding: 20px;
}

.panel-heading,
.prompt-identity,
.detail-section-title,
.detail-section-title--action,
.dialog-header,
.dialog-footer,
.rail-title-row,
.rail-section-heading,
.html-editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.panel-heading h1,
.prompt-identity h2,
.dialog-header h2,
.detail-section h3,
.work-stage-empty h2 {
  margin: 0;
  letter-spacing: -0.035em;
}

.panel-heading h1 {
  font-size: 24px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.09em;
}

.quiet-button,
.mini-button {
  color: #55534f;
  background: transparent;
  font-weight: 700;
}

.quiet-button {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 12px;
}

.quiet-button:hover,
.mini-button:hover {
  color: var(--ink);
  background: var(--panel-soft);
}

.mini-button {
  min-height: 28px;
  padding: 0 8px;
  font-size: 11px;
}

.note-composer {
  margin-top: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #fff;
  box-shadow: 0 7px 22px rgba(43, 38, 31, 0.04);
}

.note-composer textarea,
.rail-composer textarea {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  line-height: 1.65;
  outline: 0;
}

.note-composer textarea::placeholder,
.rail-composer textarea::placeholder {
  color: #a09d97;
}

.composer-row,
.rail-composer > div,
.restore-row,
.reference-editor-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.composer-row {
  justify-content: space-between;
  margin-top: 8px;
}

select,
input[type="text"],
input[type="search"],
input[type="url"],
textarea:not(.note-composer textarea):not(.rail-composer textarea) {
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: #fff;
}

select,
input[type="text"],
input[type="search"],
input[type="url"] {
  min-height: 38px;
  padding: 0 10px;
}

textarea:not(.note-composer textarea):not(.rail-composer textarea) {
  padding: 10px 11px;
  line-height: 1.6;
}

.composer-row select {
  width: min(190px, 52%);
  min-height: 34px;
  border-color: transparent;
  background: var(--panel-soft);
  font-size: 12px;
}

.primary-button,
.secondary-button,
.danger-button {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 750;
}

.primary-button {
  color: #fff;
  background: var(--ink);
  box-shadow: 0 4px 12px rgba(32, 32, 31, 0.12);
}

.primary-button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: #383836;
}

.primary-button--spark {
  background: var(--accent);
  box-shadow: 0 5px 16px rgba(102, 87, 232, 0.24);
}

.primary-button--spark:hover:not(:disabled) {
  background: var(--accent-deep);
}

.primary-button--wide {
  width: 100%;
}

.secondary-button {
  color: #4d4b47;
  border: 1px solid var(--line);
  background: #fff;
}

.secondary-button:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--panel-soft);
}

.danger-button {
  color: var(--danger);
  background: var(--danger-soft);
}

.library-tools {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 14px;
}

.search-field {
  min-width: 0;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
  color: var(--muted);
}

.search-field input {
  min-width: 0;
  width: 100%;
  min-height: 34px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
}

.library-tools > select {
  max-width: 160px;
  background: var(--panel-soft);
}

.note-list {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
  padding-right: 3px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.empty-state,
.prompt-empty,
.drop-zone-empty,
.rail-empty,
.work-stage-empty,
.list-empty {
  color: var(--muted);
  text-align: center;
}

.empty-state {
  min-height: 260px;
  display: grid;
  place-content: center;
  padding: 28px;
}

.empty-state h2,
.prompt-empty h2,
.drop-zone-empty h3 {
  margin: 10px 0 5px;
  color: var(--ink);
  font-size: 17px;
}

.empty-state p,
.prompt-empty p,
.drop-zone-empty p,
.rail-empty p {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
}

.empty-glyph {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  margin: 0 auto;
  border: 1px dashed var(--line-strong);
  border-radius: 14px;
  color: var(--accent);
  background: var(--accent-soft);
  font-size: 22px;
}

.note-card {
  position: relative;
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  gap: 9px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
  transition: border-color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.note-card:hover {
  border-color: var(--line-strong);
  box-shadow: 0 8px 22px rgba(48, 43, 35, 0.06);
}

.note-card.is-selected {
  border-color: var(--project-color, var(--accent));
  box-shadow: inset 3px 0 0 var(--project-color, var(--accent));
}

.note-card.is-dragging,
.selected-card.is-dragging,
.rail-selected-card.is-dragging {
  opacity: 0.45;
}

.drag-handle {
  padding-top: 1px;
  color: #b4b0a9;
  cursor: grab;
  user-select: none;
}

.drag-handle:active {
  cursor: grabbing;
}

.note-card-main {
  min-width: 0;
  cursor: pointer;
}

.note-card-main p,
.selected-copy p,
.rail-selected-card p,
.rail-library-card p {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.note-card-main p {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  font-size: 13px;
}

.note-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 7px;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  min-height: 21px;
  padding: 0 7px;
  border-radius: 999px;
  color: #5b5750;
  background: #f1efea;
  font-size: 10px;
  font-weight: 750;
}

.pin-mark {
  color: #a36e1c;
  font-size: 11px;
}

.membership-dots {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
}

.membership-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--dot-color);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.08);
}

.note-add-button,
.selected-remove-button,
.rail-add-button {
  width: 30px;
  height: 30px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  color: #5d5a55;
  background: var(--panel-soft);
  font-size: 18px;
  line-height: 1;
}

.note-add-button:hover,
.rail-add-button:hover {
  color: #fff;
  background: var(--project-color, var(--accent));
}

.note-card.is-selected .note-add-button {
  color: #fff;
  background: var(--project-color, var(--accent));
}

.prompt-panel {
  display: flex;
  flex-direction: column;
  position: relative;
}

.prompt-strip-row,
.workbench-rail-head {
  min-height: 57px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(250,249,247,0.92);
}

.prompt-tabs {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}

.prompt-tabs::-webkit-scrollbar {
  display: none;
}

.prompt-tab {
  position: relative;
  flex: 0 0 auto;
  max-width: 200px;
  min-height: 35px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 10px;
  color: #6b6862;
  background: transparent;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.prompt-tab:hover {
  background: #f0eee9;
}

.prompt-tab.is-active {
  color: var(--ink);
  border-color: color-mix(in srgb, var(--tab-color) 36%, var(--line));
  background: color-mix(in srgb, var(--tab-color) 10%, #fff);
  box-shadow: inset 0 -2px 0 var(--tab-color);
}

.prompt-tab-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--tab-color);
}

.prompt-tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
}

.prompt-tab-count {
  min-width: 19px;
  height: 19px;
  display: inline-grid;
  place-items: center;
  padding: 0 5px;
  border-radius: 999px;
  color: #77736c;
  background: rgba(255,255,255,0.72);
  font-size: 9px;
}

.new-prompt-button {
  width: 36px;
  min-width: 36px;
  height: 36px;
  color: var(--accent-deep);
  border: 1px dashed #b8b0ed;
  background: var(--accent-soft);
  font-size: 20px;
}

.new-prompt-button:hover {
  border-style: solid;
  background: #e6e1ff;
}

.prompt-empty {
  flex: 1;
  display: grid;
  place-content: center;
  padding: 28px;
}

.prompt-empty .primary-button {
  margin: 16px auto 0;
}

.prompt-workspace {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.prompt-identity {
  min-height: 74px;
  padding: 14px 18px 11px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, color-mix(in srgb, var(--project-color) 8%, #fff), #fff 58%);
}

.prompt-title-wrap {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.prompt-color-dot {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--project-color, var(--accent));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--project-color, var(--accent)) 14%, transparent);
}

.prompt-identity h2 {
  max-width: 520px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 20px;
}

.prompt-heading-actions {
  display: flex;
  align-items: center;
  gap: 5px;
}

.view-switch,
.rail-view-switch {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 8px 14px 0;
}

.view-switch button,
.rail-view-switch button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 11px;
  border: 0;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  font-size: 12px;
  font-weight: 750;
}

.view-switch button span {
  min-width: 19px;
  height: 19px;
  display: inline-grid;
  place-items: center;
  padding: 0 5px;
  border-radius: 999px;
  background: #ece9e3;
  font-size: 9px;
}

.view-switch button.is-active,
.rail-view-switch button.is-active {
  color: var(--ink);
  background: #efede8;
}

.builder-view,
.preview-view {
  min-height: 0;
  flex: 1;
  padding: 12px 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.builder-view.is-drop-active {
  background: color-mix(in srgb, var(--project-color) 7%, transparent);
}

.selected-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.selected-card {
  display: grid;
  grid-template-columns: 28px 16px minmax(0,1fr) auto;
  gap: 8px;
  align-items: start;
  padding: 11px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--project-color, var(--accent));
  border-radius: 12px;
  background: #fff;
}

.selected-card:hover {
  border-color: color-mix(in srgb, var(--project-color) 28%, var(--line));
}

.selected-order {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--project-color, var(--accent));
  background: color-mix(in srgb, var(--project-color) 10%, #fff);
  font-size: 10px;
  font-weight: 800;
}

.selected-copy {
  min-width: 0;
  cursor: pointer;
}

.selected-copy .tag-pill {
  margin-bottom: 6px;
}

.selected-copy p {
  font-size: 13px;
}

.selected-remove-button {
  color: #8a8780;
  background: transparent;
  font-size: 16px;
}

.selected-remove-button:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.drop-zone-empty {
  min-height: 330px;
  display: grid;
  place-content: center;
  padding: 28px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  background: linear-gradient(145deg, #fbfaf8, #f6f4ef);
}

.preview-view {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.preview-meta {
  min-height: 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
}

.output-badge {
  min-height: 23px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border-radius: 999px;
  color: var(--accent-deep);
  background: var(--accent-soft);
  font-weight: 750;
}

.preview-view pre,
.rail-preview-view pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #292826;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fbfaf8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Noto Sans Mono", monospace;
  line-height: 1.72;
}

.preview-view pre {
  min-height: 100%;
  padding: 18px;
  font-size: 13px;
}

.prompt-footer {
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: rgba(250,249,247,0.94);
}

.workbench {
  position: fixed;
  z-index: 40;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #efede8;
}

.workbench-header {
  min-height: 62px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-strong);
  background: rgba(250,249,247,0.96);
}

.workbench-source-controls {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.url-field {
  min-width: 220px;
  width: min(540px, 54vw);
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.url-field span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
}

.url-field input {
  min-width: 0;
  width: 100%;
  min-height: 36px;
  padding: 0;
  border: 0;
  outline: 0;
}

.source-divider {
  color: #9b9891;
  font-size: 10px;
}

.workbench-body {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: 410px minmax(0, 1fr);
  gap: 1px;
  background: var(--line-strong);
}

.workbench-prompt-rail,
.work-stage {
  min-width: 0;
  min-height: 0;
  background: #fff;
}

.workbench-prompt-rail {
  display: flex;
  flex-direction: column;
}

.workbench-rail-head {
  min-height: 54px;
  padding: 8px 10px;
}

.prompt-tabs--compact .prompt-tab {
  max-width: 148px;
  min-height: 32px;
  padding: 0 8px;
  font-size: 11px;
}

.workbench-prompt-body {
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.rail-title-row {
  min-height: 50px;
  justify-content: flex-start;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(90deg, color-mix(in srgb, var(--project-color) 9%, #fff), #fff 70%);
}

.rail-title-row strong {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.rail-view-switch {
  padding: 7px 10px 0;
}

.rail-view-switch button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 11px;
}

.rail-build-view,
.rail-preview-view {
  min-height: 0;
  flex: 1;
  padding: 8px 10px 10px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.rail-composer {
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.rail-composer > div {
  justify-content: space-between;
  margin-top: 5px;
}

.rail-composer select {
  max-width: 170px;
  min-height: 31px;
  border-color: transparent;
  background: var(--panel-soft);
  font-size: 11px;
}

.rail-composer .primary-button {
  min-height: 32px;
  padding: 0 11px;
  font-size: 11px;
}

.rail-section-heading {
  margin: 12px 2px 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.rail-selected-list,
.rail-library-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.rail-selected-card,
.rail-library-card {
  display: grid;
  grid-template-columns: 14px minmax(0,1fr) auto;
  gap: 7px;
  align-items: start;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

.rail-selected-card {
  border-left: 3px solid var(--project-color, var(--accent));
}

.rail-selected-card p,
.rail-library-card p {
  display: -webkit-box;
  overflow: hidden;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  font-size: 11px;
  cursor: pointer;
}

.rail-card-grip {
  color: #b2aea7;
  font-size: 12px;
  cursor: grab;
}

.rail-library {
  margin-top: 10px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
}

.search-field--small {
  min-height: 34px;
  margin-bottom: 7px;
  background: #fff;
}

.search-field--small input {
  min-height: 30px;
  font-size: 11px;
}

.rail-library-card {
  background: #fff;
}

.rail-add-button {
  width: 26px;
  height: 26px;
  font-size: 15px;
}

.rail-preview-view pre {
  min-height: 100%;
  padding: 12px;
  font-size: 11px;
}

.rail-footer {
  min-height: 60px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: #faf9f7;
}

.rail-footer .primary-button,
.rail-footer .secondary-button {
  min-height: 35px;
  padding: 0 11px;
  font-size: 11px;
}

.rail-empty {
  flex: 1;
  display: grid;
  place-content: center;
  gap: 13px;
  padding: 24px;
}

.work-stage {
  position: relative;
  overflow: hidden;
}

.work-stage-empty {
  height: 100%;
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 320px));
  place-content: center;
  gap: 16px;
  padding: 30px;
  background:
    linear-gradient(rgba(255,255,255,0.76), rgba(255,255,255,0.76)),
    radial-gradient(circle at 50% 35%, rgba(102,87,232,0.12), transparent 35rem),
    #f6f4ef;
}

.work-stage-choice {
  padding: 28px 24px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255,255,255,0.86);
  box-shadow: 0 12px 32px rgba(44, 39, 31, 0.05);
}

.work-stage-choice > span {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  margin: 0 auto 9px;
  border-radius: 13px;
  color: var(--accent-deep);
  background: var(--accent-soft);
  font-weight: 800;
}

.work-stage-choice h2 {
  font-size: 17px;
}

.work-stage-choice p {
  margin: 7px 0 0;
  font-size: 12px;
  line-height: 1.6;
}

.work-stage-frame,
.html-work-stage {
  width: 100%;
  height: 100%;
}

.work-stage-frame {
  display: flex;
  flex-direction: column;
}

.frame-note {
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px 10px;
  color: #6d6963;
  border-bottom: 1px solid var(--line);
  background: #f7f5f1;
  font-size: 10px;
}

.work-stage-frame iframe,
.html-work-stage iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.html-work-stage {
  display: grid;
  grid-template-columns: 1fr;
}

.html-work-stage.is-editing {
  grid-template-columns: minmax(320px, 0.85fr) minmax(420px, 1.15fr);
  gap: 1px;
  background: var(--line-strong);
}

.html-editor-pane {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #1f2025;
}

.html-editor-toolbar {
  min-height: 40px;
  padding: 6px 9px;
  color: #c9cad1;
  border-bottom: 1px solid #34353d;
  font-size: 11px;
}

.html-editor-toolbar .mini-button {
  color: #e6e7eb;
  background: #34353d;
}

#htmlEditor {
  min-height: 0;
  flex: 1;
  width: 100%;
  padding: 15px;
  border: 0;
  border-radius: 0;
  outline: 0;
  resize: none;
  color: #e7e8ed;
  background: #1f2025;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.65;
  tab-size: 2;
}

.app-dialog {
  max-width: calc(100vw - 28px);
  padding: 0;
  border: 1px solid rgba(202,198,190,0.95);
  border-radius: 19px;
  color: var(--ink);
  background: #fff;
  box-shadow: var(--shadow);
}

.app-dialog::backdrop {
  background: rgba(31, 29, 26, 0.38);
  backdrop-filter: blur(4px);
}

.app-dialog--small { width: 480px; }
.app-dialog--medium { width: 610px; }
.app-dialog--large { width: min(860px, calc(100vw - 28px)); }
.app-dialog--auth { width: min(470px, calc(100vw - 28px)); }

.dialog-shell {
  margin: 0;
}

.dialog-header {
  min-height: 68px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}

.dialog-header h2 {
  font-size: 19px;
}

.dialog-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  color: #67645f;
  background: transparent;
  font-size: 22px;
}

.dialog-close:hover {
  background: var(--panel-soft);
}

.dialog-body {
  max-height: min(72vh, 760px);
  padding: 18px;
  overflow-y: auto;
}

.dialog-footer {
  min-height: 66px;
  justify-content: flex-end;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: #faf9f7;
}

.dialog-footer--split {
  justify-content: space-between;
}

.dialog-footer > div {
  display: flex;
  align-items: center;
  gap: 8px;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.form-stack > textarea {
  width: 100%;
}

.field-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #5f5c56;
  font-size: 11px;
  font-weight: 720;
}

.field-label input,
.field-label select,
.field-label textarea {
  width: 100%;
  color: var(--ink);
  font-weight: 450;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #5b5853;
  font-size: 12px;
}

.inline-create {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.tag-manager-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 14px;
}

.tag-manager-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto auto;
  gap: 7px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-soft);
}

.tag-manager-row input {
  width: 100%;
  background: #fff;
}

.tag-usage-count {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.tag-delete-button {
  width: 31px;
  height: 31px;
  border: 0;
  border-radius: 9px;
  color: #88847d;
  background: transparent;
}

.tag-delete-button:hover {
  color: var(--danger);
  background: var(--danger-soft);
}

.color-fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

.color-fieldset legend {
  margin-bottom: 8px;
  color: #5f5c56;
  font-size: 11px;
  font-weight: 720;
}

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

.color-choice {
  position: relative;
  width: 34px;
  height: 34px;
}

.color-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.color-choice span {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--choice-color);
  box-shadow: 0 0 0 1px var(--line-strong);
}

.color-choice input:checked + span {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--choice-color) 38%, #fff);
}

.color-choice input:checked + span::after {
  content: "✓";
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.detail-sections {
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: #f6f4ef;
}

.detail-section {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.detail-section-title {
  justify-content: flex-start;
  margin-bottom: 13px;
}

.detail-section-title--action {
  justify-content: space-between;
}

.detail-title-copy {
  display: flex;
  align-items: center;
  gap: 14px;
}

.detail-number {
  width: 29px;
  height: 29px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 9px;
  color: var(--accent-deep);
  background: var(--accent-soft);
  font-size: 11px;
  font-weight: 850;
}

.detail-section h3 {
  font-size: 15px;
}

.detail-section-title p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.detail-section > textarea {
  width: 100%;
}

.boost-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.boost-card {
  position: relative;
  min-height: 92px;
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-soft);
  cursor: pointer;
}

.boost-card:has(input:checked) {
  border-color: #a99ff0;
  background: var(--accent-soft);
}

.boost-card input {
  margin: 2px 0 0;
}

.boost-card span {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.boost-card strong {
  font-size: 12px;
}

.boost-card small {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.5;
}

.reference-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.reference-card {
  display: grid;
  grid-template-columns: minmax(0,1fr) auto;
  gap: 8px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-soft);
}

.reference-card strong,
.reference-card p {
  margin: 0;
}

.reference-card strong {
  display: block;
  margin-bottom: 3px;
  font-size: 12px;
}

.reference-card p {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.55;
}

.reference-card-actions {
  display: flex;
  align-items: flex-start;
  gap: 4px;
}

.reference-card-actions button {
  min-height: 28px;
  padding: 0 7px;
  border: 0;
  border-radius: 8px;
  color: #615e59;
  background: #fff;
  font-size: 10px;
}

.reference-card-actions button:hover {
  background: #ece9e3;
}

.reference-editor {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid #beb6f2;
  border-radius: 12px;
  background: #faf9ff;
}

.reference-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.field-label--wide {
  grid-column: 1 / -1;
}

.reference-editor-actions {
  justify-content: flex-end;
  margin-top: 12px;
}

.settings-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.settings-row {
  width: 100%;
  min-height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}

.settings-row:hover {
  background: var(--panel-soft);
}

.settings-row span:first-child {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.settings-row strong {
  font-size: 12px;
}

.settings-row small {
  color: var(--muted);
  font-size: 10px;
}

.settings-row--file {
  cursor: pointer;
}

.settings-row--danger strong,
.settings-row--danger > span:last-child {
  color: var(--danger);
}

.auth-mount {
  min-height: 400px;
  display: grid;
  place-items: center;
  padding: 10px 18px 20px;
}

.paywall-body > p {
  margin: 0 0 16px;
  color: #55524d;
  font-size: 13px;
  line-height: 1.7;
}

.paywall-body details {
  margin-top: 14px;
  color: var(--muted);
  font-size: 11px;
}

.paywall-body summary {
  cursor: pointer;
}

.restore-row {
  margin-top: 10px;
}

.restore-row input {
  min-width: 0;
  flex: 1;
}

.toast-region {
  position: fixed;
  z-index: 100;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: min(380px, calc(100vw - 36px));
  padding: 11px 13px;
  border: 1px solid rgba(210,206,198,0.95);
  border-radius: 12px;
  color: #fff;
  background: #292826;
  box-shadow: 0 14px 35px rgba(31, 29, 26, 0.22);
  font-size: 12px;
  line-height: 1.55;
  pointer-events: auto;
  animation: toast-in 180ms ease-out both;
}

.toast[data-tone="error"] {
  background: #8f3e37;
}

.toast[data-tone="success"] {
  background: #286a4e;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(7px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 1080px) {
  .app-header {
    padding: 0 14px;
  }

  .brand span:last-child {
    display: none;
  }

  .main-layout {
    width: calc(100% - 20px);
    grid-template-columns: minmax(300px, 0.86fr) minmax(440px, 1.14fr);
  }

  .workbench-body {
    grid-template-columns: 360px minmax(0, 1fr);
  }

  .source-divider {
    display: none;
  }
}

@media (max-width: 820px) {
  :root {
    --header-height: 60px;
  }

  .app-header {
    gap: 8px;
  }

  .header-actions {
    gap: 4px;
  }

  .sync-status {
    display: none;
  }

  .header-button--accent {
    font-size: 0;
  }

  .header-button--accent span {
    font-size: 16px;
  }

  .main-layout {
    height: auto;
    min-height: calc(100vh - var(--header-height) - 18px);
    grid-template-columns: 1fr;
  }

  .library-panel,
  .prompt-panel {
    min-height: 620px;
  }

  .workbench-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
  }

  .workbench-source-controls .secondary-button:last-of-type,
  .workbench-source-controls .source-divider {
    display: none;
  }

  .url-field {
    min-width: 0;
    width: 100%;
  }

  .workbench-body {
    grid-template-columns: 330px minmax(500px, 1fr);
    overflow-x: auto;
  }

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

@media (max-width: 560px) {
  .main-layout {
    width: calc(100% - 12px);
    margin: 6px auto;
    gap: 7px;
  }

  .panel {
    border-radius: 17px;
  }

  .library-panel {
    padding: 14px;
  }

  .prompt-identity {
    padding-inline: 13px;
  }

  .prompt-identity h2 {
    max-width: 210px;
    font-size: 17px;
  }

  .prompt-heading-actions .quiet-button {
    font-size: 0;
    width: 34px;
    padding: 0;
  }

  .prompt-heading-actions .quiet-button::before {
    content: "✦";
    font-size: 13px;
  }

  .selected-card {
    grid-template-columns: 25px minmax(0,1fr) auto;
  }

  .selected-card > .drag-handle {
    display: none;
  }

  .dialog-body {
    padding: 14px;
  }

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

  .field-label--wide {
    grid-column: auto;
  }

  .dialog-footer--split {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .dialog-footer--split > div {
    width: 100%;
  }

  .dialog-footer--split > div button {
    flex: 1;
  }

  .workbench {
    min-width: 820px;
  }
}
