:root {
  color: #273444;
  background: #edf0f3;
  font: 14px/1.4 Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 800px; background: #edf0f3; }
button, textarea, select, input { font: inherit; }
button { cursor: pointer; }

.app-shell { display: grid; grid-template-columns: minmax(280px, 22vw) 1fr; height: 100vh; }
.sidebar { display: flex; flex-direction: column; gap: 0; padding: 28px; background: #f7f8fa; border-right: 1px solid #d8dde4; }
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 34px; }
.brand-mark { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; color: #fff; background: #465b81; font-size: 22px; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 16px; }
.brand small { margin-top: 3px; color: #75808e; font-size: 12px; }
.field-label, .settings h2 { margin: 0 0 9px; color: #334050; font-size: 12px; font-weight: 700; }
#editor { width: 100%; height: 205px; resize: vertical; padding: 13px; border: 1px solid #cfd6de; border-radius: 7px; outline: 0; background: #fff; color: #1d2835; font: 14px/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; }
#editor:focus { border-color: #465b81; box-shadow: 0 0 0 3px rgb(70 91 129 / 16%); }
.editor-meta { display: flex; justify-content: space-between; margin: 8px 0 18px; color: #7b8794; font-size: 11px; }
.warning { margin: -10px 0 12px; color: #9b2c2c; font-size: 12px; }
.primary-actions, .history-actions { display: flex; gap: 8px; align-items: center; }
.primary-actions #stop { flex: 0 0 auto; }
.history-actions { margin-top: 9px; }
.history-actions button { padding: 5px 8px; font-size: 11px; }
.history-actions span { margin-left: auto; color: #75808e; font-size: 11px; }
button { border: 1px solid #cfd6de; border-radius: 6px; padding: 8px 13px; background: #fff; color: #334050; }
button:hover { border-color: #9ba9ba; background: #f0f3f7; }
button:focus-visible, select:focus-visible { outline: 2px solid #465b81; outline-offset: 2px; }
button.primary { width: 100%; padding: 10px; border-color: #465b81; background: #465b81; color: #fff; font-weight: 700; }
button.primary:hover { background: #344767; }
.settings { margin-top: 30px; padding-top: 23px; border-top: 1px solid #dde2e8; }
.settings label { display: grid; grid-template-columns: 82px 1fr; align-items: center; gap: 8px; min-height: 39px; color: #526071; font-size: 12px; }
.settings input[type="range"] { width: 100%; accent-color: #465b81; }
.settings select { width: 100%; height: 29px; border: 1px solid #cfd6de; background: #fff; color: #334050; }
#status { margin-top: auto; padding-top: 18px; color: #7b8794; font-size: 11px; }
.paper-settings { margin-top: 20px; }
.toggle-label input { justify-self: start; }
.style-actions { display: flex; gap: 6px; margin-top: 5px; }
.style-actions button { flex: 1; }
#style-preview { display: block; width: 100%; height: 44px; margin-top: 8px; border: 1px solid #d8dde4; background: #fff; }
#style-preview svg { width: 100%; height: 100%; }
#favorite-styles { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 7px; }
#favorite-styles button { padding: 4px 7px; font-size: 11px; }
.workspace { min-width: 0; display: flex; flex-direction: column; }
.toolbar { display: flex; align-items: center; justify-content: space-between; min-height: 72px; padding: 0 28px; background: #fff; border-bottom: 1px solid #d8dde4; }
.toolbar strong, .toolbar span { display: block; }
.toolbar strong { font-size: 15px; }
.toolbar span { margin-top: 3px; color: #7b8794; font-size: 11px; }
.toolbar-actions { display: flex; gap: 8px; align-items: center; }
.toolbar-actions select { height: 34px; max-width: 105px; border: 1px solid #cfd6de; background: #fff; color: #334050; }
#preview { flex: 1; overflow: auto; padding: 30px; text-align: center; }
#pages { width: min(100%, 794px); margin: 0 auto; }
.page { display: block; width: 100%; height: auto; margin: 0 auto 26px; background: #fff; box-shadow: 0 2px 12px #b7bec8; }
#loading-indicator { position: fixed; z-index: 2; inset: 0; display: grid; place-items: center; background: #edf0f3; color: #526071; }
#loading-indicator[hidden] { display: none; }
.word-popover { position: fixed; z-index: 4; display: flex; align-items: center; flex-wrap: wrap; gap: 7px; max-width: min(330px, calc(100vw - 16px)); padding: 8px 9px 7px 11px; border: 1px solid #cfd6de; border-radius: 7px; background: #fff; box-shadow: 0 4px 12px rgb(39 52 68 / 18%); color: #526071; font-size: 12px; }
.word-popover[hidden] { display: none; }
.word-popover span { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.word-popover button { padding: 6px 9px; border-color: #465b81; background: #465b81; color: #fff; font-size: 12px; font-weight: 700; }
.word-popover button:hover { border-color: #344767; background: #344767; }
.word-popover button:disabled { cursor: wait; opacity: .65; }
.word-popover-actions { display: flex; gap: 4px; width: 100%; }
.word-popover-actions button { min-width: 28px; padding: 4px 7px; border-color: #cfd6de; background: #fff; color: #334050; font-size: 14px; line-height: 1; }
.word-popover-actions button:hover { border-color: #465b81; background: #f0f3f7; color: #273444; }
.word-popover-actions button:last-child { margin-left: auto; font-size: 11px; }
.word-popover small { width: 100%; color: #7b8794; font-size: 10px; }
.word-target { cursor: pointer; fill: transparent; pointer-events: all; }
.word-target:focus { outline: none; stroke: #465b81; stroke-width: 2; stroke-dasharray: 4 3; }
.page .guides { pointer-events: none; }
.guide { stroke: #9cb6df; stroke-width: 1; opacity: .55; }
.guide.grid { stroke: #d2dce8; opacity: .75; }
dialog { width: min(620px, calc(100vw - 32px)); border: 1px solid #cfd6de; border-radius: 10px; padding: 24px; color: #273444; box-shadow: 0 8px 24px rgb(39 52 68 / 25%); }
dialog::backdrop { background: rgb(39 52 68 / 38%); }
dialog h2 { margin: 0; font-size: 18px; }
dialog p { color: #526071; font-size: 13px; }
.dialog-close { float: right; padding: 2px 8px; font-size: 20px; }
#variant-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.variant-option { min-height: 92px; padding: 6px; }
.variant-option svg { display: block; width: 100%; height: 64px; }

@media (prefers-reduced-motion: reduce) {
  .word-popover { transition: none; }
}

@media (max-width: 900px) {
  body { min-width: 0; }
  .app-shell { grid-template-columns: 280px 1fr; }
  .sidebar { padding: 20px; }
  .toolbar { padding: 0 18px; }
  #preview { padding: 18px; }
}

@media (max-width: 680px) {
  body { min-width: 0; }
  .app-shell { display: block; height: auto; }
  .sidebar { padding: 18px; border-right: 0; border-bottom: 1px solid #d8dde4; }
  .brand { margin-bottom: 20px; }
  #editor { height: 150px; }
  .settings { margin-top: 20px; padding-top: 18px; }
  .settings label { grid-template-columns: 106px 1fr; }
  .workspace { min-height: 60vh; }
  .toolbar { min-height: auto; align-items: flex-start; gap: 12px; padding: 14px 18px; }
  .toolbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  #preview { padding: 12px; }
  #variant-options { grid-template-columns: 1fr; }
}

@media print {
  @page { size: A4; margin: 0; }
  body { min-width: 0; background: #fff; }
  .app-shell { display: block; height: auto; }
  .sidebar, .toolbar { display: none; }
  #preview { overflow: visible; padding: 0; }
  #pages { width: 210mm; }
  .page { width: 210mm; height: 297mm; margin: 0; box-shadow: none; break-after: page; }
  .page:last-child { break-after: auto; }
  .page .guides[data-print="false"] { display: none; }
}
