:root {
  --bg: #f6f7fb;
  --card: #ffffff;
  --card-alt: #f8fafc;
  --line: #d7dbe7;
  --line-strong: #b6c0d4;
  --text: #1f2937;
  --muted: #5b6475;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --accent-ink: #1d4ed8;
  --error: #b42318;
  --warn: #b54708;
  --ok: #027a48;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  --editor-font: "SFMono-Regular", "Cascadia Code", "Consolas", "Menlo", monospace;
  --body-font: "Inter", "Noto Sans JP", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  height: 100%;
  min-height: 100%;
  background: linear-gradient(180deg, #f6f7fb 0%, #eef3ff 100%);
  color: var(--text);
  font-family: var(--body-font);
}

body {
  min-height: 100vh;
  overflow: hidden;
}


button, textarea, input {
  font: inherit;
}

button {
  cursor: pointer;
}


*::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

*::-webkit-scrollbar-thumb {
  background: rgba(132, 146, 175, 0.62);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

*::-webkit-scrollbar-track {
  background: rgba(215, 219, 231, 0.32);
  border-radius: 999px;
}

.app-shell {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 5px;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.05);
  backdrop-filter: blur(10px);
}

.protocol-warning {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 10px;
  border: 1px solid rgba(181, 71, 8, 0.28);
  border-radius: 16px;
  background: rgba(255, 251, 235, 0.96);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.protocol-warning-main,
.protocol-warning-meta {
  display: grid;
  gap: 5px;
}

.protocol-warning p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.protocol-warning[hidden] {
  display: none !important;
}

.protocol-warning-label {
  font-size: 0.84rem;
  color: var(--muted);
}

.protocol-warning code,
.protocol-warning a {
  display: inline-block;
  word-break: break-all;
}

.protocol-warning code {
  padding: 5px 8px;
  border-radius: 10px;
  border: 1px solid rgba(181, 71, 8, 0.2);
  background: #fff7ed;
}

.protocol-warning a {
  color: var(--text);
  text-decoration: none;
}

.brand-group, .menu-buttons, .assist-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.brand-group {
  margin-left: auto;
  justify-content: flex-end;
}

.brand {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.version-pill, .filename-chip, .dirty-indicator {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font-size: 0.74rem;
  font-weight: 600;
}

.version-button {
  border: 0;
  cursor: pointer;
}

.dirty-indicator {
  background: #fff1f3;
  color: #be123c;
}

.menu-buttons button,
.menu-buttons .menu-link,
.assist-toolbar button,
.brand-undo-button,
.sync-button,
.about-ok-btn,
.about-close {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: #ffffff;
  color: var(--text);
  padding: 5px 9px;
  border-radius: 9px;
  box-shadow: none;
  transition: border-color 120ms ease, background-color 120ms ease, color 120ms ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.menu-buttons button:hover,
.menu-buttons .menu-link:hover,
.assist-toolbar button:hover,
.brand-undo-button:hover,
.sync-button:hover,
.about-ok-btn:hover,
.about-close:hover {
  border-color: var(--accent);
  background: #f7fbff;
  color: var(--text);
}


.assist-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding: 4px 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.04);
}

.assist-toolbar[hidden] {
  display: none !important;
}

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 28px minmax(0, 1fr);
  gap: 4px;
  align-items: stretch;
}

.pane {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) clamp(118px, 21vh, 154px);
  height: 100%;
  border: 1px solid rgba(132, 146, 175, 0.2);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px 5px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96) 0%, rgba(248, 250, 252, 0.92) 100%);
}

.pane-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.pane-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.pane-header h2,
.subpanel-header h3 {
  margin: 0;
  font-size: 0.94rem;
}

.pane-subtitle,
.subpanel-header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.pane-subtitle[hidden] {
  display: none !important;
}

.editor-stack {
  min-height: 0;
  display: flex;
  background: linear-gradient(180deg, rgba(248, 250, 252, 0.9), rgba(255, 255, 255, 0.95));
}

#body-editor {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  margin: 0;
  padding: 11px 13px;
  border: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  caret-color: #111827;
  font-family: var(--editor-font);
  font-size: 14px;
  line-height: 1.56;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
  tab-size: 2;
}

#body-editor:focus,
.secondary-editor:focus {
  outline: none;
}

#body-editor::selection {
  background: rgba(37, 99, 235, 0.18);
}

.secondary-editor {
  width: 100%;
  height: 100%;
  min-height: 0;
  padding: 7px 10px;
  border: 0;
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, #fbfdff 0%, #f8fafc 100%);
  resize: none;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
  font-family: var(--editor-font);
  font-size: 13px;
  line-height: 1.6;
  color: var(--text);
}

.preview-surface {
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
  padding: 5px 8px 6px;
  background: linear-gradient(180deg, rgba(252, 252, 255, 1) 0%, rgba(248, 250, 252, 0.95) 100%);
}

.preview-empty {
  color: var(--muted);
  padding: 24px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  background: var(--card-alt);
}

.preview-block {
  position: relative;
  margin: 0 0 1px;
  padding: 3px 7px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: rgba(255, 255, 255, 0.65);
}

.preview-block:hover {
  border-color: rgba(37, 99, 235, 0.28);
  background: #ffffff;
}

.preview-block.active {
  border-color: rgba(37, 99, 235, 0.7);
  background: #eff6ff;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.18);
}

.preview-block.unsupported {
  border-color: rgba(181, 71, 8, 0.35);
  background: #fff7ed;
}

.preview-block.heading {
  padding-top: 4px;
  padding-bottom: 4px;
  margin-bottom: 3px;
}

.preview-block pre {
  margin: 0;
  white-space: pre-wrap;
  font-family: var(--editor-font);
}

.preview-block h1,
.preview-block h2,
.preview-block h3,
.preview-block h4,
.preview-block p {
  margin-top: 0;
}

.preview-block.heading-level-1 h1 { font-size: 1.12rem; line-height: 1.24; margin-bottom: 0.12rem; }
.preview-block.heading-level-2 h2 { font-size: 1.0rem; line-height: 1.26; margin-bottom: 0.1rem; }
.preview-block.heading-level-3 h3 { font-size: 0.95rem; line-height: 1.3; margin-bottom: 0.08rem; }
.preview-block.heading-level-4 h4 { font-size: 0.91rem; line-height: 1.32; margin-bottom: 0.08rem; }

.heading-number {
  color: var(--text);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.preview-block p {
  line-height: 1.56;
  margin-bottom: 0;
}

.preview-block ul,
.preview-block ol {
  margin: 0.02rem 0 0.03rem 1.05rem;
  padding-left: 0.82rem;
}

.preview-block li {
  margin: 0.03rem 0;
}

.preview-block li > .preview-block {
  margin-top: 0.08rem;
}

.panel-bottom {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border-top: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(252, 252, 255, 1) 0%, rgba(248, 250, 252, 0.96) 100%);
}

.subpanel-header {
  padding: 5px 9px 0;
}

.macros-panel .subpanel-header {
  display: flex;
  align-items: baseline;
  gap: 5px;
  flex-wrap: nowrap;
}

#macro-panel-subtitle {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subpanel-header p[hidden] {
  display: none !important;
}

.preview-pane-header {
  align-items: center;
}

.pane,
.sync-rail {
  height: 100%;
}

.preview-status {
  margin-left: auto;
  max-width: min(68%, 560px);
  font-size: 0.74rem;
  color: var(--muted);
  line-height: 1.35;
  text-align: right;
  text-wrap: pretty;
  white-space: normal;
}

.sync-rail {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 5px;
}

.sync-button {
  width: 26px;
  height: 26px;
  min-height: 26px;
  padding: 0;
  border-radius: 8px;
  font-size: 0.96rem;
  font-weight: 600;
}

.sync-button.secondary {
  background: #ffffff;
}

.diagnostics-list {
  min-height: 0;
  display: grid;
  gap: 6px;
  padding: 7px 9px 9px;
  overflow: auto;
  scrollbar-gutter: stable both-edges;
  overscroll-behavior: contain;
}

.diagnostic-card {
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #ffffff;
}

.diagnostic-card.error {
  border-color: rgba(180, 35, 24, 0.25);
  background: #fff5f4;
}

.diagnostic-card.warning {
  border-color: rgba(181, 71, 8, 0.25);
  background: #fffaeb;
}

.diagnostic-card.info {
  border-color: rgba(2, 122, 72, 0.25);
  background: #ecfdf3;
}

.diagnostic-card strong {
  display: block;
  margin-bottom: 4px;
}



.about-dialog {
  border: 0;
  padding: 0;
  border-radius: 20px;
  box-shadow: 0 28px 64px rgba(15, 23, 42, 0.24);
  max-width: min(480px, calc(100vw - 24px));
  width: 100%;
}

.about-dialog::backdrop {
  background: rgba(15, 23, 42, 0.24);
  backdrop-filter: blur(4px);
}

.about-card {
  position: relative;
  padding: 18px 20px 16px;
  display: grid;
  gap: 10px;
  background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.about-app-name {
  font-size: 0.92rem;
  color: var(--muted);
  text-align: center;
}

.about-mark {
  font-size: 2rem;
  font-weight: 700;
  text-align: center;
  color: var(--text);
}

.about-tagline {
  text-align: center;
  color: var(--muted);
  margin-top: -4px;
}

.about-meta-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 10px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #ffffff;
}

.about-label {
  color: var(--muted);
  font-size: 0.82rem;
  align-self: center;
}

.about-value {
  min-width: 0;
  word-break: break-word;
}

.about-value a {
  color: var(--accent-ink);
  text-decoration: none;
}

.about-actions {
  display: flex;
  justify-content: center;
  padding-top: 4px;
}

.about-ok-btn {
  min-width: 96px;
}

.about-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 999px;
}

@media (max-width: 1120px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100vh;
    overflow: visible;
  }


  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(640px, auto) auto minmax(640px, auto);
    overflow: visible;
  }

  .source-pane,
  .preview-pane {
    min-height: 640px;
  }

  .sync-rail {
    grid-auto-flow: column;
  }

  .pane,
  .sync-rail {
    height: 100%;
  }

  .preview-status {
    max-width: 100%;
    text-align: left;
  }
}


@media print {
  body {
    background: white;
  }

  .topbar,
  .assist-toolbar,
  .sync-rail,
  .source-pane,
  .diagnostics-panel,
  .protocol-warning {
    display: none !important;
  }


  .workspace {
    display: block;
  }

  .preview-pane {
    border: none;
    box-shadow: none;
  }

  .preview-surface {
    padding: 0;
    overflow: visible;
  }

  .preview-block {
    break-inside: avoid;
    border: none;
    background: transparent;
    box-shadow: none;
    padding-left: 0;
    padding-right: 0;
  }
}
