:root {
  --bg: #f6f6f3;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5f6670;
  --border: #d9dad5;
  --accent: #2f5d8a;
  --accent-text: #ffffff;
  --focus: #2f5d8a;
  --code-bg: #f0f0ec;

  --radius: 6px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181b;
    --surface: #1e2125;
    --text: #e3e5e8;
    --muted: #9aa1aa;
    --border: #353a40;
    --accent: #6f9fd0;
    --accent-text: #0f1215;
    --focus: #8ab4e0;
    --code-bg: #2a2e33;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #16181b;
  --surface: #1e2125;
  --text: #e3e5e8;
  --muted: #9aa1aa;
  --border: #353a40;
  --accent: #6f9fd0;
  --accent-text: #0f1215;
  --focus: #8ab4e0;
  --code-bg: #2a2e33;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.7 var(--sans);
}
main, .bar { max-width: 1400px; margin: 0 auto; padding: 0 24px; }

.bar {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 16px;
  padding-top: 20px;
  padding-bottom: 12px;
}
h1 { margin: 0; font-size: 18px; font-weight: 600; letter-spacing: .02em; }
.lead { margin: 0; color: var(--muted); font-size: 13px; grid-column: 1; }
.theme { grid-column: 2; grid-row: 1 / span 2; align-self: center; display: flex; }
.theme button, .tabs button { border-radius: 0; margin-left: -1px; font-size: 12px; padding: 4px 10px; }
.theme button:first-child, .tabs button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.theme button:last-child, .tabs button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.theme button[aria-pressed="true"], .tabs button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.tabs { display: flex; }
.tabs[hidden] { display: none; }
.direction { display: flex; margin: 0 0 14px; }
.direction button { border-radius: 0; margin-left: -1px; padding: 6px 16px; font-weight: 600; }
.direction button:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.direction button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.direction button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.source { color: var(--muted); font-size: 12px; margin: 6px 0 0; min-height: 1.7em; }
.spacer { margin-left: auto; }

button {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 5px 12px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.panes { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.pane { display: flex; flex-direction: column; min-width: 0; }
.pane-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; min-height: 32px; margin-bottom: 6px; }
.pane-head label, .pane-head .label { font-weight: 600; }
#clear { margin-left: auto; }
.status { color: var(--muted); font-size: 12px; min-width: 1em; }

textarea, .preview {
  width: 100%;
  height: calc(100vh - 240px);
  min-height: 320px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
textarea { resize: vertical; font: 13px/1.6 var(--mono); }
.preview { overflow: auto; font: 15px/1.8 var(--sans); overflow-wrap: anywhere; }
.preview[hidden], textarea[hidden] { display: none; }

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

/* プレビュー内の見た目 */
.preview > :first-child { margin-top: 0; }
.preview h1, .preview h2, .preview h3, .preview h4, .preview h5, .preview h6 { line-height: 1.4; margin: 1.4em 0 .5em; }
.preview h1 { font-size: 1.6em; } .preview h2 { font-size: 1.35em; } .preview h3 { font-size: 1.15em; }
.preview h4, .preview h5, .preview h6 { font-size: 1em; }
.preview a { color: var(--accent); }
.preview code { font: .9em var(--mono); background: var(--code-bg); padding: 1px 4px; border-radius: 3px; }
.preview pre { background: var(--code-bg); padding: 10px 12px; border-radius: var(--radius); overflow: auto; }
.preview pre code { background: none; padding: 0; }
.preview blockquote { margin: 1em 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.preview table { border-collapse: collapse; margin: 1em 0; }
.preview th, .preview td { border: 1px solid var(--border); padding: 4px 10px; }
.preview th { background: var(--code-bg); }
.preview .align-left { text-align: left; }
.preview .align-center { text-align: center; }
.preview .align-right { text-align: right; }
.preview hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.preview img { max-width: 100%; }

.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }

@media (max-width: 760px) {
  main, .bar { padding: 0 16px; }
  .bar { grid-template-columns: 1fr; padding-top: 16px; padding-bottom: 12px; }
  .theme { grid-column: 1; grid-row: auto; justify-self: start; }
  .panes { grid-template-columns: 1fr; }
  textarea, .preview { height: 40vh; min-height: 200px; }
}
