:root {
  --ink: #181714;
  --paper: #f3f0e8;
  --paper-deep: #e7e1d4;
  --acid: #d8ff3e;
  --signal: #ec4d2f;
  --signal-soft: #ffe0d8;
  --safe: #315f43;
  --safe-soft: #dceadf;
  --line: rgba(24, 23, 20, 0.22);
  --muted: #716d64;
  --shadow: 0 22px 60px rgba(32, 28, 19, 0.12);
}

* { box-sizing: border-box; }

html { background: var(--paper); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 8%, rgba(216, 255, 62, 0.34), transparent 28rem),
    linear-gradient(125deg, var(--paper) 0%, #f8f5ed 45%, #ece6d9 100%);
  font-family: "Avenir Next", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

.grain {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.75' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.12'/%3E%3C/svg%3E");
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }

.masthead,
main {
  width: min(1480px, calc(100% - 48px));
  margin-inline: auto;
}

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  padding: 52px 0 32px;
  border-bottom: 2px solid var(--ink);
}

.eyebrow {
  margin: 0 0 8px;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .18em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 850px;
  margin-bottom: 10px;
  font-family: "Bodoni 72", "Songti SC", serif;
  font-size: clamp(48px, 7vw, 104px);
  font-weight: 700;
  letter-spacing: -.06em;
  line-height: .84;
}

.lede {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 16px;
}

.privacy-stamp {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  padding: 11px 15px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: rgba(255,255,255,.35);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .12em;
}

.pulse {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--safe);
  box-shadow: 0 0 0 5px rgba(49,95,67,.14);
}

main { padding: 30px 0 80px; }

.drop-zone {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 28px;
  min-height: 180px;
  padding: 34px;
  border: 2px dashed var(--ink);
  background: rgba(255,255,255,.35);
  transition: transform .18s ease, background .18s ease, box-shadow .18s ease;
}

.drop-zone:hover,
.drop-zone.is-dragging {
  transform: translateY(-3px);
  background: rgba(216,255,62,.28);
  box-shadow: var(--shadow);
}

.drop-index {
  font-family: "Bodoni 72", serif;
  font-size: 72px;
  line-height: 1;
  color: var(--signal);
}

.drop-zone h2 { margin-bottom: 5px; font-size: 25px; }
.drop-zone p { margin: 0; color: var(--muted); }

.primary-button,
.ghost-button,
.clean-button,
.danger-button,
.icon-button {
  border: 1px solid var(--ink);
  border-radius: 0;
  padding: 11px 16px;
  background: transparent;
  color: var(--ink);
  font-weight: 750;
  transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}

.primary-button {
  background: var(--ink);
  color: white;
  box-shadow: 5px 5px 0 var(--acid);
}

.primary-button:hover { transform: translate(-2px,-2px); box-shadow: 7px 7px 0 var(--acid); }
.ghost-button:hover { background: var(--paper-deep); }
.clean-button {
  color: white;
  border-color: var(--signal);
  background: var(--signal);
  box-shadow: 4px 4px 0 #ffb49e;
}
.clean-button:hover { transform: translate(-1px,-1px); box-shadow: 5px 5px 0 #ffb49e; }
.danger-button { color: #9b2818; border-color: #9b2818; }
.danger-button:hover { color: white; background: #9b2818; }
.icon-button { padding: 4px 11px; font-size: 24px; border: 0; }

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: 24px;
  margin-top: 28px;
  animation: rise .45s cubic-bezier(.2,.75,.2,1) both;
}

@keyframes rise { from { opacity: 0; transform: translateY(16px); } }
.is-hidden { display: none !important; }

.preview-panel,
.risk-banner,
.stats,
.signals-section,
.chunks-section,
.export-bar {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.54);
  backdrop-filter: blur(18px);
}

.preview-panel { align-self: start; position: sticky; top: 18px; }
.panel-heading {
  display: flex;
  justify-content: space-between;
  padding: 12px 15px;
  border-bottom: 1px solid var(--line);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
  font-weight: 800;
}

.image-stage {
  display: grid;
  place-items: center;
  min-height: 300px;
  padding: 18px;
  background:
    linear-gradient(45deg, #ddd7ca 25%, transparent 25%),
    linear-gradient(-45deg, #ddd7ca 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ddd7ca 75%),
    linear-gradient(-45deg, transparent 75%, #ddd7ca 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

.image-stage img {
  display: block;
  width: 100%;
  max-height: 64vh;
  object-fit: contain;
  box-shadow: 0 14px 36px rgba(0,0,0,.18);
}

.file-facts { margin: 0; padding: 8px 16px 16px; }
.file-facts div { display: grid; grid-template-columns: 74px minmax(0,1fr); padding: 9px 0; border-bottom: 1px solid var(--line); }
.file-facts div:last-child { border-bottom: 0; }
.file-facts dt { color: var(--muted); font-size: 12px; }
.file-facts dd { margin: 0; overflow-wrap: anywhere; font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; }

.data-panel { display: grid; gap: 18px; }

.risk-banner {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 20px;
  align-items: center;
  padding: 24px;
}

.risk-banner.has-risk { background: var(--signal-soft); border-color: var(--signal); }
.risk-banner.is-clear { background: var(--safe-soft); border-color: var(--safe); }
.risk-mark {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border: 2px solid currentColor;
  border-radius: 50%;
  font-family: "Bodoni 72", serif;
  font-size: 42px;
  line-height: 1;
}
.risk-banner.has-risk .risk-mark { color: var(--signal); }
.risk-banner.is-clear .risk-mark { color: var(--safe); }
.risk-kicker { margin-bottom: 3px; font: 800 10px/1 "SFMono-Regular", Consolas, monospace; letter-spacing: .16em; }
.risk-banner h2 { margin-bottom: 5px; font-size: clamp(20px, 2.5vw, 34px); }
.risk-banner p:last-child { margin-bottom: 0; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(4,1fr); }
.stats div { padding: 18px; border-right: 1px solid var(--line); }
.stats div:last-child { border: 0; }
.stats strong { display: block; font: 700 34px/1 "Bodoni 72", serif; }
.stats span { color: var(--muted); font-size: 12px; }

.signals-section,
.chunks-section { padding: 22px; }
.section-title-row { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 18px; }
.section-title-row h2 { margin: 0; font-size: 24px; }
.toolbar { display: flex; gap: 8px; }

.signal-list { display: grid; gap: 8px; }
.signal-item {
  display: grid;
  grid-template-columns: 88px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-left: 5px solid var(--signal);
  background: rgba(255,255,255,.72);
}
.signal-item code { color: #9b2818; font-family: "SFMono-Regular", Consolas, monospace; font-size: 11px; overflow-wrap: anywhere; }
.signal-item span { color: var(--muted); font-size: 12px; }
.empty-state { padding: 22px; border: 1px dashed var(--line); color: var(--muted); text-align: center; }

.chunk-table-wrap { overflow-x: auto; border: 1px solid var(--line); }
.chunk-table { width: 100%; border-collapse: collapse; min-width: 700px; }
.chunk-table th,
.chunk-table td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.chunk-table th { color: var(--muted); background: var(--paper-deep); font: 800 10px/1 "SFMono-Regular", Consolas, monospace; letter-spacing: .12em; }
.chunk-table tbody tr { transition: background .15s ease; }
.chunk-table tbody tr:hover { background: rgba(216,255,62,.13); }
.chunk-table tbody tr.is-deleted { opacity: .45; text-decoration: line-through; }
.chunk-type { font: 800 15px/1 "SFMono-Regular", Consolas, monospace; }
.chunk-role { max-width: 310px; color: var(--muted); font-size: 12px; }
.badge { display: inline-block; padding: 4px 7px; border: 1px solid currentColor; font: 800 9px/1 "SFMono-Regular", Consolas, monospace; letter-spacing: .08em; }
.badge.risk { color: #a02e1b; background: var(--signal-soft); }
.badge.changed { color: #665400; background: #fff1a8; }
.badge.neutral { color: var(--muted); }
.row-button { padding: 6px 9px; border: 1px solid var(--ink); background: white; font-size: 12px; }

.export-bar { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 20px 22px; border: 2px solid var(--ink); }
.export-title { margin-bottom: 3px; font-weight: 800; }
.export-note { margin: 0; color: var(--muted); font-size: 12px; }

.editor-dialog { width: min(760px, calc(100vw - 28px)); max-height: calc(100vh - 28px); padding: 0; border: 2px solid var(--ink); background: var(--paper); box-shadow: 14px 14px 0 rgba(24,23,20,.22); }
.editor-dialog::backdrop { background: rgba(24,23,20,.66); backdrop-filter: blur(4px); }
.dialog-shell { display: grid; max-height: calc(100vh - 32px); }
.dialog-header,
.dialog-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; }
.dialog-header { border-bottom: 1px solid var(--line); }
.dialog-header h2 { margin: 0; }
.dialog-body { overflow-y: auto; padding: 20px; }
.dialog-footer { border-top: 1px solid var(--line); }
.dialog-footer > div { display: flex; gap: 8px; }
.warning-box { margin-bottom: 18px; padding: 14px; border: 1px solid var(--signal); background: var(--signal-soft); }
.warning-box p { margin: 5px 0 0; font-size: 13px; }
.field-grid { display: grid; gap: 12px; margin-bottom: 16px; }
.field { display: grid; gap: 6px; }
.field span { color: var(--muted); font-size: 12px; font-weight: 700; }
input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 0; padding: 11px; color: var(--ink); background: rgba(255,255,255,.78); }
textarea { resize: vertical; font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; line-height: 1.5; }
input:focus, textarea:focus, button:focus-visible, .drop-zone:focus-visible { outline: 3px solid var(--acid); outline-offset: 2px; }
.raw-editor { margin-top: 14px; padding: 13px; border: 1px solid var(--line); }
.raw-editor summary { cursor: pointer; font-weight: 800; }
.raw-editor p { color: var(--muted); font-size: 12px; }
.small-dialog { width: min(560px, calc(100vw - 28px)); }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: 420px;
  padding: 12px 16px;
  color: white;
  background: var(--ink);
  box-shadow: 5px 5px 0 var(--acid);
  opacity: 0;
  transform: translateY(14px);
  pointer-events: none;
  transition: .2s ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: #9b2818; box-shadow-color: #ffb49e; }

@media (max-width: 920px) {
  .masthead { align-items: flex-start; }
  .workspace { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
  .image-stage img { max-height: 70vh; }
}

@media (max-width: 640px) {
  .masthead, main { width: min(100% - 24px, 1480px); }
  .masthead { display: grid; padding-top: 28px; }
  .drop-zone { grid-template-columns: 1fr; }
  .drop-index { font-size: 48px; }
  .stats { grid-template-columns: repeat(2,1fr); }
  .stats div:nth-child(2) { border-right: 0; }
  .stats div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .section-title-row, .export-bar { align-items: stretch; flex-direction: column; }
  .toolbar { flex-wrap: wrap; }
  .dialog-footer { align-items: stretch; flex-direction: column-reverse; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

.image-stage video { width: 100%; max-height: 64vh; background: #181714; }
.video-fields { margin: 18px 0 0; }
.video-fields div { border-top: 1px solid var(--line); padding: 12px 0; }
.video-fields dt { font-weight: 750; font-size: 12px; overflow-wrap: anywhere; }
.video-fields dd { margin: 5px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.6 "SFMono-Regular", Consolas, monospace; max-height: 240px; overflow: auto; }
.toolbar { flex-wrap: wrap; }
.signal-item { grid-template-columns: minmax(88px, 150px) minmax(0, 1fr); }
.signal-item span { grid-column: 2; overflow-wrap: anywhere; }
.data-panel, .preview-panel { min-width: 0; }
@media (max-width: 920px) { .workspace { grid-template-columns: minmax(0, 1fr); } }

.data-panel { grid-template-columns: minmax(0, 1fr); }
.data-panel > section, .chunk-table-wrap { min-width: 0; }
.risk-banner > div { min-width: 0; overflow-wrap: anywhere; }

.risk-banner.is-unknown { background: #fff1cb; border-color: #8b6b29; }
.risk-banner.is-unknown .risk-mark { color: #8b6b29; }

.offline-status { width: min(1480px, calc(100% - 48px)); margin: 14px auto 0; color: var(--muted); font-size: 12px; }
@media (max-width: 640px) { .offline-status { width: calc(100% - 24px); } }

button:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.export-actions { display: flex; gap: 10px; flex-wrap: wrap; flex-shrink: 0; }
#editorLimit { margin-bottom: 16px; padding: 12px; border: 1px solid var(--line); }
