:root {
  --desk: #161310;
  --desk-2: #1e1a15;
  --ink: #f0e8da;
  --mute: #8a8074;
  --rule: rgba(240, 232, 218, 0.1);
  --paper: #f7f1e6;
  --paper-ink: #1b1814;
  --amber: #e8a87c;
  --amber-soft: rgba(232, 168, 124, 0.38);
  --broken: #c45c3a;
  --good: #6f9e82;
  --ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --read: "Iowan Old Style", "Palatino Linotype", Palatino, "Songti SC", "Noto Serif SC", serif;
  --mono: "SF Mono", "IBM Plex Mono", ui-monospace, Menlo, monospace;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--desk);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.mast {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--rule);
  background: var(--desk-2);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.85rem;
  min-width: 0;
}

.mark {
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  color: var(--ink);
  flex-shrink: 0;
}

.hook {
  color: var(--mute);
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

nav a {
  color: var(--mute);
  text-decoration: none;
  font-size: 0.88rem;
}

nav a:hover {
  color: var(--amber);
}

.status {
  margin: 0;
  padding: 0.55rem 1.25rem;
  background: rgba(232, 168, 124, 0.12);
  color: var(--amber);
  border-bottom: 1px solid var(--rule);
}

body.busy .status {
  background: rgba(232, 168, 124, 0.22);
  font-variant-numeric: tabular-nums;
}

body.busy .btn,
body.busy label.file {
  opacity: 0.55;
  pointer-events: none;
}

.stage {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(280px, 0.85fr);
  gap: 1rem;
  padding: 1rem 1.25rem 0.5rem;
  min-height: 0;
}

.well,
.note {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.sheet-bar,
.note-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.65rem;
}

.btn,
select,
.page-nav button {
  font: inherit;
  color: var(--ink);
  background: rgba(240, 232, 218, 0.06);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.38rem 0.7rem;
  cursor: pointer;
}

.btn:hover,
select:hover,
.page-nav button:hover {
  background: rgba(240, 232, 218, 0.12);
}

.btn.accent {
  background: var(--amber);
  color: #1b140e;
  font-weight: 600;
}

.btn.accent:hover {
  filter: brightness(1.05);
}

.btn.ghost {
  color: var(--mute);
}

.file {
  display: inline-flex;
  align-items: center;
}

.file input {
  display: none;
}

select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--mute) 50%),
    linear-gradient(135deg, var(--mute) 50%, transparent 50%);
  background-position: calc(100% - 14px) 55%, calc(100% - 9px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 1.6rem;
  max-width: 11rem;
  color-scheme: dark;
}

.doc-chip {
  font-size: 0.78rem;
  color: var(--mute);
  background: rgba(232, 168, 124, 0.1);
  border-radius: 999px;
  padding: 0.25rem 0.65rem;
  max-width: 12rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  margin-left: auto;
  color: var(--mute);
  font-variant-numeric: tabular-nums;
}

.page-nav button {
  width: 2rem;
  padding: 0.3rem 0;
  font-size: 1.1rem;
  line-height: 1;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 22rem;
  background:
    radial-gradient(ellipse at 30% 20%, rgba(232, 168, 124, 0.07), transparent 55%),
    #0f0d0b;
  border-radius: 12px;
  padding: 1.25rem;
  overflow: auto;
  border: 1px solid var(--rule);
}

.empty-sheet {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 18rem;
  text-align: center;
  gap: 0.35rem;
  color: var(--mute);
}

.empty-title {
  margin: 0;
  font-size: 1.15rem;
  color: var(--ink);
  font-weight: 550;
}

.empty-sub {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
}

body.has-doc .empty-sheet {
  display: none;
}

body.has-doc .page-stack {
  display: block !important;
}

.page-stack {
  position: relative;
  display: block;
  width: max-content;
  max-width: 100%;
  margin: 0 auto;
  user-select: none;
}

canvas {
  display: block;
  max-width: 100%;
  height: auto;
  background: white;
  border-radius: 2px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.2),
    0 18px 48px rgba(0, 0, 0, 0.45),
    0 2px 0 rgba(255, 255, 255, 0.04);
}

svg.mesh {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: text;
}

.mesh-glyph {
  fill: var(--amber-soft);
}

.mesh-marquee {
  fill: rgba(232, 168, 124, 0.06);
  stroke: var(--amber);
  stroke-width: 1;
  stroke-dasharray: 4 3;
}

.hint {
  margin: 0.55rem 0 0;
  font-size: 0.8rem;
  color: var(--mute);
}

.note {
  background: transparent;
}

.note-bar h2 {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--mute);
  min-width: 4rem;
}

.seg {
  display: inline-flex;
  background: rgba(240, 232, 218, 0.06);
  border-radius: var(--radius);
  padding: 2px;
}

.seg button {
  font: inherit;
  border: 0;
  background: transparent;
  color: var(--mute);
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
}

.seg button .en {
  font-size: 0.68rem;
  opacity: 0.55;
  text-transform: lowercase;
}

.seg button.on {
  background: rgba(240, 232, 218, 0.14);
  color: var(--ink);
}

.note-bar .btn {
  margin-left: auto;
}

.note-body {
  flex: 1;
  min-height: 22rem;
  background: var(--paper);
  color: var(--paper-ink);
  border-radius: 12px;
  padding: 1.35rem 1.4rem 1.5rem;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.35),
    0 22px 50px rgba(0, 0, 0, 0.4);
  overflow: auto;
}

.paste {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: var(--read);
  font-size: 1.12rem;
  line-height: 1.65;
  color: var(--paper-ink);
  background: transparent;
  border: 0;
  padding: 0;
  min-height: 100%;
}

.paste.empty-paste {
  color: #8a8174;
  font-style: italic;
}

.paste.naive {
  font-family: var(--mono);
  font-size: 0.86rem;
  line-height: 1.4;
  color: var(--broken);
  font-style: normal;
}

body.mode-naive .note-body {
  box-shadow:
    0 0 0 1px rgba(196, 92, 58, 0.35),
    0 22px 50px rgba(0, 0, 0, 0.4);
}

body.mode-fix .note-body {
  box-shadow:
    0 0 0 1px rgba(111, 158, 130, 0.25),
    0 22px 50px rgba(0, 0, 0, 0.4);
}

footer {
  padding: 0.7rem 1.25rem 1rem;
  color: var(--mute);
  font-size: 0.8rem;
  border-top: 1px solid var(--rule);
}

footer code {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--amber);
}

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

  .hook {
    display: none;
  }

  .canvas-wrap,
  .note-body {
    min-height: 16rem;
  }
}
