:root {
  --paper: #f6f1e7;
  --card: #fbf8f1;
  --ink: #2a2420;
  --sub: #7a6e62;
  --rule: #d9cfbd;
  --accent: #b23a1e;
  --hi: #efe3c8;
  --mincho: "Zen Old Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font-family: "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic", sans-serif;
  font-size: 15px; line-height: 1.6; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
[hidden] { display: none !important; }

.shell-doc { padding-bottom: 32px; }

/* 見出し */
.hd { padding: 18px 0 8px; }
.hd h1 {
  font-family: var(--mincho); font-weight: 700; font-size: 28px; letter-spacing: .12em; margin: 0;
  display: inline-block; border-bottom: 3px double var(--ink); padding-bottom: 2px;
}
.hd .lead { margin: 6px 0 0; color: var(--sub); font-size: 14px; }

/* タブ（帳面の見出し紙） */
.tabs { display: flex; gap: 0; border-bottom: 2px solid var(--ink); margin: 12px 0 14px; overflow-x: auto; }
.tabs button {
  background: transparent; border: 1px solid var(--rule); border-bottom: 0; margin-right: -1px;
  padding: 8px 16px 6px; font-size: 15px; color: var(--sub); white-space: nowrap;
}
.tabs button.on { background: var(--ink); color: var(--paper); border-color: var(--ink); font-weight: 700; }
#savedN { font-variant-numeric: tabular-nums; }

/* 共通のボタン */
.btns { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin: 8px 0; }
.btns button, #b-wipe {
  background: var(--card); border: 1px solid var(--ink); padding: 7px 12px; font-size: 14px;
}
.btns button:active, #b-wipe:active, .chips button:active { background: var(--ink); color: var(--paper); }
#b-wipe.armed, #savedList button.armed { background: var(--accent); border-color: var(--accent); color: #fff; }
.msg { font-size: 13px; color: var(--accent); }
.msg .link { border: 0; background: none; padding: 0 2px; text-decoration: underline; color: var(--ink); font-size: 13px; }
.note { font-size: 12px; color: var(--sub); }
.lbl { display: block; font-size: 13px; color: var(--sub); margin: 0 0 4px; }

/* 人数 */
.serv {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;
  padding: 8px 10px; background: var(--card); border: 1px solid var(--rule); margin-bottom: 14px; font-size: 14px;
}
.stp { display: inline-flex; align-items: stretch; border: 1px solid var(--ink); background: #fff; }
.stp button { border: 0; background: transparent; width: 36px; height: 36px; font-size: 18px; line-height: 1; }
.stp button:active { background: var(--ink); color: var(--paper); }
.stp b {
  min-width: 2.2em; text-align: center; align-self: center; font-size: 20px;
  font-family: var(--mincho); font-variant-numeric: tabular-nums;
}
.factor { margin-left: auto; font-size: 13px; color: var(--sub); padding: 2px 8px; border: 1px solid var(--rule); }
.factor.on { color: #fff; background: var(--accent); border-color: var(--accent); font-weight: 700; }

/* 入力と結果 */
.cols { display: grid; grid-template-columns: 1fr; gap: 18px; }
@media (min-width: 780px) { .cols { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); gap: 28px; } }
textarea {
  width: 100%; font: inherit; font-size: 17px; line-height: 32px; color: var(--ink);
  padding: 0 10px; border: 1px solid var(--ink); resize: vertical; min-height: 200px;
  background: #fffdf8 repeating-linear-gradient(to bottom, transparent 0 31px, var(--rule) 31px 32px);
  background-attachment: local;
}
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips button { background: transparent; border: 1px solid var(--ink); padding: 5px 9px; font-size: 14px; }

table { width: 100%; border-collapse: collapse; }
.out { font-size: 16px; }
.out th, .ref th {
  font-size: 12px; font-weight: 400; color: var(--sub); text-align: left;
  border-bottom: 2px solid var(--ink); padding: 0 6px 3px;
}
.out td { border-bottom: 1px dotted var(--sub); padding: 7px 6px; vertical-align: top; cursor: pointer; }
.out td small { display: block; font-size: 12px; color: var(--sub); }
.out tr.sel td { background: var(--hi); }
.out tr.sel td:first-child { box-shadow: inset 4px 0 0 var(--accent); }
.out tr.head td { cursor: default; font-size: 13px; color: var(--sub); border-bottom: 0; padding-top: 12px; }
.out tr.empty td { cursor: default; color: var(--sub); font-size: 14px; padding: 18px 6px; }
.r { text-align: right !important; }
.out .g {
  font-family: var(--mincho); font-weight: 700; font-size: 22px; line-height: 1.1;
  font-variant-numeric: tabular-nums; white-space: nowrap; width: 5.2em;
}
.out .g .u { font-family: "BIZ UDPGothic", sans-serif; font-size: 13px; font-weight: 400; margin-left: 2px; }
.out td:nth-child(2) { white-space: nowrap; }
.total { text-align: right; padding: 8px 6px 0; font-size: 14px; }
.total b { font-family: var(--mincho); font-size: 22px; color: var(--accent); }
.total .note { display: block; }

/* 選んだ行のくわしい表示 */
.detail { margin-top: 14px; border-top: 2px solid var(--ink); padding-top: 10px; }
.detail:empty { display: none; }
.dt-h { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.dt-h b { font-size: 17px; }
.dt-h span { font-family: var(--mincho); font-size: 22px; color: var(--accent); font-weight: 700; }
.dt-fig { padding: 8px 0 2px; overflow: hidden; touch-action: pan-y; }
.fig { display: block; max-width: 100%; height: auto; }
.fig-n { font-family: var(--mincho); font-size: 15px; font-weight: 700; fill: var(--ink); }
.fig-s { font-size: 11px; fill: var(--sub); }
.dt-step { display: flex; align-items: center; gap: 10px; margin: 4px 0 10px; font-size: 14px; }
.dt-step button { width: 44px; height: 40px; border: 1px solid var(--ink); background: #fff; font-size: 20px; }
.dt-step button:active { background: var(--ink); color: var(--paper); }
.dt-step span { flex: 1; text-align: center; }
.eq { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); margin: 0; border-top: 1px solid var(--rule); border-left: 1px solid var(--rule); }
.eq div { border-right: 1px solid var(--rule); border-bottom: 1px solid var(--rule); padding: 4px 8px; }
.eq div.cur { background: var(--hi); }
.eq dt { font-size: 11px; color: var(--sub); }
.eq dd { margin: 0; font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }

/* 共有ボタン（共通部品の見た目を帳面に合わせる） */
.share { margin-top: 6px; }
.share .shell-share button {
  border-radius: 0; border: 1px solid var(--ink); background: transparent; color: var(--ink);
  font-family: inherit; font-size: 13px; padding: 5px 10px;
}
.share .shell-share button:active { background: var(--ink); color: var(--paper); }
.share .shell-done { color: var(--accent); }

/* 早見表 */
.tb-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; }
#filter { flex: 1; min-width: 0; max-width: 320px; font: inherit; font-size: 16px; padding: 7px 10px; border: 1px solid var(--ink); background: #fffdf8; }
.ref { font-size: 15px; }
.ref td { border-bottom: 1px dotted var(--sub); padding: 6px; font-variant-numeric: tabular-nums; }
.ref tr[data-n] { cursor: pointer; }
.ref tr[data-n]:hover td, .ref tr[data-n]:active td { background: var(--hi); }
.ref tr.head td { font-size: 12px; color: var(--sub); border-bottom: 1px solid var(--ink); padding-top: 14px; }
.ref tr.empty td { color: var(--sub); font-size: 14px; }
.sw { display: inline-block; width: 10px; height: 10px; border: 1px solid var(--ink); margin-right: 6px; vertical-align: 0; }
h3 { font-family: var(--mincho); font-size: 18px; margin: 26px 0 8px; border-bottom: 1px solid var(--ink); padding-bottom: 2px; }
.mini { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.mini figure { margin: 0; padding: 6px; background: var(--card); border: 1px solid var(--rule); }
.mini .fig { margin: 0 auto; max-height: 110px; width: auto; }
.mini figcaption { font-size: 12px; color: var(--sub); text-align: center; }
.mini figcaption b { display: block; color: var(--ink); font-size: 15px; }
.units th, .units td { text-align: left; border-bottom: 1px dotted var(--sub); padding: 6px; font-size: 14px; }
.units th { font-weight: 700; white-space: nowrap; width: 9em; }

/* 保存 */
.saved { list-style: none; padding: 0; margin: 0; }
.saved li { display: flex; gap: 10px; align-items: center; border-bottom: 1px dotted var(--sub); padding: 8px 0; }
.sv-t { flex: 1; min-width: 0; }
.sv-t b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sv-t span { font-size: 12px; color: var(--sub); }
.sv-b { display: flex; gap: 4px; }
.sv-b button { background: var(--card); border: 1px solid var(--ink); padding: 6px 10px; font-size: 13px; white-space: nowrap; }

/* 設定 */
.set-row { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: center; padding: 12px 0; border-bottom: 1px dotted var(--sub); }
.set-l { width: 12em; font-weight: 700; font-size: 14px; }
.seg { display: inline-flex; flex-wrap: wrap; }
.seg button { background: var(--card); border: 1px solid var(--ink); margin-right: -1px; padding: 7px 12px; font-size: 14px; }
.seg button.on { background: var(--ink); color: var(--paper); }

/* 使い方 */
.howto { margin-top: 8px; border-top: 3px double var(--ink); padding-top: 4px; max-width: 720px; }
.howto h2 { font-family: var(--mincho); font-size: 18px; margin: 18px 0 4px; }
.howto p { margin: 0 0 8px; font-size: 14px; }
.howto .eg { font-size: 14px; background: var(--card); border: 1px solid var(--rule); padding: 6px 10px; }
.ft { margin-top: 28px; font-size: 12px; color: var(--sub); }

@media (max-width: 420px) {
  .hd h1 { font-size: 24px; }
  .out { font-size: 15px; }
  .out .g { font-size: 19px; width: 4.6em; }
  .out td:nth-child(2) { white-space: normal; }
  .tabs button { padding: 8px 12px 6px; }
  .factor { margin-left: 0; }
  .set-l { width: 100%; }
}
