:root {
  color-scheme: light;
  --bg: #f6f2f0;
  --paper: #fffdf8;
  --ink: #171717;
  --muted: #68645e;
  --line: #ddd5cc;
  --soft: #f0e8df;
  --accent: #a83f5f;
  --accent-2: #146b68;
  --danger: #a63b2f;
  --shadow: 0 18px 45px rgba(40, 24, 18, 0.10);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Bahnschrift, "Segoe UI", Arial, sans-serif;
}

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

button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  min-height: 40px;
  padding: 8px 13px;
  border-radius: 8px;
  cursor: pointer;
}

button:hover {
  border-color: #bdb3a8;
}

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

button.warn {
  border-color: #d8aaa3;
  color: var(--danger);
}

.hidden,
.view:not(.active),
.editor-mode-panel.hidden {
  display: none !important;
}

.hidden-file {
  display: none;
}

.shell {
  min-height: 100vh;
}

.login {
  width: min(420px, calc(100vw - 32px));
  margin: 12vh auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 4px;
  font-size: 30px;
}

h2 {
  margin-bottom: 8px;
}

p,
label,
.status,
.toast,
#previewHint,
#topSummary,
#countBadge,
#stageMeta {
  color: var(--muted);
}

label {
  display: grid;
  gap: 6px;
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  min-height: 40px;
  padding: 8px 10px;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

.app {
  min-height: 100vh;
  padding: 18px;
}

.topbar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: center;
  max-width: 1280px;
  margin: 0 auto 18px;
}

.tabs,
.segmented,
.filters,
.action-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.tab,
.segmented button,
.filters button {
  background: rgba(255, 255, 255, 0.72);
}

.tab.active,
.segmented button.active,
.filters button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.view {
  max-width: 1280px;
  margin: 0 auto;
}

.gallery-view {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
}

.stage,
.gallery-panel,
.editor-card,
.preview-card,
.system-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.stage {
  align-content: start;
  display: grid;
  gap: 16px;
  padding: 18px;
}

.stage-copy h2 {
  font-size: 25px;
  margin-bottom: 6px;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 9px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
}

.device-frame {
  width: 244px;
  max-width: 100%;
  aspect-ratio: 1;
  border: 14px solid #ece8df;
  border-radius: 20px;
  background: #fffef6;
  display: grid;
  place-items: center;
  box-shadow: inset 0 0 0 1px #d8d1c6;
}

.device-frame.large {
  width: min(360px, 100%);
  justify-self: center;
}

.device-frame img,
.device-frame canvas {
  width: 200px;
  height: 200px;
  border: 1px solid #111;
  background: #fff;
  image-rendering: pixelated;
}

#stagePreview {
  display: block;
}

#storedPreview {
  display: none;
}

.gallery-panel,
.editor-card,
.system-card {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.bulk-tools {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin: 12px 0;
}

.note-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(142px, 1fr));
  gap: 12px;
}

.note-card {
  min-height: 0;
  padding: 9px;
  text-align: left;
  display: grid;
  gap: 8px;
  border-radius: 10px;
}

.note-card.active {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
}

.note-card.current {
  background: #edf7f5;
}

.note-card.disabled {
  opacity: 0.56;
}

.note-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  image-rendering: pixelated;
}

.note-card strong,
.note-card span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-card span {
  color: var(--muted);
  font-size: 12px;
}

.editor-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
}

.preview-card {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 12px;
  padding: 18px;
}

.grid {
  display: grid;
  gap: 12px;
}

.editor-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 14px;
}

.editor-mode-panel {
  border-top: 1px solid var(--line);
  padding-top: 14px;
  margin-top: 4px;
}

.metric {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  margin: 10px 0 14px;
  background: #fff9f1;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.label-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
}

.check input {
  width: auto;
}

code {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin: 10px 0 12px;
}

.diagnostics {
  white-space: pre-wrap;
  overflow: auto;
  max-height: 310px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 12px;
  color: var(--ink);
  font: 12px/1.45 ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
}

.diagnostics.ok {
  border-color: #9fcabf;
  background: #f0faf6;
}

.diagnostics.warn {
  border-color: #d6bb70;
  background: #fff9df;
}

.toast {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 3;
  max-width: min(560px, calc(100vw - 36px));
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  padding: 8px 14px;
  box-shadow: var(--shadow);
  font-size: 13px;
}

@media (max-width: 980px) {
  .topbar,
  .gallery-view,
  .editor-view {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: start;
  }
}

@media (max-width: 640px) {
  .app {
    padding: 12px;
  }

  .editor-grid,
  .bulk-tools {
    grid-template-columns: 1fr;
  }

  .note-grid {
    grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  }
}
