:root {
  --bg: #efe8da;
  --fg: #1b1714;
  --paper: #fbf8f1;
  --accent: #a3271f;
  --muted: #6b6259;
  /* #8f8574 は背景 #efe8da と 2.98:1。3:1 を超える隣接色 */
  --rule: #8e8473;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
/* 完成の演出（3 倍の落款・飛沫・揺れ）で横にはみ出しても、表示域を広げず横スクロールも出さない。縦は残す */
/* html の指定は表示域へ、body の指定は body 自身に効く（両方に書かないと揺れの分だけ文書の幅が広がる） */
html, body, main { overflow-x: clip; }
body {
  font-family: "Shippori Mincho", "Yu Mincho", "Hiragino Mincho ProN", "Noto Serif JP", serif;
}
/* 1 画面に収める。半紙は残りの高さ。状態の予告を足しても半紙が下限を割らないよう、間隔は 4px */
main {
  max-width: 640px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
h1 {
  font-family: "Yuji Syuku", "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-weight: 400;
  font-size: clamp(1.2rem, 5vw, 1.8rem);
  margin: 0;
  letter-spacing: 0.04em;
  text-align: center;
}
.odai-row {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.odai, .chars { flex-shrink: 0; }
.odai { margin: 0; font-size: 1.1rem; white-space: nowrap; }
#odai { font-size: 1.6rem; letter-spacing: 0.3em; }
.chars {
  display: flex;
  border: 1px solid var(--fg);
  border-radius: 4px;
}
.chars button:first-child { border-radius: 3px 0 0 3px; }
.chars button:last-child { border-radius: 0 3px 3px 0; }
.paper-wrap {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  container-type: size;
  display: flex;
  justify-content: center;
  align-items: center;
}
#paper {
  display: block;
  /* 比は枠線の内側（描画域）で取る。content-box なので枠線 2 px を先に引く */
  box-sizing: content-box;
  /* 二文字: 高さで決まる時は高さから、幅で決まる時は幅（= 高さの半分）から枠線を引き、外寸を容器に収める */
  height: min(100cqh - 2px, 200cqw - 4px, 998px);
  aspect-ratio: 1 / 2;
  background: var(--paper);
  border: 1px solid var(--rule);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  touch-action: none;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
/* 落款と墨の飛沫は半紙に重ねる飾り。入力は下へ通し、読み上げにも出さない */
.sheet { position: relative; flex: none; line-height: 0; }
.seal-layer {
  --seal: 96px;
  --seal-gap: 8px;
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.seal {
  position: absolute;
  right: var(--seal-gap);
  bottom: var(--seal-gap);
  width: var(--seal);
  height: var(--seal);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--paper);
  border-radius: 6px;
  font-family: "Shippori Mincho", "Yu Mincho", "Hiragino Mincho ProN", serif;
  font-weight: 500;
  font-size: calc(var(--seal) * 0.62);
  line-height: 1;
  rotate: -6deg;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}
.seal[hidden] { display: none; }
.splash {
  position: absolute;
  left: calc(100% - var(--seal-gap) - var(--seal) / 2);
  top: calc(100% - var(--seal-gap) - var(--seal) / 2);
  border-radius: 50%;
  background: var(--fg);
  opacity: 0;
}
/* 一文字: 容器に収まる最大の正方形。縦に余るときは上下の中央 */
#paper[data-cells="1"] {
  height: min(100cqh - 2px, 100cqw - 2px, 998px);
  aspect-ratio: 1 / 1;
}
.controls {
  display: flex;
  flex-wrap: nowrap;
  justify-content: center;
  align-items: center;
  gap: 12px;
  max-width: 100%;
}
/* 広い画面は 1 行。狭い画面のメディアクエリで 2 段にする */
.row { display: contents; }
button {
  font: inherit;
  font-weight: 500;
  font-size: 1.05rem;
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--fg);
  background: var(--paper);
  color: var(--fg);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
}
.chars button {
  min-width: 48px;
  padding: 0 10px;
  border: 0;
  border-radius: 0;
}
.chars button + button { box-shadow: inset 1px 0 0 var(--fg); }
.chars button[aria-pressed="true"] { background: var(--fg); color: var(--paper); }
button:disabled { opacity: 0.45; cursor: default; }
button:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }
button[hidden] { display: none !important; }
/* 主操作は同時に一つ。書くあいだは「完成」（墨色）、完成後は「Xに投稿」（黒） */
#finish { background: var(--fg); color: var(--paper); border-color: var(--fg); }
/* 白紙のあいだの「完成」は押せないが焦点は当たる（aria-disabled）。透かさず紙色の面に --muted の枠と字で、
   枠は背景 #efe8da と 4.9:1（3:1 以上）。透明度 0.45 の墨色は背景と 2.81:1 で境目が見えにくかった */
#finish[aria-disabled="true"] { background: var(--paper); color: var(--muted); border-color: var(--muted); cursor: default; }
#image,
#theme,
#image-save {
  background: var(--paper);
  color: var(--fg);
  border: 1px solid var(--fg);
}
#reset {
  background: var(--paper);
  color: var(--accent);
  border: 1px solid var(--accent);
}
#reset:hover,
#reset:active { background: var(--paper); color: var(--accent); }
#share {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #000000;
  color: #ffffff;
  border-color: #000000;
}
#share svg { width: 18px; height: 18px; flex: none; display: block; }
#share:hover { background: #272727; color: #ffffff; border-color: #272727; }
#image-save { font-size: 15px; }
/* 師範評と状態の文は同じ行。常に 1 行。狭い画面では 14px まで小さくして収め、折り返しで半紙を縮めない */
.status-row {
  width: 100%;
  min-height: 1.4em;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.hint, .status { margin: 0; line-height: 1.4; min-height: 1.4em; white-space: nowrap; color: var(--muted); text-align: center; }
.hint { font-size: clamp(14px, min(0.95rem, calc((100vw - 40px) / 20)), 0.95rem); }
.status { font-size: clamp(14px, calc((100vw - 40px) / 22), 1.3rem); line-height: 1.5; min-height: 1.5em; }
/* 予告（完成前）と師範評（完成後）は同じ場所に重ね、高さは大きい方だけ取る。半紙の大きさは完成で変えない */
.say { position: relative; width: 100%; display: grid; }
.say > * { grid-area: 1 / 1; }
.hint { align-self: start; }
/* 白紙のあいだ「完成」が押せない理由は、予告と同じ欄の下端に見える形で出す（完成前の師範評の欄は空） */
.finish-hint { align-self: end; }
/* 師範評: 見出しは 1 行、本文は大きく。16 字が 1 行に入る大きさで、長い評も切らずに折り返す */
.review { margin: 0; text-align: center; color: var(--fg); }
.review-head { display: block; font-size: 0.875rem; line-height: 1.1; min-height: 1.1em; color: var(--muted); letter-spacing: 0.2em; }
.review-body { display: block; font-size: 2.25rem; line-height: 1.15; min-height: 1.15em; font-weight: 500; overflow-wrap: anywhere; }
.review-title + .grade-note:not(:empty) { margin-left: 0.75em; }
/* 段位の注記は見出しの行に小さく添える。見出しの行は 1 行のまま */
.grade-note { font-size: 0.75rem; letter-spacing: 0.05em; white-space: nowrap; }
.glyphs > span { display: inline-block; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
/* 師範評は専用の 1 行を常に確保する（完成前は空）。保存や共有の文が出ても消えず、半紙も縮まない */
/* 完成時の status は読み上げ専用。枠は残して文字だけ切り取り、画面の師範評は #review の 1 か所だけ */
.status.is-review { clip-path: inset(50%); }
#intent-link {
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--fg);
  white-space: nowrap;
}
#intent-link[hidden] { display: none; }
/* 390px 幅は主操作と、書き直し・お題を 2 段に分ける。字は 15px 以上、間隔は 8px 以上、高さは 48px */
@media (max-width: 720px) {
  main { gap: 2px; padding: 6px 8px; }
  h1 { font-size: 1.05rem; line-height: 1.05; letter-spacing: 0.03em; }
  .controls { flex-direction: column; align-items: stretch; gap: 8px; width: 100%; }
  .row { display: flex; justify-content: center; gap: 8px; width: 100%; }
  .controls button { font-size: 15px; padding: 0 10px; }
  .status, .hint { line-height: 1.2; min-height: 1.2em; }
  #odai { font-size: 1.45rem; }
  .seal-layer { --seal: 64px; --seal-gap: 6px; }
  .review-head { font-size: 14px; }
  .review-body { font-size: clamp(18px, (100vw - 32px) / 16, 2rem); }
}
@media (max-width: 720px) and (max-height: 700px) {
  main { gap: 1px; padding: 2px 8px; }
  h1 { font-size: 0.95rem; line-height: 1; }
  .odai { font-size: 1rem; }
  #odai { font-size: 1.25rem; letter-spacing: 0.12em; }
  .status, .hint { line-height: 1.05; min-height: 1.05em; }
  .status { font-size: clamp(14px, calc((100vw - 24px) / 22), 1rem); }
}
