:root {
  color-scheme: light;
  --canvas: #f3f4f6;
  --surface: #ffffff;
  --stage: #e9ecef;
  --ink: #111827;
  --muted: #5b6472;
  --line: #e2e6ec;
  --line-strong: #cbd2dc;
  --hust: #b41e28;
  --hust-deep: #8f151d;
  --hust-soft: #fdf2f3;
  --hust-border: #f0c7ca;
  --radius-sm: 0.45rem;
  --radius-md: 0.7rem;
  --radius-lg: 0.9rem;
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

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

button, summary, select { cursor: pointer; }

:focus-visible {
  outline: 2.5px solid var(--hust);
  outline-offset: 2px;
}

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

.ico { width: 1.05rem; height: 1.05rem; flex: 0 0 auto; }
.ico-sm { width: 0.95rem; height: 0.95rem; flex: 0 0 auto; }

/* Header */
.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.58rem max(1.25rem, calc((100% - 82rem) / 2));
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(12px);
  border-top: 3px solid var(--hust);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
}

.brand-logo {
  height: 2.35rem;
  width: auto;
  display: block;
  object-fit: contain;
  border-radius: 0.2rem;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-weight: 750;
  font-size: 0.98rem;
  letter-spacing: -0.015em;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.badge-hust {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  color: var(--hust);
  background: var(--hust-soft);
  border: 1px solid var(--hust-border);
  padding: 0.16rem 0.45rem;
  border-radius: 999px;
}

.top-nav {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-link {
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0.42rem 0.7rem;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
}

.nav-link:hover {
  color: var(--ink);
  background: var(--canvas);
}

/* Buttons */
.primary, .secondary-btn, .ghost-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-height: 2.5rem;
  padding: 0.5rem 0.95rem;
  border-radius: 0.55rem;
  font-size: 0.88rem;
  font-weight: 650;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid transparent;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.primary {
  background: var(--hust);
  color: #fff;
  border-color: var(--hust);
  box-shadow: 0 2px 8px rgba(180, 30, 40, 0.22);
}

.primary:hover:enabled {
  background: var(--hust-deep);
  border-color: var(--hust-deep);
}

.secondary-btn {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line-strong);
}

.secondary-btn:hover:enabled {
  border-color: var(--hust);
  color: var(--hust);
  background: var(--hust-soft);
}

.ghost-btn {
  min-height: 2.15rem;
  padding: 0.35rem 0.72rem;
  font-size: 0.83rem;
  background: transparent;
  color: var(--ink);
  border-color: var(--line);
}

.ghost-btn:hover:enabled {
  background: var(--canvas);
  border-color: var(--line-strong);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* Main container */
main {
  flex: 1;
  width: 100%;
  max-width: 84.5rem;
  margin: 0 auto;
  padding: 1.1rem 1.25rem 2rem;
}

.intro {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.95rem;
}

.intro-copy { min-width: 0; }

h1 {
  margin: 0;
  font-size: clamp(1.18rem, 1.65vw, 1.45rem);
  font-weight: 750;
  line-height: 1.28;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.intro p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-size: 0.875rem;
  line-height: 1.45;
}

.intro code {
  font-family: "Cascadia Code", Consolas, "Liberation Mono", monospace;
  font-size: 0.85em;
  padding: 0.1rem 0.32rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.3rem;
  color: var(--ink);
}

/* Workspace */
.workspace {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: clamp(23rem, calc(100vh - 17.5rem), 34rem);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 10px rgba(17, 24, 39, 0.04);
  overflow: hidden;
}

.writer.is-dragover {
  border-color: var(--hust);
  box-shadow: 0 0 0 3px rgba(180, 30, 40, 0.14);
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 3.35rem;
  padding: 0.5rem 0.9rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.pane-title {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.pane-head h2, .pane-head label {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.layout-pill {
  font-size: 0.74rem;
  font-weight: 650;
  color: var(--hust);
  background: var(--hust-soft);
  border: 1px solid var(--hust-border);
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
}

/* Editor Toolbar */
.toolbar {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  height: 1.95rem;
  padding: 0 0.52rem;
  border: 1px solid transparent;
  border-radius: 0.4rem;
  background: transparent;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.tool-btn:hover:enabled {
  background: var(--canvas);
  color: var(--ink);
  border-color: var(--line);
}

.tool-btn.tool-accent {
  color: var(--hust);
  background: var(--hust-soft);
  border-color: var(--hust-border);
}

.tool-btn.tool-accent:hover:enabled {
  background: #f9e3e5;
  border-color: var(--hust);
}

.tool-sep {
  width: 1px;
  height: 1.1rem;
  background: var(--line);
  margin: 0 0.15rem;
}

textarea {
  width: 100%;
  flex: 1;
  min-height: 0;
  border: 0;
  resize: none;
  padding: 1rem 1.15rem;
  background: transparent;
  font: 0.89rem/1.65 "Cascadia Code", Consolas, "Liberation Mono", monospace;
  color: var(--ink);
}

textarea::placeholder { color: #8c95a0; }
textarea:focus-visible { outline: none; }

.assets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.55rem 0.9rem;
  border-top: 1px solid var(--line);
  background: #fafaf8;
}

.assets[hidden] { display: none; }

.assets button {
  max-width: 100%;
  overflow-wrap: anywhere;
  min-height: 1.85rem;
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
}

.assets button:hover:enabled {
  border-color: var(--hust);
  color: var(--hust);
  background: var(--hust-soft);
}

.pane-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.9rem;
  border-top: 1px solid var(--line);
  background: #fafaf8;
  color: var(--muted);
  font-size: 0.8rem;
}

.doc-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.78rem;
}

.foot-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex: 0 0 auto;
}

.hint { color: var(--muted); font-size: 0.8rem; }

/* Preview Stage & Paper */
.reader {
  background-color: var(--stage);
  background-image: radial-gradient(rgba(17, 24, 39, 0.07) 1px, transparent 1px);
  background-size: 16px 16px;
}

.paper-stage {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 0.9rem;
  overflow: auto;
}

.paper {
  width: 100%;
  min-width: 0;
  max-width: 38rem;
  min-height: 100%;
  padding: clamp(1.15rem, 2.4vw, 1.85rem);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  box-shadow: 0 4px 14px rgba(17, 24, 39, 0.06);
  line-height: 1.65;
  overflow-wrap: anywhere;
  transition: max-width 0.2s ease;
}

.paper-stage[data-layout="A4_Landscape"] .paper {
  max-width: 48rem;
}

.paper-stage[data-layout="16:9"] .paper {
  max-width: 54rem;
  border-top: 4px solid var(--hust);
}

.paper > :first-child { margin-top: 0; }
.paper > :last-child { margin-bottom: 0; }

.paper hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 1.15rem 0;
}

.paper .preview-math { overflow-wrap: normal; }
.paper .preview-math-display {
  display: block;
  overflow-x: auto;
  padding: .35rem 0;
  text-align: center;
}

.paper h1, .paper h2, .paper h3 {
  font-family: inherit;
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--ink);
}

.paper h1 { font-size: 1.65rem; padding-bottom: 0.35rem; border-bottom: 1px solid var(--line); }
.paper h2 { font-size: 1.28rem; margin-top: 1.35rem; }
.paper h3 { font-size: 1.05rem; margin-top: 1.1rem; }

.paper pre {
  overflow: auto;
  padding: 0.85rem 1rem;
  background: #f4f5f7;
  border: 1px solid var(--line);
  border-radius: 0.45rem;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.85rem;
}

.paper code {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.88em;
  background: #f4f5f7;
  padding: 0.1rem 0.3rem;
  border-radius: 0.25rem;
}

.paper pre code { background: transparent; padding: 0; }

.paper blockquote {
  margin: 1rem 0;
  padding: 0.4rem 0 0.4rem 1rem;
  border-left: 3px solid var(--hust);
  color: var(--muted);
  background: #fafaf9;
}

.paper .preview-callout {
  --callout-accent: #1d4ed8;
  --callout-bg: #eff6ff;
  border-color: var(--callout-accent);
  background: var(--callout-bg);
  color: var(--ink);
  border-radius: .35rem;
  padding: .65rem .85rem;
}

.paper .preview-callout[data-type="tip"],
.paper .preview-callout[data-type="warning"] {
  --callout-accent: #92400e;
  --callout-bg: #fffbeb;
}

.paper .preview-callout[data-type="important"],
.paper .preview-callout[data-type="caution"] {
  --callout-accent: #991b1b;
  --callout-bg: #fef2f2;
}

.paper .preview-callout-label { color: var(--callout-accent); font-weight: 750; }
.paper .preview-callout-label + p { margin-top: .25rem; }
.paper .preview-callout > :last-child { margin-bottom: 0; }

.paper .preview-table {
  max-width: 100%;
  overflow: auto;
  margin: 1rem 0;
}

.paper table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.paper th {
  background: #f4f5f7;
  font-weight: 700;
  text-align: left;
}

.paper td, .paper th {
  min-width: 5rem;
  border: 1px solid var(--line);
  padding: 0.45rem 0.65rem;
  vertical-align: top;
  overflow-wrap: break-word;
}

.paper .has-index :is(td, th):first-child { min-width: 3rem; text-align: center; }
.paper .cell-center { text-align: center; }
.paper .cell-right { text-align: right; }

.paper img {
  display: block;
  height: auto;
  max-width: 100%;
  max-height: 20rem;
  margin: 0.8rem auto;
  border-radius: 0.35rem;
  object-fit: contain;
}

.paper-empty {
  color: var(--muted);
  font-size: 0.92rem;
  padding: 1.5rem 0;
}

/* Export Dock */
.export {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 0.7rem 0.95rem;
  margin-top: 0.8rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 10px rgba(17, 24, 39, 0.04);
}

.options, .actions {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.options label {
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--muted);
}

.export-checks {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem .9rem;
  font-size: .86rem;
  color: var(--ink);
}

.export-checks label { display: flex; align-items: center; gap: .35rem; cursor: pointer; }
.export-checks input { margin: 0; accent-color: var(--hust); }

.preview-tools { display: flex; align-items: center; gap: .4rem; }
#reload-page { font-size: 1.2rem; line-height: 1; min-width: 2rem; min-height: 2rem; }
.paper.is-paginated { padding: 0; background: transparent; border: 0; box-shadow: none; }
.preview-page {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: clamp(1.15rem, 2.4vw, 1.85rem);
  background: white;
  border: 1px solid var(--line);
  border-radius: .45rem;
}
.preview-page + .preview-page { margin-top: .8rem; }
.preview-page-body > :first-child { margin-top: 0; }
.preview-page-body > :last-child { margin-bottom: 0; }
.preview-page-number { margin-top: auto; padding-top: .8rem; text-align: center; color: var(--muted); font-size: .82rem; }

.export-progress { margin: .85rem 0 .45rem; }
.export-progress-caption { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .35rem; font-size: .85rem; }
#progress-percent { font-variant-numeric: tabular-nums; }
.progress-track { height: .7rem; margin: 0 .65rem; border-radius: 2rem; background: #e4eff6; }
.progress-water { position: relative; width: 0; height: 100%; border-radius: inherit; background: #449aca; transition: width .2s ease; }
.progress-duck { position: absolute; right: 0; top: 50%; transform: translate(50%, -50%) scaleX(-1); }
.export-progress.is-running .progress-duck { animation: duck-swim .75s ease-in-out infinite alternate; }
@keyframes duck-swim {
  to { transform: translate(50%, -64%) scaleX(-1) rotate(-8deg); }
}
@media (prefers-reduced-motion: reduce) {
  .progress-water { transition: none; }
  .export-progress.is-running .progress-duck { animation: none; }
}
.save-dialog { width: min(28rem, calc(100% - 2rem)); border: 1px solid var(--line); border-radius: .75rem; padding: 1.2rem; color: var(--ink); }
.save-dialog::backdrop { background: #14182166; }
.save-dialog label { display: block; font-weight: 700; }
.save-dialog input { width: 100%; margin-top: .4rem; padding: .5rem; border: 1px solid var(--line); border-radius: .4rem; font: inherit; }
.save-dialog p { color: var(--muted); font-size: .85rem; }
.save-dialog .actions { justify-content: flex-end; }

.layout-switch {
  display: inline-flex;
  padding: 0.2rem;
  background: var(--canvas);
  border: 1px solid var(--line);
  border-radius: 0.55rem;
  gap: 0.2rem;
}

.seg-btn {
  min-height: 2rem;
  padding: 0.28rem 0.72rem;
  border: 0;
  border-radius: 0.4rem;
  background: transparent;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--muted);
  transition: background 0.14s ease, color 0.14s ease, box-shadow 0.14s ease;
}

.seg-btn:hover:enabled { color: var(--ink); }

.seg-btn.is-active {
  background: var(--surface);
  color: var(--hust);
  box-shadow: 0 1px 3px rgba(24, 28, 32, 0.1);
}

/* Status */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.65rem 0.15rem 1.35rem;
  min-height: 1.4rem;
}

#status {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

#status.error {
  color: var(--hust);
  font-weight: 600;
}

#download-title { margin: 0 0 .85rem; font-size: 1.1rem; }
.download-formats { display: flex; flex-wrap: wrap; gap: .55rem; margin-bottom: .85rem; }
.download-formats button { flex: 1 1 8rem; justify-content: center; }

/* Guide */
.guide {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 0.95rem 1.15rem;
}

.guide summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 700;
  font-size: 0.94rem;
  list-style: none;
}

.guide summary::-webkit-details-marker { display: none; }

.guide-toggle::before {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 0.35rem;
  background: var(--canvas);
  color: var(--muted);
  font-weight: 700;
}

.guide[open] .guide-toggle::before { content: "−"; color: var(--hust); background: var(--hust-soft); }

.guide-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.9rem;
  margin-top: 1rem;
  padding-top: 0.95rem;
  border-top: 1px solid var(--line);
}

.guide-step {
  padding: 0.85rem;
  background: var(--canvas);
  border-radius: var(--radius-md);
}

.step-num {
  display: inline-grid;
  place-items: center;
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 999px;
  background: var(--hust);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 750;
  margin-bottom: 0.5rem;
}

.guide-step h3 {
  margin: 0 0 0.35rem;
  font-size: 0.9rem;
  font-weight: 700;
}

.guide-step p {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.55;
  color: var(--muted);
}

.guide-step p + p { margin-top: 0.45rem; }

.guide-step code {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.84em;
  background: var(--surface);
  padding: 0.08rem 0.28rem;
  border-radius: 0.25rem;
  color: var(--ink);
}

.guide-limits {
  margin: 0.85rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.footer-inner {
  max-width: 84.5rem;
  margin: 0 auto;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.footer-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--hust);
  flex: 0 0 auto;
}

.footer-brand strong { color: var(--ink); font-weight: 700; }

.footer-feedback {
  color: #0756b8;
  font-weight: 650;
  text-underline-offset: .18em;
}

/* Responsive */
@media (max-width: 860px) {
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .pane { height: auto; min-height: 20rem; }
  textarea { min-height: 18rem; }
  .paper-stage { min-height: 18rem; }
  .guide-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
  main { padding-top: 1.25rem; }
  .intro { align-items: flex-start; flex-direction: column; }
  .brand-sub { display: none; }
  .actions { width: 100%; }
  .actions button { flex: 1; }
}
