:root {
  --serif: "Palatino Linotype", "Book Antiqua", Palatino, "Yu Mincho", YuMincho, "Hiragino Mincho ProN",
           "Noto Serif CJK JP", "Noto Serif JP", "Source Han Serif JP", serif;
  --sans: "Yu Gothic UI", "Yu Gothic", YuGothic, "Hiragino Sans", "Noto Sans CJK JP", "Noto Sans JP", sans-serif;
  --ink: #1c1814;
  --tab: #171513;
  --tablabel: #e6dcc6;
  --ui-bg: rgba(26, 20, 15, .92);
  --ui-fg: #ebe3d4;
  --ui-sub: #b3a894;
  --ui-line: rgba(255, 255, 255, .14);
  color-scheme: dark;
  background: #120c08;
}
:root:not(.dark) {
  color-scheme: light;
  background: #9c7a54;
  --ui-bg: rgba(251, 247, 239, .95);
  --ui-fg: #2a241d;
  --ui-sub: #6f6555;
  --ui-line: rgba(0, 0, 0, .12);
}

html, body { margin: 0; height: 100%; overflow: hidden; }
body { font-family: var(--sans); }
canvas { display: block; }

#stage {
  position: fixed; inset: 0; overflow: hidden;
  touch-action: none; user-select: none; -webkit-user-select: none;
  -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent;
  cursor: ns-resize;
}
#stage.dragging, #stage.dragging * { cursor: grabbing !important; }

#desk { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }

.face { position: absolute; inset: 0; overflow: hidden; contain: strict; pointer-events: none; }
.face canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; will-change: transform; }

#page { position: absolute; right: 0; bottom: 0; overflow: hidden; }
#paper { position: absolute; left: 0; top: 0; width: 100%; height: 100%; }
#bodywrap { position: absolute; overflow: hidden; contain: strict; }
#body { position: absolute; left: 0; top: 0; will-change: transform; }

#tab {
  position: absolute; left: 0; top: 0; will-change: transform;
  display: flex; align-items: center; justify-content: center;
  background: var(--tab); color: var(--tablabel);
  border-radius: 0 2px 2px 0;
  font-family: var(--sans); font-weight: 700; line-height: 1;
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, .04);
}

#head {
  position: absolute; display: flex; flex-direction: column; justify-content: flex-end;
  contain: strict; will-change: transform;
  color: var(--ink);
}
#yomi {   /* 見出し欄の上端に固定 (めくっても位置が動かない)。タイトルは下揃えのまま */
  position: absolute; left: 0; top: 0; width: 100%;
  font-family: var(--serif); font-weight: 400; line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85;
}
#word {
  flex: none; min-width: 0;
  font-family: var(--serif); font-weight: 700; line-height: 1.06;
  white-space: nowrap; font-feature-settings: "palt";
  text-shadow: 0 0 .6px rgba(28, 24, 20, .45);
}
#word.two { white-space: normal; text-wrap: balance; overflow-wrap: anywhere; }
#rule { position: absolute; height: 1.5px; background: var(--ink); opacity: .78; }

#link { position: absolute; inset: 0; z-index: 5; -webkit-user-drag: none; }

#vignette, #grain { position: absolute; left: 0; top: 0; width: 100%; height: 100%; pointer-events: none; }
#vignette { background: radial-gradient(ellipse 85% 95% at 56% 30%, transparent 40%, rgba(6, 3, 1, .62) 100%); }
:root:not(.dark) #vignette { background: radial-gradient(ellipse 90% 100% at 50% 35%, transparent 50%, rgba(30, 18, 6, .22) 100%); }

/* ---- UI ---- */
#menu-btn {
  position: fixed; top: 12px; right: 12px; z-index: 20;
  width: 40px; height: 40px; padding: 0; border: 1px solid var(--ui-line); border-radius: 10px;
  background: var(--ui-bg); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
#menu-btn span { display: block; width: 18px; height: 2px; border-radius: 1px; background: var(--ui-fg); }
#menu {
  position: fixed; top: 60px; right: 12px; z-index: 20;
  width: min(320px, calc(100vw - 24px)); box-sizing: border-box; padding: 12px 14px;
  border: 1px solid var(--ui-line); border-radius: 12px;
  background: var(--ui-bg); color: var(--ui-fg); font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .35);
}
#menu label { display: flex; align-items: center; gap: 8px; padding: 5px 0; cursor: pointer; }
#reload {
  display: block; width: 100%; margin: 0 0 8px; padding: 8px 0;
  border: 1px solid var(--ui-line); border-radius: 8px; background: transparent;
  color: var(--ui-fg); font: inherit; cursor: pointer;
}
#menu select { margin-left: auto; font: inherit; }
#menu hr { border: 0; border-top: 1px solid var(--ui-line); margin: 10px 0; }
#menu .help { margin: 0; font-size: 12px; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; }
#menu .help dt { color: var(--ui-fg); }
#menu .help dd { margin: 0; color: var(--ui-sub); }
#menu .meta { margin: 10px 0 0; font-size: 12px; color: var(--ui-sub); }
#menu a { color: inherit; }

#typed {
  position: fixed; right: 16px; bottom: 16px; z-index: 15;
  padding: 6px 12px; border-radius: 8px; border: 1px solid var(--ui-line);
  background: var(--ui-bg); color: var(--ui-fg);
  font: 600 18px ui-monospace, Consolas, monospace; letter-spacing: .04em;
}

.missing { position: fixed; inset: 0; margin: auto; height: 2em; text-align: center; color: #eee; font-size: 18px; }
