:root {
  --ground: #eceae6;
  --paper: #ffffff;
  --ink: #000000;
  --structure: var(--ink);
  --gray: #d8d5d0;
  --text-size: clamp(0.95rem, 1.3vw, 1.15rem);
  --blank-line: 1lh;
  --poem-line: 1.9em;
  --root2: 1.41421;
  --sheet-portrait: min(72svh, 48rem, calc(84vw * var(--root2)));
  --sheet-landscape: min(68svh, 46rem, calc(92vw / var(--root2)));
  --font-gothic: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Hiragino Kaku Gothic Pro", "Yu Gothic", "YuGothic", "Noto Sans JP", "Hiragino Sans GB", Meiryo, sans-serif;
  --font-mincho: "Hiragino Mincho ProN", "Hiragino Mincho Pro", "Yu Mincho", "YuMincho", "Noto Serif JP", "MS PMincho", serif;
}

* {
  box-sizing: border-box;
}

::selection {
  background: var(--gray);
  color: var(--ink);
}

html {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--ground);
  color: var(--ink);
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  min-width: 320px;
  min-height: 100svh;
  margin: 0;
  overflow: hidden;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-gothic);
  font-size: var(--text-size);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: currentColor;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  -webkit-tap-highlight-color: transparent;
}

a:focus:not(:focus-visible) {
  outline: none;
}

a:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus:not(:focus-visible) {
  outline: none;
}

.site-nav a,
.scroll-cue,
.about-page .text-scroll,
.list-page .list-scroll,
.photo-viewer-controls button,
.photo-viewer-close {
  color: var(--ink);
  font-family: var(--font-gothic);
}

.about-page .text-scroll,
.list-page .list-scroll {
  font-weight: 300;
}

.about-page .text-scroll :is(h1, p, li) {
  text-box: trim-both text;
}

/* 一覧の各行は1行ボックスのまま（trimすると行間が字面幅まで潰れる） */
.list-page .list-scroll :is(li, #work-list-empty) {
  text-box: normal;
  text-box-trim: none;
}

/* 見出しは1行ボックスを埋めてから空行1。trimすると行グリッドが初手でずれる */
.about-page .text-scroll h1,
.list-page .list-scroll h1,
.list-frame h1 {
  text-box: normal;
  text-box-trim: none;
}

.about-page .text-flow p + p {
  margin-block-start: calc((1.9 - 1) * 1em);
}

.site-nav {
  position: absolute;
  z-index: 4;
  bottom: 100%;
  right: 0;
  display: flex;
}

.work-page .site-nav {
  position: fixed;
  top: env(safe-area-inset-top, 0px);
  right: env(safe-area-inset-right, 0px);
  bottom: auto;
}

.site-nav a {
  display: block;
  min-block-size: 1.5rem;
  padding: 0.04em 0.35em 0.1em;
  border: 1px solid var(--structure);
  border-bottom: 0;
  background: var(--paper);
  text-decoration: none;
}

.work-page .site-nav a {
  border-bottom: 1px solid var(--structure);
}

.site-nav a + a {
  margin-left: -1px;
}

.about-sheet,
.list-sheet,
.work-sheet {
  touch-action: none;
}

.about-sheet,
.list-sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100svh;
  display: grid;
  place-items: center;
}

.frame-group {
  position: relative;
  min-width: 0;
  min-height: 0;
}

.about-page .frame-group,
.list-page .frame-group,
.essay-page .frame-group,
.tanka-page .frame-group,
.poem-page .frame-group {
  opacity: 0;
}

.frame-group.is-ready {
  opacity: 1;
}

@media (scripting: none) {
  .about-page .frame-group,
  .list-page .frame-group,
  .essay-page .frame-group,
  .tanka-page .frame-group,
  .poem-page .frame-group {
    opacity: 1;
  }
}

.about-page .frame-group,
.list-page .frame-group {
  height: var(--sheet-portrait);
  aspect-ratio: 1 / var(--root2);
}

.text-frame,
.list-frame,
.work-frame {
  position: relative;
  z-index: 2;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 1px solid var(--structure);
  background: var(--paper);
  color: var(--ink);
  line-height: 1;
  text-align: start;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
}

.text-frame::-webkit-scrollbar,
.list-frame::-webkit-scrollbar,
.work-frame::-webkit-scrollbar {
  display: none;
}

.scroll-rule {
  display: none;
  position: absolute;
  z-index: 3;
  bottom: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: var(--structure);
  pointer-events: none;
}

.text-frame,
.list-frame {
  overflow-x: hidden;
  overflow-y: auto;
  touch-action: none;
}

.work-frame {
  overflow-x: auto;
  overflow-y: hidden;
  touch-action: none;
}

.text-scroll,
.list-scroll {
  display: block;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  writing-mode: horizontal-tb;
  font-feature-settings: "palt" 0;
  width: 100%;
  height: max-content;
  min-height: 100%;
  line-height: 1.9;
  overflow: hidden;
}

.work-scroll {
  display: block;
  box-sizing: border-box;
  margin: 0;
  margin-block-end: auto;
  padding: 0;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-feature-settings: "palt" 0;
  height: 100%;
  width: max-content;
  max-height: 100%;
  min-height: 0;
  line-height: 1;
  color: var(--ink);
  font-family: var(--font-mincho);
}

.essay-page .work-scroll,
.tanka-page .work-scroll,
.poem-page .work-scroll {
  overflow: clip;
}

.essay-page .work-scroll {
  margin-block-end: calc((1 - 1.9) / 2 * 1em);
}

html.work-document {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body.work-page {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 100svh;
  overflow: hidden;
}

.work-sheet {
  position: relative;
  z-index: 1;
  display: grid;
  width: 100%;
  height: 100svh;
  min-height: 0;
  padding-block: 0;
  place-items: center;
}

.work-page .frame-group {
  height: var(--sheet-landscape);
  aspect-ratio: var(--root2) / 1;
  margin: 0 auto;
}

html.essay-document,
html.tanka-document,
html.poem-document {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body.essay-page,
body.tanka-page,
body.poem-page {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 100svh;
  overflow: hidden;
}

.essay-page .work-sheet,
.tanka-page .work-sheet,
.poem-page .work-sheet {
  display: grid;
  height: 100svh;
  min-height: 0;
  padding-block: 0;
  place-items: center;
}

.essay-page .frame-group,
.tanka-page .frame-group,
.poem-page .frame-group {
  height: var(--sheet-landscape);
  aspect-ratio: var(--root2) / 1;
}

.poem-page .work-scroll section + section {
  margin-block-start: calc(var(--poem-line) * 2);
}

.poem-page .work-scroll h1,
.poem-page .poem-stanza p {
  margin: 0;
  line-height: 1;
  text-box: normal;
}

.poem-page .poem-body {
  margin: 0;
  line-height: 1;
}

.poem-page .poem-stanza p {
  display: block;
  text-indent: 0;
}

.poem-page .poem-stanza p + p {
  margin-block-start: calc(var(--poem-line) - 1em);
}

.poem-page .poem-stanza + .poem-stanza {
  margin-block-start: var(--poem-line);
}

.essay-page .work-scroll section,
.tanka-page .work-scroll section,
.poem-page .work-scroll section {
  display: block;
  margin: 0;
  padding: 0;
}

.essay-page .work-scroll section + section,
.tanka-page .work-scroll section + section {
  margin-top: 0;
  margin-block-start: calc(1.9em * 2);
}

.essay-page .work-scroll h1 {
  display: block;
  max-width: none;
  margin: 0;
  padding: 0;
  background: transparent;
  font-weight: 400;
  line-height: 1;
}

.essay-page .work-body p {
  margin: 0;
}

.essay-page .work-body h2 + * {
  margin: 0;
}

.essay-page .work-scroll h2 {
  display: block;
  margin: 0;
  margin-block: 2em 0.8em;
  padding: 0;
  background: transparent;
}

.essay-page .work-quote p {
  font-style: normal;
}

.essay-page .work-quote {
  margin-block: 3.5em;
  padding-inline-start: 1em;
}

.essay-page .work-body > p {
  text-indent: 1em;
}

.essay-page .work-note {
  margin-top: 0;
  margin-block-start: 4em;
  padding-top: 0;
  padding-block-start: 2em;
  border-top: 0;
  border-block-start: 1px solid var(--ink);
}

.essay-page .work-note li + li {
  margin-top: 0;
  margin-block-start: 0.35em;
}

.essay-page .prose {
  margin-block-start: 2.5em;
}

.work-page .scroll-cue span {
  display: inline-block;
  transform: rotate(90deg);
}

.tanka-page .work-scroll h1 {
  display: block;
  max-width: none;
  margin: 0;
  padding: 0;
  background: transparent;
  font: inherit;
  font-weight: 400;
  line-height: 1.9;
}

.poem-page .work-scroll h1 {
  display: block;
  max-width: none;
  margin: 0;
  padding: 0;
  background: transparent;
  font: inherit;
  font-weight: 400;
  line-height: 1;
}

.tanka-page .work-scroll h1 .work-slash,
.poem-page .work-scroll h1 .work-slash {
  margin: 0;
}

.poem-page .work-scroll h2 {
  display: block;
  margin: 0;
  margin-block: 0 var(--poem-line);
  padding: 0;
  background: transparent;
  font: inherit;
  font-weight: 400;
  line-height: 1;
}

.poem-page .work-body h2 + * {
  margin: 0;
}

.poem-page .poem + .poem {
  margin-block-start: calc(var(--poem-line) * 2);
}

.list-frame {
  max-height: none;
}

.text-frame:focus-visible,
.list-frame:focus-visible,
.work-frame:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.text-scroll,
.work-scroll {
  padding: 0;
}

.text-scroll h1,
.text-flow p,
.list-frame h1,
.work-list li,
#work-list-empty,
.work-scroll h1,
.work-scroll h2,
.work-scroll p,
.work-scroll li,
.work-scroll summary,
.work-scroll time {
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: 1.9;
}

.list-scroll :is(h1, h2, p, li),
.list-scroll #work-list-empty {
  line-height: 1.9;
}

.text-scroll h1,
.list-frame h1,
.work-scroll h1,
.work-scroll h2 {
  display: block;
  max-width: none;
  margin: 0;
  margin-block-end: 1.6em;
  padding: 0;
  background: transparent;
  font-weight: inherit;
  line-height: 1.9;
}

.about-page .text-scroll h1,
.list-page .list-scroll h1,
.list-frame h1 {
  margin-block-end: var(--blank-line);
}

.work-scroll {
  padding: 0;
}

.work-scroll section {
  margin: 0;
  padding: 0;
}

.work-scroll section + section {
  margin-block-start: 2.5em;
}

.essay-page .work-scroll > :last-child,
.tanka-page .work-scroll > :last-child {
  margin-block-end: 0;
}

.work-scroll h1 .work-slash {
  margin: 0 0.15em;
}

.work-meta {
  display: block;
  margin-block-start: -1em;
}

.work-body p {
  margin: 0;
  margin-block-end: 0.75em;
  line-height: 1.9;
}

.work-scroll h2 {
  margin: 0;
  margin-block-start: 2em;
}

.work-body h2 + * {
  margin: 0;
  margin-block-start: 0.75em;
}

.work-format-criticism > * + * {
  margin: 0;
  margin-block-start: 1.25em;
}

.work-quote {
  margin-block: 3.5em;
  margin-inline: 0;
  padding: 0;
  border: 0;
  background: var(--paper);
}

.work-quote p {
  margin: 0;
  font-style: oblique 6deg;
  font-synthesis: style;
}

.work-quote p + p {
  margin-top: 0.65em;
}

.work-note {
  margin-top: 4em;
  padding-top: 2em;
  border-top: 1px solid var(--ink);
}

.work-note ol {
  margin: 0.5em 0 0;
  padding: 0;
  list-style: none;
}

.work-note li + li {
  margin-top: 0.35em;
}

.work-note-ref {
  white-space: nowrap;
}

.work-note-ref a,
.work-note-return {
  text-decoration: none;
}

.work-note-label,
.work-note-return {
  margin-right: 0.35em;
}

.work-note-rule {
  display: inline-block;
  margin-right: 0.12em;
  letter-spacing: -0.06em;
  white-space: nowrap;
  transform: scaleX(1.064);
  transform-origin: left center;
}

.work-note li:target,
.work-note-ref a:target {
  background: var(--paper);
  outline: 2px solid var(--structure);
  outline-offset: 1px;
}

.prose p {
  margin: 0.5em 0;
}

.prose summary {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.prose summary:focus:not(:focus-visible) {
  outline: none;
}

.prose summary:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.prose summary + p {
  margin-top: 0.75em;
}

.tanka-sequence {
  display: block;
  height: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
  font: inherit;
  line-height: 1.9;
}

.tanka-sequence li {
  display: inline;
  margin: 0;
  padding: 0;
  font: inherit;
}

.tanka-sequence li + li::before {
  content: "　　";
}

.tanka-sequence p {
  display: inline;
  margin: 0;
}

.photo-sequence,
.photo-sequence figure {
  margin: 0;
  padding: 0;
  height: 100%;
}

.photo-sequence figure + figure {
  margin-top: 0;
  margin-block-start: 2.5em;
}

.photo-sequence img {
  display: block;
  width: auto;
  height: 100%;
  max-height: 100%;
  object-fit: contain;
}

.photo-fullscreen-trigger {
  display: block;
  width: auto;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  cursor: zoom-in;
}

.photo-fullscreen-trigger:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.photo-fullscreen-label {
  display: block;
  width: fit-content;
  margin: 0.35em 0 0 auto;
  padding: 0 0.08em 0.06em;
  border: 0;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  line-height: 1.7;
}

.photo-viewer[hidden] {
  display: none;
}

.photo-viewer {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding-top: max(3.5rem, env(safe-area-inset-top));
  padding-right: max(clamp(1rem, 4vw, 3rem), env(safe-area-inset-right));
  padding-bottom: max(3.5rem, env(safe-area-inset-bottom));
  padding-left: max(clamp(1rem, 4vw, 3rem), env(safe-area-inset-left));
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  place-items: center;
  overflow: hidden;
  background: var(--paper);
}

.photo-viewer-stage {
  display: grid;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  cursor: zoom-in;
  touch-action: none;
}

.photo-viewer-stage[data-zoomed="true"] {
  cursor: grab;
}

.photo-viewer-stage.is-dragging {
  cursor: grabbing;
}

.photo-viewer-stage img {
  display: block;
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
  will-change: transform;
}

.photo-viewer-controls {
  position: absolute;
  z-index: 1;
  top: max(0.35rem, env(safe-area-inset-top));
  left: max(0.55rem, env(safe-area-inset-left));
  display: flex;
  gap: 0.45em;
}

.photo-viewer-controls button {
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0 0.08em 0.06em;
  border: 0;
  border-radius: 0;
  background: var(--paper);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  font: inherit;
  cursor: pointer;
}

.photo-viewer-controls button:disabled {
  opacity: 0.35;
  cursor: default;
}

.photo-viewer-controls button:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

.photo-viewer-close {
  position: absolute;
  z-index: 1;
  top: max(0.35rem, env(safe-area-inset-top));
  right: max(0.55rem, env(safe-area-inset-right));
  min-width: 44px;
  min-height: 44px;
  margin: 0;
  padding: 0 0.08em 0.06em;
  border: 0;
  border-radius: 0;
  background: var(--paper);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
  font: inherit;
  cursor: pointer;
}

.photo-viewer-close:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

html.work-document.photo-viewer-open,
html.work-document.photo-viewer-open body {
  overflow: hidden;
}

.photo-sequence figcaption {
  margin-top: 0;
  margin-block-start: 0.5em;
}

.text-flow p {
  margin: 0;
}

.text-flow p:last-child {
  margin-block-end: 0;
}

.about-page .text-flow a {
  text-decoration-color: var(--ink);
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.work-list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.work-list[hidden] {
  display: none;
}

.list-scroll .work-list li,
.list-scroll #work-list-empty {
  margin: 0;
  padding: 0;
  line-height: 1.9;
}

.work-list li a.work-list-label {
  display: inline;
  padding: 0;
  line-height: inherit;
  font-style: normal;
  text-decoration: underline;
  text-decoration-color: currentColor;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.08em;
}

.work-list li .work-list-num {
  font-style: normal;
}

#work-list-empty[hidden] {
  display: none;
}

.scroll-cue {
  position: absolute;
  z-index: 4;
  top: 100%;
  left: 0;
  min-width: 2.2em;
  min-height: 2.2em;
  margin: 0;
  padding: 0;
  border: 1px solid var(--structure);
  border-top: 0;
  border-radius: 0;
  background: var(--paper);
  font: inherit;
  line-height: 1;
  cursor: pointer;
}

.scroll-cue[hidden] {
  display: none;
}

.scroll-cue:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

@media (max-width: 700px) {
  .about-page .frame-group,
  .list-page .frame-group {
    height: min(72svh, calc(88vw * var(--root2)));
  }

  .work-page .frame-group,
  .essay-page .frame-group,
  .tanka-page .frame-group,
  .poem-page .frame-group {
    height: min(68svh, calc(88vw * var(--root2)));
    aspect-ratio: 1 / var(--root2);
  }
}
