:root {
  --bg: #f6f1e7;        /* 和紙 */
  --fg: #2b2622;
  --sub: #7d7268;
  --card: #fffdf8;
  --paper: #fffdf6;
  --line: #e2d8c6;
  --rule: #d9cdb8;
  --shu: #c0392b;       /* 朱 */
  --shu-ink: #ffffff;
  --shu-soft: #f8e5e1;
  --ai: #2c4a6e;        /* 藍: 承認 */
  --ai-soft: #e3eaf3;
  --shadow: 0 2px 10px rgba(70, 50, 20, 0.08);
  --mincho: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1a17;
    --fg: #f1ebe3;
    --sub: #a89d92;
    --card: #282420;
    --paper: #2b2622;
    --line: #3e3731;
    --rule: #4a423a;
    --shu: #e0574a;
    --shu-soft: #45231f;
    --ai: #8fb0d8;
    --ai-soft: #22303f;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", "Noto Sans JP", sans-serif;
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
#app { max-width: 480px; margin: 0 auto; padding: 16px 16px calc(24px + env(safe-area-inset-bottom)); }
.hidden { display: none !important; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 21px; margin: 8px 0 12px; font-family: var(--mincho); }
.sub { color: var(--sub); font-size: 14px; margin: 4px 0; }
.center { text-align: center; }

button { font: inherit; cursor: pointer; border: 0; border-radius: 12px; color: inherit; }
button:disabled { opacity: 0.5; cursor: default; }
.primary { background: var(--shu); color: var(--shu-ink); padding: 14px 18px; font-size: 17px; font-weight: 700; }
.secondary { background: var(--card); border: 1px solid var(--line); padding: 14px 18px; font-size: 16px; }
.big { width: 100%; padding: 17px; font-size: 19px; }
.link { display: block; margin: 8px auto 0; background: none; color: var(--sub); text-decoration: underline; padding: 8px; font-size: 14px; }
.row { display: flex; gap: 10px; margin-top: 12px; }
.row > button { flex: 1; }
.wide { width: 100%; margin-top: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; box-shadow: var(--shadow); }

/* ---------- home ---------- */
.brand { text-align: center; margin: 20px 0 16px; }
.brand h1 { font-family: var(--mincho); font-size: 40px; letter-spacing: 6px; color: var(--shu); }
.saved { text-align: center; margin-bottom: 14px; }
.saved .sub { margin: 0; }
.saved-amount { font-family: var(--mincho); font-size: 42px; font-weight: 700; margin: 2px 0; }
.login-banner { text-align: center; margin-bottom: 14px; }
.login-banner p { margin: 0 0 10px; }
#h-plaza { margin-top: 4px; }
.list-head { margin-top: 26px; font-size: 18px; }
.ringi-list { list-style: none; padding: 0; margin: 0; }
.ringi-list li {
  display: flex; align-items: center; gap: 10px; padding: 12px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; cursor: pointer;
}
.ringi-list .li-main { flex: 1; min-width: 0; }
.ringi-list .li-item { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ringi-list .li-meta { font-size: 13px; color: var(--sub); margin-top: 2px; }
.ringi-list .li-price { font-weight: 700; white-space: nowrap; }
.chip { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 10px; border: 1px solid var(--line); color: var(--sub); margin-right: 4px; }
.chip.shu { border-color: var(--shu); color: var(--shu); }
.todo { margin: 0 0 14px; }
.todo button { width: 100%; text-align: left; margin-bottom: 8px; background: var(--shu-soft); border: 1px solid var(--shu); padding: 12px 14px; font-size: 15px; }
.legal { text-align: center; font-size: 12px; color: var(--sub); margin-top: 24px; }
.legal a { color: var(--sub); }

/* ---------- compose ---------- */
.seg { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; padding: 10px 4px; font-size: 15px; background: none; border-radius: 9px; }
.seg button.on { background: var(--shu); color: var(--shu-ink); font-weight: 700; }
#c-mode-note { margin: 8px 2px 12px; font-size: 13px; line-height: 1.5; }

/* The 稟議書 itself: ruled paper with a red title rule. */
.paper {
  background: var(--paper); border: 1px solid var(--rule); border-radius: 4px; padding: 18px 16px;
  box-shadow: var(--shadow); position: relative;
}
.paper-title {
  font-family: var(--mincho); font-size: 24px; font-weight: 700; letter-spacing: 8px; text-align: center;
  margin: 0 0 12px; padding-bottom: 8px; border-bottom: 2px double var(--shu);
}
.paper label { display: block; font-size: 13px; color: var(--sub); margin: 12px 0 0; }
.paper input, .paper select, .paper textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px; font: inherit; font-size: 16px; color: var(--fg);
  background: transparent; border: 0; border-bottom: 1px solid var(--rule); border-radius: 0;
}
.paper textarea { resize: vertical; border: 1px solid var(--rule); border-radius: 4px; }
.paper input:focus, .paper select:focus, .paper textarea:focus { outline: none; border-color: var(--shu); }
.paper .check { display: flex; align-items: center; gap: 8px; color: var(--fg); font-size: 15px; }
.paper .check input { width: 20px; height: 20px; margin: 0; }
.paper .big { margin-top: 16px; }
.error { color: var(--shu); font-size: 14px; min-height: 1.2em; margin: 8px 0 0; }

/* ---------- ringi document ---------- */
.plaza-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.plaza-bar select { font: inherit; font-size: 14px; padding: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--fg); }
.doc { padding-bottom: 20px; }
.doc .doc-head { display: flex; justify-content: space-between; font-size: 12px; color: var(--sub); margin-bottom: 6px; }
.doc table { width: 100%; border-collapse: collapse; font-size: 15px; }
.doc th {
  width: 5.5em; text-align: left; vertical-align: top; font-weight: 400; color: var(--sub); font-size: 13px;
  padding: 9px 6px 9px 0; border-bottom: 1px solid var(--rule); white-space: nowrap;
}
.doc td { padding: 8px 0; border-bottom: 1px solid var(--rule); line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }
.doc td.price { font-family: var(--mincho); font-size: 26px; font-weight: 700; }
.doc .deadline { margin: 10px 0 0; font-size: 13px; color: var(--sub); text-align: right; }

/* 印鑑: a round red seal, slightly rotated, as if pressed by hand. */
.seal {
  position: absolute; right: 14px; top: 104px; width: 84px; height: 84px; border-radius: 50%;
  border: 4px solid var(--shu); color: var(--shu); display: flex; align-items: center; justify-content: center;
  font-family: var(--mincho); font-weight: 700; font-size: 26px; letter-spacing: 2px;
  transform: rotate(-14deg); opacity: 0.88; background: transparent; pointer-events: none;
  box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 4px var(--shu);
}
.seal.small { font-size: 21px; }
.seal.grey { border-color: var(--sub); color: var(--sub); box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 4px var(--sub); }
.seal.ai { border-color: var(--ai); color: var(--ai); box-shadow: inset 0 0 0 2px var(--paper), inset 0 0 0 4px var(--ai); }
.seal.press { animation: press 0.35s ease-out; }
@keyframes press {
  0% { transform: rotate(-14deg) scale(1.8); opacity: 0; }
  70% { transform: rotate(-14deg) scale(0.94); opacity: 0.95; }
  100% { transform: rotate(-14deg) scale(1); opacity: 0.88; }
}

.vote-panel { margin-top: 14px; }
.stamps { display: flex; gap: 14px; justify-content: center; margin-bottom: 10px; }
.stamp-btn {
  width: 116px; height: 116px; border-radius: 50%; font-family: var(--mincho); font-size: 30px; font-weight: 700;
  background: var(--card); border: 4px solid var(--line); color: var(--sub);
}
.stamp-btn.approve.on { border-color: var(--ai); color: var(--ai); background: var(--ai-soft); }
.stamp-btn.reject.on { border-color: var(--shu); color: var(--shu); background: var(--shu-soft); }
#r-vote-form textarea {
  width: 100%; padding: 10px; font: inherit; font-size: 16px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--fg); margin-top: 6px;
}
#r-vote-form .big { margin-top: 8px; }
.note-box { background: var(--card); border: 1px dashed var(--line); border-radius: 12px; padding: 12px; text-align: center; font-size: 14px; }

.tally { margin: 18px 0 8px; }
.tally-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--line); }
.tally-bar .a { background: var(--ai); }
.tally-bar .r { background: var(--shu); }
.tally-nums { display: flex; justify-content: space-between; font-size: 14px; margin-top: 6px; }
.tally-nums .a { color: var(--ai); font-weight: 700; }
.tally-nums .r { color: var(--shu); font-weight: 700; }

.reasons { list-style: none; padding: 0; margin: 8px 0 0; }
.reasons li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.reasons .who { font-size: 12px; white-space: nowrap; padding-top: 2px; }
.reasons .who b { display: block; font-size: 15px; }
.reasons .who .a { color: var(--ai); }
.reasons .who .r { color: var(--shu); }
.reasons .txt { flex: 1; font-size: 15px; line-height: 1.55; overflow-wrap: anywhere; }
.reasons .own { font-size: 11px; color: var(--sub); }
.flower { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 4px 9px; font-size: 13px; white-space: nowrap; }
.flower.on { border-color: var(--shu); background: var(--shu-soft); }

.owner { margin-top: 14px; }
.owner .card { text-align: center; }
.owner .card p { margin: 0 0 10px; }
.owner .row { margin-top: 8px; }

.fine { font-size: 12px; color: var(--sub); line-height: 1.6; margin: 10px 0 0; }
.fine a, .legal a { color: var(--sub); }
.report-link { font-size: 12px; }
.reasons .rep { background: none; color: var(--sub); font-size: 11px; padding: 2px 0 0; text-decoration: underline; display: block; }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet { background: var(--bg); width: 100%; max-width: 480px; border-radius: 16px 16px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 92dvh; overflow-y: auto; }
.sheet h3 { margin-bottom: 4px; }
.opt { display: flex; align-items: center; gap: 10px; padding: 11px 4px; font-size: 15px; border-bottom: 1px solid var(--line); }
.opt input { width: 20px; height: 20px; flex: none; }
.sheet textarea { width: 100%; margin-top: 12px; padding: 10px; font: inherit; font-size: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--fg); }

.share-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.88); z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 16px; }
.share-overlay img { max-width: 100%; max-height: 52dvh; border-radius: 6px; }
.share-overlay p { color: #fff; font-size: 14px; text-align: center; margin: 0; line-height: 1.5; }
.share-overlay .row { width: 100%; max-width: 420px; margin-top: 4px; }
.share-overlay .secondary { text-align: center; text-decoration: none; color: var(--fg); font-size: 15px; padding: 12px 6px; }
.share-overlay .link { color: #fff; }
.share-text { width: 100%; max-width: 420px; font: inherit; font-size: 13px; padding: 8px; border-radius: 8px; border: 0; background: #fff; color: #222; }

/* Ad slots (public/ads.js). Fixed height and kept clear of buttons, so nothing shifts under a finger. */
.ad-slot { width: 300px; max-width: 100%; height: 250px; margin: 24px auto 8px; }
.ad-slot[hidden] { display: none; }
.ad-placeholder {
  position: relative; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%;
  border: 1.5px dashed var(--line); border-radius: 8px; background: var(--card); color: var(--sub); font-size: 14px;
}
.ad-label { position: absolute; top: 6px; left: 6px; padding: 1px 6px; border-radius: 4px; background: var(--sub); color: var(--bg); font-size: 11px; }

.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 20px; font-size: 14px; z-index: 20; max-width: 90vw; }
.loading { text-align: center; color: var(--sub); margin-top: 40vh; }

/* Keep the button clear of the ad above it (accidental clicks). */
#plaza-ad .big { margin-top: 24px; }
