:root {
  /* UI概要に基づく初期レイアウト（% は画面横方向比率） */
  --headerH: 5vh;
  --footerH: 5vh;
  --bodyH: calc(100vh - var(--headerH) - var(--footerH));
  --editorPct: 45; /* 初期 45% */
  --viewerPct: 55; /* 初期 55% */

  /* White theme */
  --border: 1px solid rgba(17, 24, 39, 0.12);
  --bg: #f6f7f9;
  --bg2: #ffffff;
  --panel: #ffffff;
  --text: #111827;
  --muted: rgba(17, 24, 39, 0.62);
  --shadow: 0 8px 20px rgba(17, 24, 39, 0.06);
  --accent: #2563eb;
  --accent2: rgba(37, 99, 235, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica,
    Arial, "Apple Color Emoji", "Segoe UI Emoji";
  /* App全体はスクロール禁止（各パネル内で完結させる） */
  overflow: hidden;
}

.app {
  height: 100vh;
  display: grid;
  grid-template-rows: var(--headerH) var(--bodyH) var(--footerH);
  overflow: hidden;
}

.app__header,
.app__footer {
  background: var(--bg2);
  border-bottom: var(--border);
}

.app__footer {
  border-top: var(--border);
  border-bottom: none;
}

.app__body {
  display: grid;
  height: var(--bodyH);
  grid-template-columns:
    minmax(0, calc(var(--editorPct) * 1%))
    minmax(0, calc(var(--viewerPct) * 1%));
}

.panel {
  min-width: 0;
  background: var(--panel);
  border-right: var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel--viewer {
  border-right: none;
}

.panel__title {
  padding: 8px 10px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: var(--border);
  user-select: none;
}


/* Header */
.header {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
}

.header__left,
.header__right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.divider {
  width: 1px;
  align-self: stretch;
  background: rgba(17, 24, 39, 0.14);
  margin: 0 4px;
}

.btn {
  appearance: none;
  border: 1px solid rgba(17, 24, 39, 0.14);
  background: #ffffff;
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  box-shadow: 0 1px 0 rgba(17, 24, 39, 0.02);
}

.btn:hover {
  background: rgba(17, 24, 39, 0.03);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent2);
  outline-offset: 2px;
}

.btn--ghost {
  background: transparent;
}


/* Editor (CodeMirror 6) */
.editorWrap {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* Editor layout: editor + minimap (minimap to the right of the text editor) */
.editorShell{
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

.editorShell .editorWrap{
  flex: 1;
  min-width: 0;
}

.editorMinimap{
  position: relative;
  flex: 0 0 auto;
  width: fit-content;
  height: 100%;
  background: #ffffff;
  border-left: var(--border);
  overflow: hidden;
  display: flex;
  align-items: stretch;
}

/* The minimap host should not force-expand; it should keep its intrinsic width */

/* Koma language: splitter token colors (&& == || ##) */
.editorWrap .cm-koma-splitter-andand{ color: #b91c1c; font-weight: 600; }   /* red-700 */
.editorWrap .cm-koma-splitter-eqeq{ color: #047857; font-weight: 600; }     /* emerald-700 */
.editorWrap .cm-koma-splitter-pipepipe{ color: #1d4ed8; font-weight: 600; } /* blue-700 */
.editorWrap .cm-koma-splitter-hashhash{ color: #0f766e; font-weight: 600; } /* teal-700 */

/* Koma language: line text colors (via mark decorations; no background) */
.editorWrap .cm-koma-line-splitter-andand{ color: #b91c1c; }
.editorWrap .cm-koma-line-splitter-eqeq{ color: #047857; }
.editorWrap .cm-koma-line-splitter-pipepipe{ color: #1d4ed8; }
.editorWrap .cm-koma-line-splitter-hashhash{ color: #0f766e; }

.editorWrap .cm-koma-line-prop-init{ color: #6d28d9; }   /* violet-700 */
.editorWrap .cm-koma-line-prop-page{ color: #be123c; }   /* rose-700 */
.editorWrap .cm-koma-line-prop-row{ color: #15803d; }    /* green-700 */
.editorWrap .cm-koma-line-prop-column{ color: #4338ca; } /* indigo-700 */
.editorWrap .cm-koma-line-prop-text{ color: #0e7490; }   /* cyan-700 */
.editorWrap .cm-koma-line-prop-bubble{ color: #7e22ce; } /* purple-700 */


/* Koma language: line text colors (via mark decorations; no background) */


/* Page label line (virtual line above &&; does not count as a document line) */
.editorWrap .cm-koma-page-label-line{
  font-size: 12px;
  line-height: 1.2;
  opacity: 0.75;
  padding: 2px 6px;
  color: rgba(17, 24, 39, 0.72);
  user-select: none;
}


.editorWrap .cm-line.cm-koma-line-prop-init{ color: rgb(255,211,255); }
.editorWrap .cm-line.cm-koma-line-prop-page{ color: rgb(255,205,205); }
.editorWrap .cm-line.cm-koma-line-prop-row{ color: rgb(190,240,190); }
.editorWrap .cm-line.cm-koma-line-prop-column{ color: rgb(210,210,255); }
.editorWrap .cm-line.cm-koma-line-prop-text{ color: rgb(214,255,255); }
.editorWrap .cm-line.cm-koma-line-prop-bubble{ color: rgb(228,200,255); }

/* Allow selecting highlighted tokens/lines by drag (do not make decorations atomic) */
/* NOTE: editor line background colors / page labels were removed (user request). */

/* Lint: ensure diagnostics are visible (wavy underline + gutter markers) */
.editorWrap .cm-lintRange{
  text-decoration: underline wavy rgba(220, 38, 38, 0.9);
  text-underline-offset: 3px;
}

.editorWrap .cm-lint-marker{
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: block;
  margin: 4px 0 0 4px;
}

.editorWrap .cm-lint-marker-error{ background: rgba(220, 38, 38, 0.9); }
.editorWrap .cm-lint-marker-warning{ background: rgba(245, 158, 11, 0.95); }

.minimap{
  flex: 0 0 auto;
  width: fit-content;
  height: 100%;
  overflow: hidden;
}

/* Mount container */
.editor {
  flex: 1;
  width: 100%;
  min-height: 0;
}

/* CodeMirror layout */
.editorWrap .cm-editor {
  height: 100%;
  flex: 1;
  background: transparent;
  color: var(--text);
}

.editorWrap .cm-scroller {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 14px;
  line-height: 1.5;
  overflow: auto;

  /* Hide scrollbars (scroll is still allowed) */
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge legacy */
}
.editorWrap .cm-scroller::-webkit-scrollbar {
  width: 0;
  height: 0;
}


.editorWrap .cm-content {
  padding: 12px;
  color: var(--text);
  caret-color: var(--text);
}

.editorWrap .cm-gutters {
  border-right: var(--border);
  background: rgba(17, 24, 39, 0.02);
  color: rgba(17, 24, 39, 0.45);
}

.editorWrap .cm-lineNumbers .cm-gutterElement {
  padding: 0 8px 0 8px;
}

.editorWrap .cm-activeLineGutter {
  background: rgba(17, 24, 39, 0.04);
}

.editorWrap .cm-focused {
  outline: none;
}

.minimap{
  flex: 1;
  position: relative;
  padding: 0;
  overflow: hidden;
}

/* CodeMirror minimap host */
.cm-minimap-host{
  height: 100%;
  display: flex;
  justify-content: flex-start;
  align-items: stretch;
}

/* Minimap (inside viewer right sidebar) */

/* Container created by minimap extension (we create this in JS) */
.km-minimap-wrap{
  position: relative;
  width: fit-content;
  height: 100%;
  overflow: hidden;
  background: #ffffff;
}

/* Minimap background (uniform white) */
.km-minimap-bg{ display: none; }

/* Make minimap content sit above the stripes */
.km-minimap-wrap > canvas,
.km-minimap-wrap > .cm-minimap,
.km-minimap-wrap > .minimap,
.km-minimap-wrap > :not(.km-minimap-bg):not(.km-minimap-viewport){
  position: relative;
  z-index: 1;
}

/* Minimap viewport highlight (VSCode-like) */
.km-minimap-viewport{
  position: absolute;
  left: 0;
  right: 0;
  border: 1px solid rgba(17, 24, 39, 0.14);
  background: rgba(17, 24, 39, 0.04);
  border-radius: 4px;
  z-index: 3;
  pointer-events: none;
  box-shadow: none;
}

/* Minimap content: keep intrinsic width, fill height */
.km-minimap-wrap canvas,
.km-minimap-wrap .cm-minimap{
  width: auto;
  height: 100%;
  display: block;
}


.viewer {
  flex: 1;
  padding: 0;
  overflow: hidden;
  min-height: 0;
  background: rgba(17, 24, 39, 0.04);
}

.viewer__pages {
  display: grid;
  grid-template-columns: repeat(1, minmax(0, 1fr));
  gap: 12px;
  align-content: start;
  height: 100%;
  min-height: 0;
}

.page {
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  height: 100%;
  min-height: 0;
}

.page__title {
  display: none;

  font-size: 12px;
  color: var(--muted);
}

.page__canvas {
  border: none;
  border-radius: 0;
  padding: 0;
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.page__image {
  /* ビューワサイズにフィット（アスペクト比維持・縮小のみ） */
  max-width: 100%;
  max-height: 100%;
  /* Keep intrinsic bitmap size when possible to avoid unnecessary resampling.
     Shrink only when the viewer is smaller than the rendered bitmap. */
  width: auto;
  height: auto;
  display: block;
  border-radius: 0;
  background: transparent;
}


.koma {
  border: 1px dashed rgba(17, 24, 39, 0.25);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(17, 24, 39, 0.55);
  min-height: 36px;
}

.page__script {
  display: none;

  border-top: 1px dashed rgba(17, 24, 39, 0.18);
  padding-top: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 12px;
  color: rgba(17, 24, 39, 0.75);
  white-space: pre-wrap;
  word-break: break-word;
  /* スクロール禁止のため、長文は見切れる（初期実装の範囲） */
  max-height: 28%;
  overflow: hidden;
}

.app__footer {
  display: grid;
  grid-template-columns:
    minmax(0, 1fr)
    auto
    minmax(0, 1fr);
}

.footer {
  display: flex;
  align-items: center;
  min-width: 0;
}

.footer--handle {
  justify-content: center;
  border-left: var(--border);
  border-right: var(--border);
}

.handle {
  width: calc(100% - 12px);
  height: calc(var(--footerH) - 12px);
  margin: 6px;
  border-radius: 8px;
  border: 1px solid rgba(17, 24, 39, 0.18);
  background: rgba(17, 24, 39, 0.04);
  color: var(--text);
  font-size: 14px;
  cursor: ew-resize;
  touch-action: none; /* iPad などでスワイプをドラッグとして扱う */
  user-select: none;
}

.handle:active {
  background: rgba(17, 24, 39, 0.06);
}

/* Footer */
.status {
  padding: 8px 10px;
  font-size: 12px;
  color: var(--muted);
  user-select: none;
}

.footerRight {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  gap: 10px;
}

/* Modal */
.modal {
  border: none;
  padding: 0;
  background: transparent;
}

.modal::backdrop {
  background: rgba(17, 24, 39, 0.35);
}

.modal__inner {
  width: min(1100px, calc(100vw - 40px));
  height: min(720px, calc(100vh - 40px));
  margin: auto;
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 18px 50px rgba(17, 24, 39, 0.22);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid rgba(17, 24, 39, 0.12);
}

.modal__title {
  font-size: 13px;
  color: var(--muted);
}

.modal__body {
  min-height: 0;
}

/* Settings modal */
.settingsModal {
  width: min(980px, calc(100vw - 40px));
  height: min(680px, calc(100vh - 40px));
}

.settingsModal__header {
  gap: 10px;
}

.settingsModal__title {
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
}

.settingsModal__mode {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px;
  border-radius: 12px;
  border: 1px solid rgba(17, 24, 39, 0.14);
  background: rgba(17, 24, 39, 0.04);
}

.settingsModal__mode .seg {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.settingsModal__mode input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.settingsModal__mode .seg:has(input:checked) {
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 6px 16px rgba(17, 24, 39, 0.10);
}

.settingsLayout {
  height: 100%;
  display: grid;
  grid-template-columns: 180px 1fr;
  min-height: 0;
}

.settingsNav {
  border-right: 1px solid rgba(17, 24, 39, 0.12);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: rgba(17, 24, 39, 0.02);
}

.settingsNav__item {
  text-align: left;
  padding: 10px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}

.settingsNav__item:hover {
  background: rgba(17, 24, 39, 0.04);
}

.settingsNav__item.is-active {
  background: #ffffff;
  border-color: rgba(17, 24, 39, 0.14);
  box-shadow: 0 8px 22px rgba(17, 24, 39, 0.12);
}

.settingsMain {
  min-width: 0;
  min-height: 0;
  padding: 14px;
}

.settingsPane {
  height: 100%;
  min-height: 0;
}

.settingsPlaceholder {
  height: 100%;
  border: 1px dashed rgba(17, 24, 39, 0.20);
  border-radius: 14px;
  background: rgba(17, 24, 39, 0.02);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
}

.settingsPlaceholder__title {
  font-size: 13px;
  color: var(--text);
  font-weight: 600;
}

.settingsPlaceholder__desc {
  font-size: 12px;
  color: var(--muted);
}

/* Settings: section headers */
.settingsSectionTitle {
  font-size: 14px;
  font-weight: 700;
  margin: 4px 0 6px;
}

.settingsSectionDesc {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 10px;
}

/* Settings: font table */
.settingsFontTableWrap {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;
}

.settingsFontTable {
  width: 100%;
  border-collapse: collapse;
}

.settingsFontTable th,
.settingsFontTable td {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  font-size: 12px;
  vertical-align: middle;
}

.settingsFontTable th {
  text-align: left;
  color: var(--muted);
  background: #fafafa;
  font-weight: 700;
}

.settingsFontTable tbody tr:last-child td {
  border-bottom: 1px solid var(--border);
}

.settingsFontName {
  font-weight: 700;
}

.settingsFontSizeInput {
  width: 72px;
  padding: 4px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

.settingsFontSample {
  font-size: 14px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settingsFontDelete {
  width: 28px;
  height: 28px;
  line-height: 26px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
}

.settingsFontDelete[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}

.viewer--modal {
  height: 100%;
}

@media (max-width: 900px) {
  /* いったんUI概要の比率は維持しつつ、余白だけ縮める */
  .panel__title,
  .status {
    padding: 6px 8px;
  }
  .editorWrap .cm-content {
    padding: 10px;
  }
}


/* Viewer shell: viewer + minimap on the right */
.viewerShell{
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

.viewerShell .viewer{
  flex: 1;
  min-width: 0;
  min-height: 0;
}


/* Right-edge resizer (drag to resize editor/viewer ratio) */
.minimapResizer{
  position: absolute;
  top: 0;
  right: 0;
  width: 10px;
  height: 100%;
  cursor: ew-resize;
  background: transparent;
  z-index: 10;
}

/* Split footer: two independent footers aligned with body columns */
.app__footerSplit{
  display: grid;
  grid-template-columns:
    minmax(0, calc(var(--editorPct) * 1%))
    minmax(0, calc(var(--viewerPct) * 1%));
  height: var(--footerH);
  background: var(--bg2);
  border-top: var(--border);
}

.footerCol{
  display: flex;
  align-items: center;
  height: 100%;
  padding: 6px 10px;
  overflow: hidden;
}

.footerCol--editor{
  border-right: var(--border);
  justify-content: flex-start;
}

.footerCol--viewer{
  justify-content: flex-end;
}
