:root {
  color-scheme: light;
  --ink: #172026;
  --muted: #64727d;
  --line: #d9e0e5;
  --soft: #f5f7f8;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-dark: #0b5e57;
  --warn: #8a5a00;
  --shadow: 0 18px 45px rgba(27, 37, 44, 0.12);
  font-family: "Yu Gothic", "Meiryo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #eef2f4;
  color: var(--ink);
}

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

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

button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

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

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

.app-header {
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 0 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #172026;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(23, 32, 38, 0.18);
}

.app-header h1 {
  margin: 2px 0 0;
  font-size: 22px;
  letter-spacing: 0;
}

.eyebrow,
.panel-label,
.block-kind {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.header-actions button:last-child,
#mobileUnlockButton,
#addBlockButton {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.pc-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(260px, 320px) minmax(420px, 1fr) minmax(360px, 460px);
  gap: 14px;
  padding: 14px;
  height: calc(100vh - 76px);
}

.workflow-rail {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.workflow-step {
  min-height: 58px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-areas:
    "num label"
    "num value";
  align-items: center;
  column-gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 9px 10px;
}

.workflow-step span {
  grid-area: num;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: #e8eef2;
  color: #4b5b66;
  font-weight: 800;
}

.workflow-step strong {
  grid-area: label;
  font-size: 12px;
}

.workflow-step em {
  grid-area: value;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.workflow-step.done span {
  background: #0f766e;
  color: #fff;
}

.settings-panel,
.editor-panel,
.preview-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: auto;
  box-shadow: 0 10px 30px rgba(27, 37, 44, 0.08);
}

.settings-panel {
  padding: 16px;
}

.editor-panel {
  padding: 16px;
}

.preview-panel {
  display: flex;
  flex-direction: column;
}

.editor-topline,
.preview-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.editor-topline h2,
.preview-toolbar h2,
.mobile-card h2 {
  margin: 2px 0 0;
  font-size: 20px;
  letter-spacing: 0;
}

.editor-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.editor-meta span {
  border: 1px solid #dce6ea;
  border-radius: 999px;
  background: #f4f8fa;
  color: #4b5b66;
  padding: 4px 8px;
  font-size: 12px;
}

.summary-card {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0 16px;
}

.summary-card div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
  padding: 10px;
}

.summary-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.summary-card strong {
  display: block;
  min-width: 0;
  margin-top: 4px;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.draft-status,
#pageModeLabel {
  flex: 0 0 auto;
  border-radius: 999px;
  border: 1px solid #bddbd7;
  background: #eefaf8;
  color: var(--accent-dark);
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
}

.draft-status.is-dirty {
  border-color: #f1d28b;
  background: #fff8e6;
  color: var(--warn);
}

.field {
  display: grid;
  gap: 6px;
  margin: 12px 0;
}

.field span,
.check-group legend,
.template-section h3 {
  color: #37444d;
  font-size: 12px;
  font-weight: 700;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.compact-field {
  margin: 8px 0;
}

.inline-field {
  width: 220px;
  margin: 0;
}

.check-group {
  display: grid;
  gap: 8px;
  margin: 16px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.check-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.check-group input {
  width: auto;
}

.template-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.template-section h3 {
  margin: 0 0 8px;
}

.prototype-warning,
.route-hint,
.muted,
.tool-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.prototype-warning {
  border: 1px solid #f1d28b;
  border-radius: 8px;
  background: #fff8e6;
  color: #6f4900;
  padding: 10px;
}

.print-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.print-tabs button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.editor-tools {
  display: flex;
  align-items: end;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  margin-bottom: 12px;
}

.quick-add {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quick-add button {
  background: #eef7f6;
  border-color: #bddbd7;
  color: var(--accent-dark);
  font-weight: 700;
}

.block-list {
  display: grid;
  gap: 12px;
}

.block-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.block-editor:focus-within {
  border-color: #5bb9b0;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

.block-editor-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  background: #f9fbfb;
  border-bottom: 1px solid var(--line);
}

.block-title-input {
  margin-top: 5px;
  font-weight: 700;
}

.block-actions {
  display: flex;
  gap: 6px;
}

.block-body {
  padding: 12px;
}

.math-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.math-buttons button {
  min-width: 48px;
  padding: 6px 8px;
}

.figure-preview svg,
.figure-block svg {
  width: 100%;
  height: auto;
  border: 1px solid #cfd8df;
  background: #fff;
}

.preview-toolbar {
  padding: 16px 16px 0;
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-actions button {
  background: #172026;
  border-color: #172026;
  color: #fff;
}

.a4-stage {
  flex: 1;
  overflow: auto;
  display: grid;
  place-items: start center;
  padding: 12px 16px 24px;
  background: #dfe6ea;
}

.a4-page {
  width: 210mm;
  min-height: 297mm;
  transform: scale(0.52);
  transform-origin: top center;
  margin-bottom: -140mm;
  background: #fff;
  color: #111827;
  box-shadow: var(--shadow);
  padding: 13mm;
  display: flex;
  flex-direction: column;
}

.print-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 2px solid #111827;
  padding-bottom: 6mm;
  margin-bottom: 7mm;
}

.print-header p {
  margin: 0 0 3mm;
  color: #4b5563;
  font-size: 10pt;
}

.print-header h2 {
  margin: 0;
  font-size: 18pt;
  letter-spacing: 0;
}

.print-unit {
  max-width: 70mm;
  text-align: right;
  font-size: 10pt;
  line-height: 1.5;
}

.print-blocks {
  display: grid;
  gap: 5mm;
  align-content: start;
}

.preview-block {
  break-inside: avoid;
}

.preview-block h3 {
  margin: 0 0 2mm;
  font-size: 13pt;
  letter-spacing: 0;
}

.preview-block p {
  white-space: pre-wrap;
  margin: 0;
  font-size: 11pt;
  line-height: 1.75;
}

.heading-block {
  border-left: 5px solid #0f766e;
  padding-left: 4mm;
}

.latex-display {
  border: 1px solid #cbd5e1;
  border-radius: 3mm;
  background: #f8fafc;
  padding: 4mm;
  font-family: "Times New Roman", serif;
  font-size: 14pt;
}

.handwriting-preview {
  position: relative;
  border: 1px solid #94a3b8;
  border-radius: 2mm;
  overflow: hidden;
  background-color: #fff;
}

.handwriting-preview span {
  display: inline-block;
  margin: 2mm;
  padding: 1mm 2mm;
  background: #fff;
  color: #475569;
  font-size: 9pt;
}

.handwriting-preview.horizontal {
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 22px, #cbd5e1 23px);
}

.handwriting-preview.dotted {
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent 22px, #cbd5e1 23px, transparent 24px);
}

.handwriting-preview.grid {
  background-image: linear-gradient(#e2e8f0 1px, transparent 1px), linear-gradient(90deg, #e2e8f0 1px, transparent 1px);
  background-size: 18px 18px;
}

.handwriting-preview.dot {
  background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
  background-size: 12px 12px;
}

.score-block,
.meta-block {
  border: 1px solid #111827;
  padding: 3mm;
  font-size: 12pt;
  white-space: pre-wrap;
}

.page-break-line {
  border-top: 1px dashed #94a3b8;
  color: #64748b;
  text-align: center;
  font-size: 9pt;
  padding-top: 2mm;
}

.print-footer {
  margin-top: auto;
  text-align: center;
  color: #64748b;
  font-size: 9pt;
}

.mobile-only {
  display: none;
}

.mobile-viewer {
  min-height: calc(100vh - 76px);
  padding: 16px;
}

.mobile-card {
  max-width: 620px;
  margin: 0 auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.mobile-note {
  border: 1px solid #f1d28b;
  background: #fff8e6;
  color: #6f4900;
  border-radius: 8px;
  padding: 10px;
  line-height: 1.7;
}

.saved-panel {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.mini-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.mini-heading h3 {
  margin: 0;
  font-size: 13px;
}

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

.saved-item {
  display: grid;
  gap: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  padding: 9px;
  margin-top: 8px;
}

.saved-item strong {
  font-size: 13px;
}

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

.mobile-print-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.mobile-print-list article {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.mobile-print-list h3 {
  margin: 0 0 6px;
  font-size: 16px;
}

.mobile-print-list p,
.mobile-print-list span {
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 880px) {
  .app-header {
    height: auto;
    min-height: 64px;
    align-items: flex-start;
    padding: 12px 14px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  .app-header h1 {
    font-size: 18px;
  }

  .header-actions {
    display: none;
  }

  .desktop-only {
    display: none;
  }

  .mobile-only {
    display: block;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-header,
  .settings-panel,
  .editor-panel,
  .workflow-rail,
  .preview-toolbar {
    display: none !important;
  }

  .pc-shell {
    display: block;
    height: auto;
    padding: 0;
  }

  .preview-panel {
    border: 0;
    overflow: visible;
  }

  .a4-stage {
    padding: 0;
    overflow: visible;
    background: #fff;
    display: block;
  }

  .a4-page {
    width: 210mm;
    min-height: 297mm;
    transform: none;
    margin: 0;
    box-shadow: none;
    padding: 13mm;
  }

  @page {
    size: A4 portrait;
    margin: 0;
  }
}
