:root {
  --bg: #f4efe6;
  --panel: #fffefa;
  --ink: #2b2723;
  --muted: #877c70;
  --line: #e5ddd0;
  --accent: #725432;
  --accent-2: #aa3933;
  --accent-soft: #f3eadb;
  --grid: #b23c36;         /* 罫線色（JSで上書き） */
  --paper: #fffdf4;
  --paper-edge: #f7eedb;
  --cell: 30px;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(60, 50, 30, .06), 0 10px 26px rgba(60, 50, 30, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(255,255,255,.85), transparent 340px),
    var(--bg);
  line-height: 1.7;
}

.wrap { max-width: 980px; margin: 0 auto; padding: 0 20px; }

.site-header {
  background: linear-gradient(180deg, #fffdf8 0%, rgba(255,253,248,.72) 100%);
  border-bottom: 1px solid var(--line);
  padding: 28px 0 17px;
}
.site-header h1 { font-size: 1.48rem; margin: 0 0 6px; letter-spacing: .02em; }
.tagline { margin: 0; color: var(--muted); font-size: .9rem; }
.tagline.privacy { margin-top: 3px; font-size: .84rem; }

main { padding: 22px 0 44px; display: grid; gap: 18px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
}
.panel h2 { font-size: 1.05rem; margin: 0 0 12px; }

/* editor */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.btn {
  font: inherit;
  padding: 7px 15px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  transition: filter .15s, background .15s, transform .15s;
}
.btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn.ghost { background: #fff; color: var(--accent); }
.btn.ghost:hover { background: var(--accent-soft); }

textarea#input {
  width: 100%;
  min-height: 220px;
  padding: 15px;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  resize: vertical;
}
textarea#input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* stats */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-card.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.stat-card.accent  { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.stat-value { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat-label { font-size: .84rem; color: var(--muted); margin-top: 3px; }
.stat-card.primary .stat-label,
.stat-card.accent  .stat-label { color: rgba(255,255,255,.88); }
.stat-label .sub { display: block; font-size: .76rem; }

/* options */
.opt-grid { display: flex; flex-wrap: wrap; gap: 10px 22px; align-items: center; }
.opt { display: inline-flex; align-items: center; gap: 7px; font-size: .92rem; cursor: pointer; }
.opt input[type="checkbox"] { accent-color: var(--accent-2); }
.opt.color input[type=color] {
  width: 34px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
}
.hint { margin: 12px 0 0; font-size: .82rem; color: var(--muted); }

/* view */
.view-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.view-info { font-size: .85rem; color: var(--muted); }
.sheets {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 30px;
  align-items: flex-start;
  overflow-x: auto;
  padding: 2px 2px 24px;
}
.sheet-block { flex: 0 0 auto; }
.sheet-title { font-size: .82rem; color: var(--muted); margin: 0 0 8px; text-align: center; }

/* 縦書き原稿用紙（20×20）
   実物に近い横長レイアウト：10行 + 中央余白 + 10行。
   1行ごとにすき間を持たせ、ただの正方形グリッドに見えないようにする。 */
:root {
  --cell-w: 25px;
  --cell-h: 25px;
  --line-gap: 9px;
  --center-gap: 40px;
  --paper-pad-x: 38px;
  --paper-pad-y: 30px;
}

.sheet {
  position: relative;
  padding: var(--paper-pad-y) var(--paper-pad-x);
  background: linear-gradient(180deg, #fffdf6 0%, #fdf8ec 100%);
  border: 1px solid rgba(120, 70, 45, .18);
  border-radius: 4px;
  box-shadow: 0 10px 24px rgba(60, 40, 30, .12);
}

/* 外枠。実物の原稿用紙と同じく、枠線が升目全体を囲む。 */
.manuscript-paper {
  display: inline-flex;
  align-items: stretch;
  border: 2px solid var(--grid);
  background: var(--paper);
  direction: ltr;
}

.paper-half {
  display: flex;
  flex-direction: row-reverse;
  gap: var(--line-gap);
}

/* 中央の折り目余白。上部に魚尾、下部に「20×20」を置く。 */
.center-gutter {
  flex: 0 0 var(--center-gap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  height: calc(var(--cell-h) * 20);
}
.center-gutter::before {
  content: "";
  margin-top: calc(var(--cell-h) * 1.1);
  width: 55%;
  height: 13px;
  background: var(--grid);
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% 52%, 0 100%);
}
.center-gutter::after {
  content: "20×20";
  margin-bottom: calc(var(--cell-h) * .55);
  font-size: 9px;
  letter-spacing: .08em;
  color: var(--grid);
  line-height: 1;
}

.column {
  position: relative;
  display: grid;
  grid-template-rows: repeat(20, var(--cell-h));
  width: var(--cell-w);
  height: calc(var(--cell-h) * 20);
  border-left: 1px solid var(--grid);
  border-right: 1px solid var(--grid);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  width: var(--cell-w);
  height: var(--cell-h);
  border-bottom: 1px solid var(--grid);
  overflow: hidden;
}
.cell:last-child { border-bottom: 0; }
.cell.has-combo { grid-template-rows: 1fr; }

/* 本物の縦組みで描画する。「ー」「〜」の回転や「、」「っ」の
   マス内配置はフォントの縦書き字形に任せる。 */
.glyph {
  display: inline-grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-family: "Yu Mincho", "Hiragino Mincho ProN", "YuMincho", "MS Mincho", serif;
  font-size: 18px;
  line-height: 1;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  text-align: center;
  user-select: text;
}

.glyph.is-mark { font-size: 19px; }
.glyph.is-space { color: transparent; }
.glyph.is-latin { font-size: 15px; text-orientation: upright; }

/* 行末記号を「最後の枠の中に収める」ための2字配置。
   1字目を中央寄り、記号を下端寄りに小さく置き、マス外には出さない。 */
.cell.has-combo .glyph {
  position: absolute;
  inset: 0;
}
.cell.has-combo .combo-main {
  transform: translateY(-3.5px);
  font-size: 16px;
}
.cell.has-combo .combo-mark {
  transform: translateY(7.6px);
  font-size: 11px;
  line-height: 1;
}
.cell.has-combo .combo-mark + .combo-mark {
  transform: translateY(2px);
}

/* オプションで「枠の外に配置する」を選んだ場合のみ使う。標準では使わない。 */
.outside-hanger {
  position: absolute;
  top: calc(100% + 1px);
  left: 0;
  width: var(--cell-w);
  min-height: calc(var(--cell-h) * .55);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  pointer-events: none;
  overflow: visible;
}
.glyph.is-hang {
  width: 100%;
  height: calc(var(--cell-h) * .34);
  font-size: 11px;
  color: var(--grid);
  line-height: 1;
}

.opt.select select {
  font: inherit;
  font-size: .9rem;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 5px 28px 5px 9px;
}

.site-footer { border-top: 1px solid var(--line); padding: 16px 0; }
.site-footer p { margin: 0; color: var(--muted); font-size: .82rem; }

@media (max-width: 680px) {
  .wrap { padding: 0 14px; }
  .panel { padding: 16px; }
  .sheets { flex-wrap: nowrap; }
}

@media (max-width: 480px) {
  :root { --cell-w: 22px; --cell-h: 22px; --line-gap: 5px; --center-gap: 30px; --paper-pad-x: 24px; --paper-pad-y: 24px; }
  .stat-value { font-size: 1.55rem; }
  .glyph { font-size: 15px; }
  .glyph.is-mark { font-size: 16px; }
  .glyph.is-latin { font-size: 12px; }
  .cell.has-combo .combo-main { font-size: 13px; transform: translateY(-3px); }
  .cell.has-combo .combo-mark { font-size: 9px; transform: translateY(6.6px); }
}

@media print {
  :root { --cell-w: 24px; --cell-h: 24px; --line-gap: 6px; --center-gap: 38px; --paper-pad-x: 34px; --paper-pad-y: 28px; }
  body { background: #fff; }
  .site-header, .site-footer, .editor, .stats, .options, .view-head { display: none !important; }
  .panel { border: none; box-shadow: none; padding: 0; background: #fff; }
  .sheets { gap: 24px; overflow: visible; padding: 0; }
  .sheet { box-shadow: none; page-break-inside: avoid; break-inside: avoid; }
}

.site-footer .credit { margin-top: 4px; }
.site-footer .credit a { color: var(--accent); }
