/* 家系図ノート 閲覧ページ。外のフォント・画像は読まない(docs/19 §3-2) */

:root {
  --bg: #fbfaf7;
  --ink: #333;
  --muted: #6f685d;
  --frame: #8a8377;
  --line: #5a544a;
  --accent: #9b4a32;
  --panel: #ffffff;
  --notice: #f3efe6;
  --error: #a8321e;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Yu Gothic", "Meiryo",
    "Noto Sans JP", "Noto Sans CJK JP", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.7;
  -webkit-text-size-adjust: 100%;
}

.masthead { padding: 20px 16px 4px; max-width: 960px; margin: 0 auto; }
.masthead h1 { font-size: 1.3rem; margin: 0 0 4px; }
.lead { margin: 0; color: var(--muted); font-size: 0.95rem; }

main { max-width: 1400px; margin: 0 auto; padding: 8px 16px 24px; }

.intro { max-width: 928px; margin: 0 auto; }

.notice {
  background: var(--notice);
  border-left: 4px solid var(--frame);
  border-radius: 6px;
  padding: 12px 16px;
  margin: 12px 0 20px;
  font-size: 0.95rem;
}
.notice p { margin: 0 0 8px; }
.notice p:last-child { margin-bottom: 0; }

.drop-zone {
  border: 2px dashed var(--frame);
  border-radius: 12px;
  padding: 32px 16px;
  text-align: center;
  background: var(--panel);
}
.drop-zone.dragging { border-color: var(--accent); background: #fff6f1; }
.drop-hint { color: var(--muted); font-size: 0.85rem; margin: 12px 0 0; }

.pick input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.pick-button {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 12px 28px;
  border-radius: 999px;
  cursor: pointer;
}
.pick input[type="file"]:focus-visible + .pick-button { outline: 3px solid #e2a68f; outline-offset: 2px; }

.error {
  color: var(--error);
  background: #fdf0ec;
  border-radius: 6px;
  padding: 10px 14px;
  margin: 16px auto;
  max-width: 928px;
  overflow-wrap: anywhere;
}

[hidden] { display: none !important; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 4px 0 8px;
}
.tree-title { font-size: 1.1rem; margin: 0; overflow-wrap: anywhere; min-width: 0; }
.tools { display: flex; gap: 6px; flex-wrap: wrap; }
.tools button, .detail-head button {
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--frame);
  background: var(--panel);
  color: var(--ink);
  border-radius: 8px;
  padding: 6px 12px;
  min-height: 40px;
  min-width: 40px;
  cursor: pointer;
}
.tools button:hover { background: var(--notice); }

.tree-notice { font-size: 0.85rem; color: var(--muted); margin: 0 0 8px; }

.stage {
  position: relative;
  height: calc(100vh - 230px);
  min-height: 360px;
  border: 1px solid #ddd6ca;
  border-radius: 10px;
  background: #fff;
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.stage:active { cursor: grabbing; }

.canvas { display: block; width: 100%; height: 100%; }
.canvas text { font-family: var(--font); text-anchor: middle; pointer-events: none; }
.canvas .label { font-size: 13px; font-weight: 600; fill: #333; }
.canvas .label.placeholder { font-weight: 400; fill: #999; }
.canvas .sublabel { font-size: 10px; fill: #8a8377; }
.canvas.far .sublabel { display: none; }
.canvas .frame { stroke: #8a8377; stroke-width: 1.2; }
/* 強調(v1.12): 外側にもう1本、墨色(名前と同じ色)。太さではなく形で言う */
.canvas .emphasis-frame { stroke: #333; }
.canvas .frame.placeholder { stroke: #b4ada2; stroke-dasharray: 4 3; }
.canvas .box { cursor: pointer; outline: none; }
.canvas .box:hover .frame { stroke-width: 2; }
.canvas .box:focus-visible .frame { stroke: var(--accent); stroke-width: 2.5; }
.canvas .box.selected .frame { stroke: var(--accent); stroke-width: 2.5; }

.detail {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 320px;
  max-width: calc(100% - 24px);
  max-height: calc(100% - 24px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid #ddd6ca;
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(60, 50, 40, 0.18);
  padding: 12px 16px 16px;
  touch-action: auto;
  user-select: text;
  -webkit-user-select: text;
  cursor: auto;
}
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.detail-head h3 { margin: 4px 0 8px; font-size: 1.1rem; overflow-wrap: anywhere; }
.detail dl { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 0.92rem; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; overflow-wrap: anywhere; }

.legend { margin: 10px 0 0; font-size: 0.88rem; color: var(--muted); }
.legend summary { cursor: pointer; }
.legend ul { list-style: none; padding: 0; margin: 8px 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.swatch { display: inline-block; width: 28px; height: 16px; border-radius: 4px; border: 1.2px solid #8a8377; }
.swatch-male { background: #e3f0fd; }
.swatch-female { background: #feeaeb; }
.swatch-unspecified { background: #f7f5f0; }
.swatch-deceased { background: #c3cfd9; }
.swatch-placeholder { background: #f7f5f0; border-style: dashed; }
.line { display: inline-block; width: 32px; height: 0; border-top: 1.5px solid var(--line); }
.line-dotted { border-top-style: dotted; }
.line-dashdot { border-top-style: dashed; }
.line-double { border-top: 4.5px double var(--line); }
.line-dashed { border-top-style: dashed; }

.footnote { font-size: 0.8rem; color: var(--muted); margin: 8px 0 0; }

body.viewing .lead { display: none; }

@media (max-width: 640px) {
  .masthead { padding-top: 10px; }
  .masthead h1 { font-size: 1.05rem; }
  .tree-title { font-size: 0.95rem; width: 100%; }
  .tools button { padding: 4px 10px; }
  .stage { height: calc(100vh - 190px); height: calc(100dvh - 190px); min-height: 300px; }
  .detail {
    top: auto;
    bottom: 0;
    right: 0;
    left: 0;
    width: auto;
    max-width: none;
    max-height: 60%;
    border-radius: 14px 14px 0 0;
  }
}
