:root {
  --bg: #fafaf8;
  --fg: #1a1a1a;
  --muted: #666;
  --accent: #7a2a2a;
  --border: #ddd;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); font-family: -apple-system, "Hiragino Sans", "Yu Gothic", sans-serif; line-height: 1.6; }
header { border-bottom: 1px solid var(--border); padding: 0.75rem 1.25rem; background: #fff; }
nav { display: flex; align-items: center; gap: 1rem; max-width: 960px; margin: 0 auto; }
nav a { color: var(--fg); text-decoration: none; }
nav a.brand { font-weight: 700; color: var(--accent); }
nav .spacer { flex: 1; }
nav button.link { background: none; border: none; color: var(--fg); cursor: pointer; font: inherit; padding: 0; }
main { max-width: 960px; margin: 2rem auto; padding: 0 1.25rem; }
footer { text-align: center; padding: 2rem; color: var(--muted); }
h1 { color: var(--accent); }
form label { display: block; margin-bottom: 0.75rem; }
form input, form select, form textarea { display: block; width: 100%; max-width: 28rem; padding: 0.5rem; font: inherit; border: 1px solid var(--border); border-radius: 4px; }
button, .btn { background: var(--accent); color: #fff; border: 0; padding: 0.5rem 1rem; border-radius: 4px; cursor: pointer; text-decoration: none; display: inline-block; font: inherit; }
button.danger { background: #a33; }
table { border-collapse: collapse; width: 100%; margin: 1rem 0; background: #fff; }
th, td { border: 1px solid var(--border); padding: 0.4rem 0.6rem; text-align: left; vertical-align: top; }
th { background: #f0f0ee; }
section.placeholder { border: 1px dashed var(--border); padding: 1rem; color: var(--muted); margin: 1rem 0; }

/* 四柱 pillar display */
section.chart { margin: 2rem 0; }
table.pillars th, table.pillars td { text-align: center; padding: 0.6rem; }
table.pillars td.stem, table.pillars td.branch { font-size: 1.8rem; font-weight: 700; font-family: "Yu Mincho", "Hiragino Mincho ProN", serif; }
table.pillars td.stem.self { color: var(--accent); text-decoration: underline; text-decoration-style: dotted; }
table.pillars tr.muted td { color: var(--muted); font-size: 0.9rem; font-weight: normal; }
table.gogyou th, table.gogyou td { text-align: center; padding: 0.4rem 1rem; font-size: 1.1rem; }
table.daiun th, table.daiun td { text-align: center; padding: 0.4rem 0.5rem; font-size: 0.95rem; }
table.daiun tr.muted td { color: var(--muted); font-size: 0.85rem; }
dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: 0.3rem 1rem; }
dl.meta dt { font-weight: 600; color: var(--muted); }
.note { color: var(--muted); font-size: 0.9rem; }

/* 紫薇 palace grid - 4x4 with center empty */
section.shibito { margin: 2rem 0; }
.palaces-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  max-width: 720px;
}
.palace {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.5rem;
  min-height: 110px;
  font-size: 0.85rem;
}
.palace.empty { border: none; background: transparent; }
.palace.mei { background: #fff5ee; border-color: var(--accent); }
.palace.body { box-shadow: inset 0 0 0 2px #ffa; }
.palace-header { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.8rem; border-bottom: 1px dotted var(--border); padding-bottom: 0.3rem; margin-bottom: 0.3rem; }
.palace-stem { font-weight: 700; color: var(--accent); }
.palace-stars { display: flex; flex-wrap: wrap; gap: 0.3rem; font-family: "Yu Mincho", serif; font-weight: 600; }
.star sup { color: var(--accent); font-size: 0.7rem; margin-left: 1px; }

/* 七政 + kimon */
section.celestial, section.kimon { margin: 2rem 0; }
table.planets { max-width: 540px; }
table.planets td.num { text-align: right; font-family: "SF Mono", Menlo, monospace; }
.retro { color: #a33; font-weight: 700; font-size: 0.8rem; }
table.palaces-tab tr.mei { background: #fff5ee; font-weight: 700; }
table.palaces-tab .star { display: inline-block; padding: 1px 6px; background: #f4ebdc; border-radius: 3px; margin-right: 0.2rem; font-weight: 600; }

/* 奇門 9宮盤 (3x3 grid) */
.kimon-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; max-width: 600px; margin: 1rem 0; }
.kimon-cell { background: #fff; border: 1px solid var(--border); border-radius: 4px; padding: 0.5rem; min-height: 110px; font-size: 0.85rem; }
.kimon-cell.chihu { background: #fff5ee; border-color: var(--accent); }
.kimon-cell.chishi { box-shadow: inset 0 0 0 2px #ffa; }
.kimon-cell .cell-head { font-weight: 700; color: var(--accent); border-bottom: 1px dotted var(--border); padding-bottom: 0.3rem; margin-bottom: 0.3rem; }
.kimon-cell > div { margin-bottom: 2px; }
.context { background: #fff5ee; border: 1px solid var(--accent); border-radius: 4px; padding: 0.5rem 1rem; margin: 1rem 0; display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; font-size: 0.95rem; }
.context .ctx-key { color: var(--muted); font-size: 0.8rem; margin-right: 0.2rem; }

/* 九星気学 年盤/月盤 (3x3 grid) */
.kyusei-ban { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; max-width: 360px; margin: 0.5rem 0 1rem; }
.kyusei-ban .ban-cell { background: #fff; border: 1px solid var(--border); border-radius: 4px; padding: 0.5rem; text-align: center; }
.kyusei-ban .ban-cell.chuuguu { background: #fff5ee; border-color: var(--accent); }
.kyusei-ban .ban-palace { color: var(--muted); font-size: 0.75rem; }
.kyusei-ban .ban-star { font-weight: 700; color: var(--accent); }

/* 鑑定文 */
section.interpretation { margin: 2rem 0; }
section.interpretation details { margin-bottom: 0.75rem; border: 1px solid var(--border); border-radius: 4px; padding: 0.5rem 1rem; background: #fff; }
section.interpretation summary { cursor: pointer; font-weight: 700; color: var(--accent); padding: 0.3rem 0; }
.passage { border-top: 1px dotted var(--border); padding: 0.5rem 0; }
.passage h3 { margin: 0.2rem 0 0.4rem; font-size: 1rem; color: #333; }
.passage-body { white-space: pre-wrap; font-family: inherit; margin: 0; color: #444; line-height: 1.7; }

/* フォーム */
fieldset { border: 1px solid var(--border); padding: 1rem; margin: 1rem 0; border-radius: 4px; }
fieldset legend { padding: 0 0.5rem; color: var(--accent); font-weight: 700; }

.chart-actions { display: flex; gap: 0.5rem; margin: 1.5rem 0; }
.chart-actions .btn { background: var(--accent); }
.chart-actions .btn[style*="888"] { background: #888; }

/* レポートページ */
.report-toc { background: #fff; border: 1px solid var(--border); border-radius: 4px; padding: 1rem 1.5rem; margin: 1.5rem 0; }
.report-toc h2 { margin: 0 0 0.5rem; font-size: 1.1rem; color: var(--accent); }
.report-toc ol { margin: 0; padding-left: 1.5rem; line-height: 1.8; }
.report-toc a { color: var(--fg); text-decoration: none; }
.report-toc a:hover { color: var(--accent); text-decoration: underline; }
section.report-section { margin: 1rem 0; }
section.report-section details { background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 4px; padding: 0.5rem 1rem; }
section.report-section details[open] { padding-bottom: 1rem; }
section.report-section summary { cursor: pointer; padding: 0.6rem 0; list-style-position: outside; }
section.report-section summary::-webkit-details-marker { color: var(--accent); }
section.report-section summary::marker { color: var(--accent); }
section.report-section .section-title { font-size: 1.2rem; font-weight: 700; color: var(--accent); }
section.report-section .section-count { color: var(--muted); font-size: 0.9rem; margin-left: 0.5rem; }
section.report-section .passage { border-top: 1px dotted var(--border); padding: 0.75rem 0; }
section.report-section .passage:first-of-type { border-top: none; }
section.report-section .passage h3 { font-size: 1rem; margin: 0.2rem 0 0.4rem; }

/* 印刷用 */
@media print {
  header, footer, form.chart-form, button, .danger, nav { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  main { max-width: 100%; padding: 0; margin: 0; }
  section { page-break-inside: avoid; }
  section.chart, section.shibito { page-break-after: auto; }
  h1, h2, h3 { page-break-after: avoid; }
  details { page-break-inside: auto; }
  details > summary { font-size: 13pt; }
  details[open] { padding: 0; border: none; }
  details:not([open]) { display: none; }
  .palace { min-height: 90px; }
  table.pillars td.stem, table.pillars td.branch { font-size: 14pt; }
}
