:root {
  --hd: #1F3A5F; --bg: #F5F1E8; --ac: #B4472F;
  --ink: #2B2723; --sub: #7A7166; --line: #E2DACB; --card: #FFFDF8;
  --mincho: "Shippori Mincho", "Hiragino Mincho ProN", "Hiragino Mincho Pro", "Yu Mincho", "YuMincho", "Noto Serif JP", serif;
  --gothic: "Zen Kaku Gothic New", "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Noto Sans JP", system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--gothic); }
/* 画面の一番上（ステータスバーの裏）を藍色にして、iPhone の上端のぼかしが白く見えないようにする */
html { background: linear-gradient(var(--hd) 0 50%, var(--bg) 50% 100%) fixed; }
body { min-height: 100vh; padding-bottom: calc(96px + env(safe-area-inset-bottom)); -webkit-text-size-adjust: 100%; }
body.lock { overflow: hidden; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; padding: 0; }
input, textarea { font: inherit; font-size: 16px; color: inherit; }
[hidden] { display: none !important; }

/* ヘッダー */
.top { position: sticky; top: 0; z-index: 10; background: var(--hd); color: #fff;
  padding: calc(env(safe-area-inset-top) + 6px) 16px 0; }
.bar { display: flex; align-items: center; justify-content: space-between; height: 32px; }
.brand { margin: 0; font-family: var(--mincho); font-size: 17px; font-weight: 600; letter-spacing: .08em; }
.brand small { font-size: 11px; margin-left: 6px; opacity: .75; letter-spacing: .12em; font-weight: 400; }
.help-btn { width: 30px; height: 30px; border-radius: 50%; border: 1px solid rgba(255,255,255,.45); font-size: 14px; }
.bar-btns { display: flex; gap: 8px; align-items: center; }
.dict-btn { height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid rgba(255,255,255,.45); font-size: 13px; letter-spacing: .1em; }

/* 用語辞典 */
.dict-top { position: sticky; top: calc(-1 * env(safe-area-inset-top)); z-index: 3; background: var(--bg); padding-top: env(safe-area-inset-top); margin-top: calc(-1 * env(safe-area-inset-top)); }
.dict-top .page-head { position: static; }
.dict-search { padding: 0 16px; max-width: 640px; margin: 0 auto; }
.dict-search input { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; background: #fff; outline: none; -webkit-appearance: none; appearance: none; }
.dict-search input:focus { border-color: var(--hd); }
.dict-cats { display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px; scrollbar-width: none; max-width: 640px; margin: 0 auto; border-bottom: 1px solid var(--line); }
.dict-cats::-webkit-scrollbar { display: none; }
.dict-cats button { flex: none; padding: 5px 12px; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-size: 12px; color: var(--hd); }
.gl { margin: 0; }
.gl dt { font-family: var(--mincho); font-weight: 600; font-size: 16px; margin-top: 14px; color: var(--ink); }
.gl dt small { font-family: var(--gothic); font-weight: 400; font-size: 11px; color: var(--sub); margin-left: 8px; }
.gl dd { margin: 3px 0 0; font-size: 14px; line-height: 1.75; color: #3E3832; }
.gl mark { background: #F8E1D8; color: inherit; border-radius: 2px; }
.dict-note { font-size: 12px; color: var(--sub); margin-top: 24px; padding-top: 12px; border-top: 1px solid var(--line); }
.search { margin-top: 8px; }
.search input { width: 100%; height: 38px; border: 0; border-radius: 10px; padding: 0 12px 0 34px; color: #fff;
  -webkit-appearance: none; appearance: none; outline: none;
  background: rgba(255,255,255,.14) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23ffffff' stroke-opacity='.7' stroke-width='2'%3E%3Ccircle cx='7' cy='7' r='5'/%3E%3Cpath d='m11 11 4 4'/%3E%3C/svg%3E") 11px center no-repeat; }
.search input::placeholder { color: rgba(255,255,255,.6); }
.years { display: flex; gap: 2px; overflow-x: auto; padding-top: 6px; scrollbar-width: none; }
.years::-webkit-scrollbar { display: none; }
.years button { flex: none; padding: 8px 14px 10px; font-size: 14px; color: rgba(255,255,255,.62); border-bottom: 3px solid transparent; }
.years button.on { color: #fff; border-color: var(--ac); font-weight: 700; }

/* 一覧 */
.month { padding: 18px 16px 6px; font-family: var(--mincho); font-size: 14px; color: var(--sub); letter-spacing: .08em; }
.item { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 11px 16px;
  background: var(--card); border-bottom: 1px solid var(--line); }
.item:first-of-type, .month + .item { border-top: 1px solid var(--line); }
.item:active { background: #F3EDE1; }
.item .d { width: 38px; flex: none; text-align: center; line-height: 1.1; }
.item .d b { display: block; font-family: var(--mincho); font-size: 21px; font-weight: 600; }
.item .d span { font-size: 11px; color: var(--sub); }
.item .main { flex: 1; min-width: 0; }
.item .name { font-family: var(--mincho); font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta { display: flex; gap: 6px; align-items: center; margin-top: 4px; font-size: 12px; color: var(--sub); min-width: 0; }
.item .meta .mk { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .meta .n { flex: none; }
.chip { flex: none; font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--tbg); color: var(--tfg); font-weight: 700; }
.hrt { color: var(--ac); font-size: 14px; flex: none; }
.thumb { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; flex: none; background: var(--line); }
.empty { padding: 56px 28px; text-align: center; color: var(--sub); line-height: 1.9; font-size: 14px; }
.empty b { display: block; font-family: var(--mincho); font-size: 18px; color: var(--ink); margin-bottom: 6px; }

/* ホーム画面追加の案内 */
.tip { margin: 12px 12px 0; padding: 14px 16px; border-radius: 12px; background: #fff; border: 1px solid var(--line); font-size: 13px; line-height: 1.75; position: relative; }
.tip b { display: block; font-size: 14px; margin-bottom: 4px; color: var(--hd); }
.tip .warn { color: var(--ac); }
.tip .tip-x { position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; color: var(--sub); font-size: 18px; }
.tip .install { margin-top: 8px; padding: 8px 16px; border-radius: 8px; background: var(--hd); color: #fff; font-weight: 700; }

/* バックアップのお知らせ */
.nudge { margin: 12px 12px 0; padding: 12px 14px; border-radius: 12px; background: #FBEFEA; border: 1px solid #EBC9BD; font-size: 13px; line-height: 1.6; }
.nudge b { display: block; color: var(--ac); font-size: 14px; }
.nudge .acts { display: flex; gap: 8px; margin-top: 8px; }
.nudge .acts button { flex: 1; height: 38px; border-radius: 8px; font-size: 14px; font-weight: 700; }
.nudge .go { background: var(--ac); color: #fff; }
.nudge .later { background: #fff; color: var(--sub); border: 1px solid var(--line); font-weight: 400 !important; }

/* 記録するボタン */
.fab { position: fixed; z-index: 20; left: 16px; right: 16px; bottom: calc(14px + env(safe-area-inset-bottom));
  height: 54px; border-radius: 14px; background: var(--ac); color: #fff; font-size: 17px; font-weight: 700; letter-spacing: .2em;
  box-shadow: 0 6px 18px rgba(120,40,20,.28); max-width: 560px; margin: 0 auto; }
.fab:active { transform: translateY(1px); }

/* シート */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(20,18,15,.45); opacity: 0; pointer-events: none; transition: opacity .2s; }
.overlay.open { opacity: 1; pointer-events: auto; }
.sheet { position: absolute; left: 0; right: 0; bottom: 0; max-height: 94vh; max-height: 94dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--bg); border-radius: 18px 18px 0 0; padding: 0 16px calc(28px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .26s ease; max-width: 640px; margin: 0 auto; overscroll-behavior: contain; }
.overlay.open .sheet { transform: none; }
.sheet-head, .page-head { position: sticky; top: 0; z-index: 3; background: var(--bg); display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px 0 8px; }
.sheet-head h2, .page-head h2 { margin: 0; font-size: 16px; font-family: var(--mincho); letter-spacing: .1em; }
.sheet-head .hint { justify-self: end; font-size: 11px; color: var(--sub); grid-column: 2 / 4; }
.link { justify-self: start; color: var(--hd); font-size: 15px; padding: 6px 2px; }

.f { margin-top: 16px; }
.lbl { display: block; font-size: 12px; color: var(--sub); margin-bottom: 6px; letter-spacing: .06em; }
.lbl em { font-style: normal; margin-left: 6px; color: var(--ink); font-weight: 700; }
.in { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 0 12px; outline: none; -webkit-appearance: none; appearance: none; }
.in:focus { border-color: var(--hd); }
input[type=date].in { display: flex; align-items: center; text-align: left; }
input[type=date].in::-webkit-date-and-time-value { text-align: left; }
textarea.in { padding: 10px 12px; line-height: 1.65; resize: vertical; min-height: 104px; }
.name-row { display: flex; gap: 8px; }
.in.nm { font-family: var(--mincho); font-size: 19px; font-weight: 600; }
.heart-btn { flex: none; width: 46px; height: 46px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 22px; color: #BDB2A2; }
.heart-btn.on { color: var(--ac); border-color: var(--ac); }
.types { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 8px; }
.type { border-radius: 10px; padding: 9px 6px; text-align: center; background: var(--tbg); color: var(--tfg); border: 2px solid transparent; }
.type b { display: block; font-family: var(--mincho); font-size: 16px; }
.type span { font-size: 11px; }
.type.on { border-color: var(--tfg); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.type.on b::before { content: "✓ "; }
.suggest { margin-top: 6px; background: #fff; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.suggest button { display: block; width: 100%; text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.suggest button:last-child { border-bottom: 0; }
.suggest b { font-family: var(--mincho); font-size: 16px; }
.suggest span { display: block; font-size: 12px; color: var(--sub); margin-top: 2px; }
.suggest .cap { padding: 6px 12px; font-size: 11px; color: var(--sub); background: #FAF7F0; }
.note { margin-top: 8px; padding: 8px 12px; border-radius: 8px; background: #FBEDE8; color: var(--ac); font-size: 13px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.note button { color: var(--sub); font-size: 12px; text-decoration: underline; flex: none; }
.ph-add { width: 100%; height: 64px; border: 1.5px dashed #CFC5B4; border-radius: 10px; color: var(--sub); font-size: 14px; background: rgba(255,255,255,.5); }
.ph { position: relative; }
.ph img { display: block; width: 100%; max-height: 320px; object-fit: cover; border-radius: 12px; background: var(--line); }
.ph-x { position: absolute; top: 8px; right: 8px; width: 34px; height: 34px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; font-size: 18px; }
.ph-acts { display: flex; gap: 8px; margin-top: 8px; }
.ph-acts button { flex: 1; height: 38px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font-size: 13px; color: var(--sub); }
.save { width: 100%; height: 54px; margin-top: 24px; border-radius: 14px; background: var(--ac); color: #fff; font-size: 17px; font-weight: 700; letter-spacing: .3em; }

.status { margin: 0; font-size: 12px; color: var(--sub); text-align: center; min-height: 1.4em; }

/* 写真の調整 */
.overlay.crop { z-index: 80; background: #111; }
.crop-box { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; color: #fff;
  padding: calc(env(safe-area-inset-top) + 8px) 16px calc(env(safe-area-inset-bottom) + 16px); }
.crop-head { width: 100%; max-width: 480px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; height: 48px; }
.crop-head h2 { margin: 0; font-size: 16px; font-family: var(--mincho); letter-spacing: .1em; }
.crop-link { color: #fff; font-size: 16px; padding: 8px 4px; justify-self: start; }
.crop-link.ok { justify-self: end; color: #F2B9A8; font-weight: 700; }
.crop-stage { flex: 1; display: flex; align-items: center; justify-content: center; width: 100%; }
#cropCanvas { width: min(calc(100vw - 32px), 480px); aspect-ratio: 1 / 1; touch-action: none; border-radius: 6px; box-shadow: 0 0 0 1px rgba(255,255,255,.35); cursor: grab; }
.crop-hint { margin: 10px 0 4px; font-size: 12px; color: rgba(255,255,255,.6); }
.crop-tools { width: 100%; max-width: 480px; display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.crop-tools button { width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.12); color: #fff; font-size: 22px; flex: none; }
.crop-tools button.wide { flex: 1; width: auto; border-radius: 12px; font-size: 15px; }
.crop-tools input[type=range] { flex: 1; accent-color: #F2B9A8; }

/* 確認画面：枠を見せずタップで編集 */
.ed { border-color: transparent; background: transparent; padding-left: 4px; }
.ed:focus { background: #fff; border-color: var(--hd); padding-left: 12px; }
textarea.ed { background: rgba(255,255,255,.55); border-color: var(--line); padding-left: 12px; }
.dates { display: flex; flex-wrap: wrap; gap: 8px; }
.dchip { display: inline-flex; align-items: center; height: 38px; background: #fff; border: 1px solid var(--line); border-radius: 999px; font-size: 14px; overflow: hidden; }
.dchip label { position: relative; display: inline-flex; align-items: center; gap: 3px; height: 100%; padding: 0 4px 0 14px; cursor: pointer; }
.dchip label small { color: var(--sub); font-size: 11px; }
.dchip input[type=date] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; border: 0; padding: 0; -webkit-appearance: none; appearance: none; }
.dchip .x { width: 32px; height: 100%; color: #A89D8D; font-size: 15px; }
.dchip.add { border-style: dashed; border-color: #D6A397; color: var(--ac); }
.dchip.add label { padding: 0 14px; font-weight: 700; }
.danger { display: block; margin: 32px auto 4px; color: #A33; font-size: 13px; text-decoration: underline; padding: 8px; }

/* 使い方ページ */
.page { position: fixed; inset: 0; z-index: 60; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch;
  transform: translateX(100%); transition: transform .26s ease; padding: env(safe-area-inset-top) 0 calc(32px + env(safe-area-inset-bottom)); }
.page.open { transform: none; }
.page-head { padding-left: 16px; padding-right: 16px; }
.page-body { padding: 0 16px; max-width: 640px; margin: 0 auto; font-size: 14px; line-height: 1.85; }
.page-body h3 { font-family: var(--mincho); font-size: 17px; margin: 28px 0 8px; padding-bottom: 6px; border-bottom: 2px solid var(--hd); color: var(--hd); }
.page-body h4 { font-size: 14px; margin: 16px 0 4px; }
.page-body p, .page-body ol, .page-body ul { margin: 4px 0; }
.page-body ol, .page-body ul { padding-left: 1.4em; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-top: 10px; }
.btn { display: block; width: 100%; height: 48px; border-radius: 12px; font-weight: 700; font-size: 15px; margin-top: 8px; }
.btn.pri { background: var(--hd); color: #fff; }
.btn.sec { background: #fff; color: var(--hd); border: 1px solid var(--hd); }
.btn.ghost { background: transparent; color: var(--sub); border: 1px dashed #C9BFB0; height: 42px; font-weight: 400; font-size: 13px; }
.last { font-size: 12px; color: var(--sub); text-align: center; margin-top: 8px; }
.prep { margin-top: 8px; padding: 10px 12px; border-radius: 10px; background: #EEF2F7; }
.prep-msg { margin: 0; font-size: 13px; color: var(--hd); text-align: center; }
.btn:disabled { opacity: .5; }
span.thumb { display: block; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 6px; background: #fff; }
.tbl th, .tbl td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.tbl th { background: #FAF7F0; white-space: nowrap; font-weight: 700; }
.small { font-size: 12px; color: var(--sub); }
.foot { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--sub); text-align: center; }

/* ホーム画面から開いたアプリでは、iPhone が画面上端にぼかしを重ねるため、
   タイトルや見出しがその範囲にかからないよう上の余白を広げる */
@media (display-mode: standalone) {
  .top { padding-top: calc(env(safe-area-inset-top) + 30px); }
  .page { padding-top: calc(env(safe-area-inset-top) + 24px); }
  .dict-top { padding-top: calc(env(safe-area-inset-top) + 24px); }
}

/* トースト */
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 100; transform: translate(-50%, 16px);
  background: rgba(30,28,25,.9); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
