/* ISHDU shared style — approved palette (cream/tea/green) + Apple/Google
   inspired layout: generous whitespace, quiet typography, subtle borders. */
:root {
  /* approved palette — exact hex from design/confirmed-only assets */
  --cream: #F5F0E9;      /* page background */
  --paper: #ffffff;      /* card surface */
  --ink: #263D33;        /* primary text (deep green) */
  --green-deep: #243B30; /* darkest green */
  --muted: #5C6B62;      /* secondary text */
  --faint: #8a7a64;      /* captions */
  --green: #376B4E;      /* accent / active */
  --edge: #70977D;       /* relation edge stroke */
  --tea: #79583D;        /* bark / branch stroke */
  --tan: #D9C6B0;        /* bark fill */
  --hair: #C3D2C5;       /* hairline borders */
  --lgreen: #EDF4EE;     /* light green fill (selected paint) */
  --lgreen2: #DCEBDC;    /* light green fill alt */
  --line: #d8cfc0;
  --line-soft: #e8e0d0;
  --warn-bg: #ede7d8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(43, 36, 28, .05), 0 8px 30px rgba(43, 36, 28, .06);
  --font: Author, Nunito, 'UD Digi Kyokasho NP', 'UD デジタル 教科書体 NP-B',
          'Yu Gothic', 'Hiragino Sans', -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--cream);
  color: var(--ink);
  line-height: 1.65;
  font-size: 16px;
}
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── accessibility ──────────────────────────────────────── */
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--green-deep); color: #fff; padding: 10px 18px;
  border-radius: 0 0 10px 0; font-weight: 700;
}
.skip-link:focus { left: 0; }

:focus-visible {
  outline: 3px solid var(--green); outline-offset: 2px; border-radius: 4px;
}

.fontscale { display: flex; gap: 2px; margin-left: 8px; }
.fontscale button {
  border: 1px solid var(--line); background: #fff; color: var(--muted);
  font-family: var(--font); font-size: 12px; font-weight: 700;
  padding: 4px 9px; border-radius: 8px; cursor: pointer;
}
.fontscale button.on { background: var(--green); border-color: var(--green); color: #fff; }
body.fs-s { font-size: 14px; }
body.fs-l { font-size: 18px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
}

.shell { max-width: 1080px; margin: 0 auto; padding: 0 24px; }

/* ── header ─────────────────────────────────────────────── */
.site-header {
  position: sticky; top: 0; z-index: 10;
  background: rgba(246, 241, 231, .88);
  backdrop-filter: saturate(1.2) blur(12px);
  border-bottom: 1px solid var(--line);
}
.site-header .inner {
  display: flex; align-items: center; gap: 24px;
  height: 60px; max-width: 1080px; margin: 0 auto; padding: 0 24px;
}
.brand { font-weight: 700; font-size: 18px; letter-spacing: .02em; color: var(--ink); }
.brand small { font-weight: 400; color: var(--faint); font-size: 12px; margin-left: 8px; }

/* Axis selector — approved Option A: header placement, single-select,
   custom dropdown (no generic select box), vertical scroll for growth */
.axis-sel { position: relative; }
.axis-sel-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--hair); background: #fff;
  font-family: var(--font); font-size: 13px; font-weight: 700;
  color: var(--muted); cursor: pointer;
}
.axis-sel-btn .axis-now { color: var(--green); }
.axis-sel-btn::after { content: "▾"; font-size: 10px; color: var(--faint); }
.axis-sel[open] .axis-sel-btn { border-color: var(--green); color: var(--green); }
.axis-sel-list {
  position: absolute; top: calc(100% + 8px); left: 0; z-index: 40;
  min-width: 190px; max-height: 280px; overflow-y: auto;
  background: #fff; border: 1px solid var(--hair); border-radius: 12px;
  box-shadow: var(--shadow); padding: 6px; margin: 0; list-style: none;
}
.axis-sel-list li {
  padding: 9px 12px; border-radius: 8px; font-size: 13.5px;
  font-weight: 600; color: var(--ink); cursor: pointer;
  display: flex; justify-content: space-between; align-items: center;
}
.axis-sel-list li:hover { background: var(--lgreen); }
.axis-sel-list li.on { color: var(--green); }
.axis-sel-list li.on::after { content: "✓"; font-size: 12px; }
.site-nav { display: flex; gap: 4px; margin-left: auto; }
.site-nav a {
  padding: 8px 14px; border-radius: 999px; font-size: 14px;
  color: var(--muted); font-weight: 600;
}
.site-nav a:hover { background: var(--line-soft); text-decoration: none; }
.site-nav a.active { background: var(--green); color: #fff; }

/* ── hero ───────────────────────────────────────────────── */
.hero { padding: 48px 0 40px; }
.hero-root { display: block; width: 260px; height: auto; margin-bottom: 18px; }
.hero-cta { margin-top: 22px !important; display: flex; align-items: center; }
.hero .eyebrow {
  font-size: 12px; letter-spacing: .22em; text-transform: uppercase;
  color: var(--tea); font-weight: 700;
}
.hero h1 { font-size: 40px; line-height: 1.2; margin: 12px 0 16px; font-weight: 700; }
.hero p { max-width: 620px; color: var(--muted); font-size: 17px; margin: 0; }

/* ── sections & cards ───────────────────────────────────── */
section.block { padding: 40px 0; border-top: 1px solid var(--line-soft); }
.block > .shell > h2, h2.block-title {
  font-size: 22px; margin: 0 0 6px; color: var(--green-deep);
}
.block .lead { color: var(--muted); font-size: 14px; margin: 0 0 24px; }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ── PIN gate ───────────────────────────────────────────── */
.pin-card { max-width: 480px; margin: 0 auto; text-align: center; }
.pin-card h2 { margin-top: 0; }
.pin-row { display: flex; gap: 10px; justify-content: center; margin: 20px 0 8px; }
.pin-row input {
  width: 200px; padding: 12px 16px; font-size: 20px; letter-spacing: .3em;
  text-align: center; border: 1.5px solid var(--line); border-radius: 10px;
  font-family: var(--font); background: #fff; color: var(--green-deep);
}
.pin-row input:focus { outline: 2px solid var(--green); border-color: var(--green); }
.pin-status { font-size: 13px; min-height: 20px; color: var(--faint); }
.pin-status.ok { color: var(--green); }
.pin-status.err { color: #a33; }
.pin-note { font-size: 12px; color: var(--faint); margin-top: 16px; }

/* ── buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 22px; border-radius: 999px; border: 1.5px solid transparent;
  font-family: var(--font); font-size: 15px; font-weight: 700; cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .15s ease;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-deep); text-decoration: none; }
.btn-outline { background: #fff; border-color: var(--tea); color: var(--tea); }
.btn-outline:hover { background: var(--warn-bg); text-decoration: none; }
.btn-google { background: #fff; border-color: #dadce0; color: #3c4043; }
.btn-google:hover { background: #f8f9fa; text-decoration: none; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ── plan table ─────────────────────────────────────────── */
.plan-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; }
@media (max-width: 900px) { .plan-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .plan-grid { grid-template-columns: repeat(2, 1fr); } }
.plan-card {
  position: relative; text-align: center; padding: 20px 12px;
  border: 1.5px solid var(--line); border-radius: var(--radius); background: var(--paper);
}
.plan-card.current { border-color: var(--green); box-shadow: var(--shadow); }
.plan-card.soon { opacity: .62; }
.plan-name { font-size: 17px; font-weight: 700; }
.plan-quota { font-size: 12px; color: var(--muted); margin: 6px 0 12px; }
.badge {
  display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: .08em;
  padding: 3px 10px; border-radius: 999px;
}
.badge-live { background: rgba(55, 107, 78, .12); color: var(--green); border: 1px solid rgba(55, 107, 78, .35); }
.badge-soon { background: rgba(0, 0, 0, .05); color: #999; border: 1px dashed rgba(0, 0, 0, .18); }
.badge-pin { background: var(--warn-bg); color: var(--tea); border: 1px solid var(--line); }

/* ── tree preview ───────────────────────────────────────── */
.tree-panel { overflow-x: auto; }
.node-pill {
  display: inline-block; padding: 6px 14px; margin: 4px;
  border-radius: 999px; border: 1px solid var(--line);
  background: #fff; font-size: 13px; font-weight: 600;
}
.node-pill.root { border-color: var(--green); color: var(--green); }
.node-pill.derived { border-color: var(--tea); color: var(--tea); }
.node-pill.chain { border-style: dashed; color: var(--faint); }

/* ── footer ─────────────────────────────────────────────── */
.site-footer {
  border-top: 1px solid var(--line); padding: 32px 0 48px;
  color: var(--faint); font-size: 12px;
}

/* ── app shell: Header / LeftNav / Canvas / RightContext ── */
body.app { display: flex; flex-direction: column; min-height: 100vh; }
.app-body {
  flex: 1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) 280px;
  gap: 0;
  max-width: 1440px; width: 100%; margin: 0 auto;
}

/* left navigation — collapsible, edge handle (Option B) */
.leftnav {
  position: relative;
  width: 232px;
  border-right: 1px solid var(--line);
  background: var(--paper);
  min-height: 60vh;
  transition: width .18s ease;
}
.leftnav-panel { padding: 20px 14px; position: sticky; top: 60px; }
.leftnav-cap {
  font-size: 10px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--faint); margin: 0 0 10px 4px;
}
.leftnav-list { list-style: none; margin: 0; padding: 0; }
.leftnav-list a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px; font-size: 14px;
  font-weight: 600; color: var(--muted);
}
.leftnav-list a:hover { background: var(--line-soft); text-decoration: none; }
.leftnav-list a.active { background: var(--green); color: #fff; }
.leftnav-list .mi { font-family: 'Material Icons Outlined'; font-size: 20px; }
.leftnav-pos { font-size: 11px; margin: 18px 4px 0; }
.leftnav-handle {
  position: absolute; top: 88px; right: -15px; z-index: 5;
  width: 30px; height: 56px; min-width: 30px;
  border: 1px solid var(--hair); border-left: none;
  border-radius: 0 12px 12px 0; background: #fff;
  color: var(--tea); cursor: pointer; padding: 0;
  display: flex; align-items: center; justify-content: center;
}
.leftnav-handle:hover { background: var(--lgreen); }
.leftnav-handle svg { width: 14px; height: 32px; }
.leftnav-handle .seam-leaf { transition: transform .18s ease; transform-origin: center; }
.leftnav.collapsed .leftnav-handle .seam-leaf { transform: scaleX(-1); }
.leftnav.collapsed { width: 0; border-right: none; }
.leftnav.collapsed .leftnav-panel { display: none; }
.leftnav.collapsed .leftnav-handle { right: -30px; border-left: 1px solid var(--hair); }

/* canvas — active view */
.canvas { padding: 32px 36px 64px; min-width: 0; }
.view { animation: view-in .18s ease; }
@keyframes view-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }
.canvas .hero { padding: 8px 0 28px; }
.canvas .pin-card { margin: 0; max-width: 520px; }
.canvas .block-title { margin-bottom: 6px; }
.canvas .lead { margin-bottom: 20px; }

/* right context panel */
.rightctx {
  border-left: 1px solid var(--line);
  background: var(--paper);
  padding: 20px 16px; min-height: 60vh;
}
.rightctx-cap {
  font-size: 10px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--faint); margin: 0 0 12px;
}
.ctx-field { margin-bottom: 14px; }
.ctx-field .k {
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--faint); margin-bottom: 3px;
}
.ctx-field .v { font-size: 13.5px; line-height: 1.55; }
.ctx-divider { border-top: 1px solid var(--line-soft); margin: 14px 0; }

/* header nav uses pills consistent with shell */
.site-nav a.active { background: var(--green); color: #fff; }

/* ── graph (Phase 11) — approved palette: hairline #C3D2C5,
   relation edge #70977D, selected paint #EDF4EE ────────── */
.cycle-badge {
  font-size: 11.5px; font-weight: 700; color: #8a3b12;
  background: #f7e7da; border: 1px solid #e0b890;
  border-radius: 999px; padding: 4px 12px; margin-left: 10px;
}
.cycle-badge.ok { color: var(--green); background: var(--lgreen); border-color: var(--hair); }

.tree-graph-wrap { overflow: auto; max-height: 68vh; }
svg.mtree { display: block; }
svg.mtree .edge {
  fill: none; stroke: var(--edge); stroke-width: 1.6;
}
svg.mtree .edge.ea { stroke-dasharray: 4 4; opacity: .6; }
svg.mtree .gnode { cursor: pointer; outline: none; }
svg.mtree .gnode rect.box {
  fill: #fff; stroke: var(--hair); stroke-width: 1.2;
  transition: stroke .15s;
}
svg.mtree .gnode rect.paint {
  fill: var(--lgreen); stroke: none;
  width: 0; transition: width .3s ease;
  pointer-events: none;
}
svg.mtree .gnode.sel rect.paint { width: 200px; } /* = NW in app.js */
svg.mtree .gnode.sel rect.box { stroke: var(--green); stroke-width: 2; }
svg.mtree .gnode:hover rect.box,
svg.mtree .gnode:focus-visible rect.box { stroke: var(--green); stroke-width: 2; }
svg.mtree .gnode[data-type="ROOT"] rect.box { stroke: var(--tea); stroke-width: 1.8; }
svg.mtree .gnode[data-type="CHAIN"] rect.box { fill: var(--warn-bg); }
svg.mtree .gnode.ea rect.box { stroke-dasharray: 4 3; }
svg.mtree .gnode text {
  font-family: var(--font); font-size: 12.5px; fill: var(--ink);
  pointer-events: none;
}
svg.mtree .gnode .gtype { font-size: 9.5px; fill: var(--faint); letter-spacing: .08em; }
svg.mtree .depth-cap {
  font-size: 10px; font-weight: 700; letter-spacing: .2em; fill: var(--faint);
}

.tguide {
  border-left: 3px solid var(--tea); padding: 4px 0 4px 14px;
}
.tguide summary {
  cursor: pointer; font-weight: 700; font-size: 13.5px; color: var(--tea);
}
.tguide[open] summary { margin-bottom: 8px; }

.history-list { list-style: none; margin: 0; padding: 0; }
.history-list li {
  font-size: 12.5px; padding: 5px 0; border-bottom: 1px solid var(--line-soft);
  display: flex; justify-content: space-between; gap: 8px; cursor: pointer;
}
.history-list li:hover { color: var(--green); }
.history-list .h-time { color: var(--faint); font-size: 11px; flex-shrink: 0; }

/* ── principle detail (approved Option C structure) ────── */
.detail-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.detail-tags { display: flex; gap: 8px; }
.detail-title { font-size: 24px; line-height: 1.35; margin: 0 0 6px; }
.detail-q { font-size: 14px; margin: 0 0 22px; }
.btn-back { padding: 8px 16px; font-size: 13px; }

.dsec { border-top: 1px solid var(--line-soft); padding: 16px 0; }
.dsec-cap {
  font-size: 11px; font-weight: 700; letter-spacing: .18em;
  text-transform: uppercase; color: var(--tea); margin-bottom: 8px;
}
.dsec .k { font-size: 12px; font-weight: 700; color: var(--faint); margin: 8px 0 4px; }
.dsec ul { margin: 4px 0; padding-left: 20px; }
.dsec li { font-size: 14px; margin: 3px 0; }
.statement { font-size: 15.5px; line-height: 1.8; }
.terms { margin: 0; }
.terms dt { font-weight: 700; font-size: 13.5px; margin-top: 8px; }
.terms dd { margin: 2px 0 0 0; font-size: 13.5px; color: var(--muted); }
.formula {
  font-size: 16px; background: var(--warn-bg); border-radius: 8px;
  padding: 10px 14px; display: inline-block;
}
.cex { font-size: 14px; background: #faf3ee; border-left: 3px solid var(--tea); padding: 10px 14px; border-radius: 0 8px 8px 0; }
.expl-switch { display: flex; gap: 6px; margin-bottom: 10px; }
.expl-btn {
  padding: 5px 14px; border-radius: 999px; border: 1px solid var(--line);
  background: #fff; font-family: var(--font); font-size: 12px; font-weight: 700;
  color: var(--faint); cursor: pointer;
}
.expl-btn.on { background: var(--green); border-color: var(--green); color: #fff; }
.expl-body { font-size: 14.5px; line-height: 1.8; }
.pill-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.node-pill.link { cursor: pointer; font-family: var(--font); font-size: 13px; }
.node-pill.link:hover { box-shadow: var(--shadow); }
.src-list li { font-size: 13px; }
.tree-group { margin-bottom: 18px; }
.tree-group .k { font-size: 12px; font-weight: 700; letter-spacing: .12em; color: var(--faint); margin-bottom: 8px; }
.search-hit {
  border: 1px solid var(--line-soft); border-radius: 10px; padding: 12px 14px;
  margin: 8px 0; cursor: pointer;
}
.search-hit:hover { border-color: var(--green); }

/* responsive shell */
@media (max-width: 1020px) {
  .app-body { grid-template-columns: auto minmax(0, 1fr); }
  .leftnav { width: 200px; }
  .rightctx { display: none; }
}
@media (max-width: 680px) {
  .app-body { grid-template-columns: minmax(0, 1fr); }
  .leftnav { display: none; }
  .canvas { padding: 20px 18px 48px; }
  .site-nav { display: none; }
}

/* ── util ───────────────────────────────────────────────── */
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-variant-numeric: tabular-nums; }
