:root {
  --bg: #f5f2ea;
  --bg-deep: #f5f2ea;
  --ink: #2c3a30;
  --muted: #5f766e;
  --muted-2: #66807a;
  --accent: #3d8a70;
  --mint: #5fa98f;
  --mint-soft: #9dd1b9;
  --peach: #eea77c;
  --peach-soft: #f6c7a4;
  --line: rgba(60, 120, 110, 0.2);
  --soft: rgba(255, 255, 255, 0.72);
  --danger: #c0503e;
  --sans: 'Kiwi Maru', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', sans-serif;
  --mincho: 'Kiwi Maru', 'Hiragino Maru Gothic ProN', sans-serif;
  --script: 'Kiwi Maru', 'Hiragino Maru Gothic ProN', sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--sans); -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
:focus-visible { outline: 2px solid var(--mint); outline-offset: 2px; }
#root { min-height: 100dvh; }

/* ---------- 汎用 ---------- */
.screen { position: relative; min-height: 100dvh; max-width: 560px; margin: 0 auto; padding: 72px 28px 48px; display: flex; flex-direction: column; gap: 18px; overflow: hidden; }
.screen.center { align-items: center; justify-content: center; text-align: center; }
.screen > * { position: relative; }
.glow { position: absolute; left: 50%; top: -60px; width: 480px; height: 480px; margin-left: -240px; border-radius: 50%; background: radial-gradient(closest-side, rgba(246, 181, 138, 0.3), rgba(246, 181, 138, 0)); pointer-events: none; }
.script { margin: 0; font-family: var(--script); font-weight: 500; font-size: 26px; color: var(--accent); letter-spacing: 0.08em; }
.lead { margin: 0; font-size: 15px; line-height: 1.8; color: var(--ink); max-width: 320px; }
.label { margin: 0; font-family: var(--mincho); font-size: 14px; color: var(--muted); letter-spacing: 0.12em; }
.small { margin: 0; font-size: 12px; line-height: 1.7; color: var(--muted-2); }
.small.center { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 300px; margin-top: 12px; }

.field { width: 100%; max-width: 340px; min-height: 50px; padding: 12px 18px; border-radius: 25px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 16px; }
textarea.field { border-radius: 18px; resize: none; line-height: 1.6; }

.btn { min-height: 48px; padding: 0 22px; border-radius: 24px; border: 1px solid var(--line); background: #fff; color: var(--accent); font-size: 14px; letter-spacing: 0.06em; }
.btn.wide { width: 100%; max-width: 300px; }
.btn.primary { border: none; color: #fff; background: linear-gradient(135deg, var(--peach-soft), var(--peach)); box-shadow: 0 3px 12px rgba(238, 167, 124, 0.5); text-shadow: 0 1px 2px rgba(160, 90, 50, 0.35); }
.btn.primary:disabled { opacity: 0.45; box-shadow: none; }
.btn.danger { border-color: rgba(192, 80, 62, 0.4); color: var(--danger); }
.code { display: block; max-width: 340px; padding: 14px 16px; border-radius: 14px; background: #fff; border: 1px solid var(--line); font-family: ui-monospace, Menlo, monospace; font-size: 14px; line-height: 1.6; word-break: break-all; user-select: all; -webkit-user-select: all; text-align: left; }
.code.small { font-size: 11px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink); min-height: 44px; }
.check input { width: 22px; height: 22px; accent-color: var(--mint); }

/* ---------- 暗証番号の入力（登録・復元のとき） ---------- */
.screen.lock { align-items: center; padding-top: 110px; gap: 30px; }
.dots { display: flex; gap: 20px; height: 20px; align-items: center; }
.dot { width: 11px; height: 11px; border-radius: 50%; border: 1px solid rgba(60, 120, 110, 0.5); }
.dot.on { border: none; background: var(--mint); box-shadow: 0 0 10px rgba(95, 169, 143, 0.6); }
.shake { animation: shake 0.36s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; width: 100%; max-width: 264px; }
.key { height: 70px; border-radius: 35px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-family: var(--sans); font-size: 26px; font-weight: 500; }
.key:active { background: rgba(157, 209, 185, 0.5); }
.key.del { border: none; background: transparent; color: var(--muted); display: flex; align-items: center; justify-content: center; }

/* ---------- トーク画面 ---------- */
.app { position: relative; height: 100dvh; height: var(--vh, 100dvh); max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
.app::before { content: ''; position: absolute; right: 6px; bottom: 80px; width: 116px; height: 250px; background: url(/bird.jpg) -48px -136px / 234px auto no-repeat; mix-blend-mode: multiply; opacity: 0.9; pointer-events: none; -webkit-mask-image: radial-gradient(closest-side, #000 82%, transparent); mask-image: radial-gradient(closest-side, #000 82%, transparent); }
.app > :not(.glow) { position: relative; }
.glow.a { left: -120px; top: -80px; margin: 0; width: 420px; height: 420px; background: radial-gradient(closest-side, rgba(246, 181, 138, 0.22), rgba(246, 181, 138, 0)); }
.glow.b { left: auto; right: -140px; top: auto; bottom: 120px; margin: 0; width: 380px; height: 380px; background: radial-gradient(closest-side, rgba(157, 209, 185, 0.22), rgba(157, 209, 185, 0)); }

.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: max(18px, env(safe-area-inset-top)) 14px 12px 18px; }
.who { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.orb { flex: none; width: 38px; height: 38px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #8ad9c6, #5fa98f 72%); box-shadow: 0 2px 10px rgba(63, 154, 115, 0.35); }
.who-text { display: flex; flex-direction: column; min-width: 0; }
.peer { font-family: var(--mincho); font-size: 19px; font-weight: 500; letter-spacing: 0.04em; white-space: normal; overflow-wrap: anywhere; line-height: 1.3; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.tag { font-family: var(--script); font-size: 11px; letter-spacing: 0.04em; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; border: none; background: transparent; color: var(--mint); display: inline-flex; align-items: center; justify-content: center; }
.icon-btn.round { border: 1px solid var(--line); background: #fff; flex: none; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--line); background: #fff; color: var(--accent); font-size: 12px; letter-spacing: 0.04em; white-space: nowrap; }

.folder { margin: 0 14px; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 44px; padding: 0 16px; border-radius: 22px; background: #fff; border: 1px solid var(--line); color: var(--accent); text-decoration: none; -webkit-touch-callout: default; box-shadow: 0 2px 8px rgba(60, 120, 110, 0.05); }
.folder-name { flex: none; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; font-size: 13px; letter-spacing: 0.1em; }
.folder-hint { font-size: 10px; color: var(--muted); text-align: right; }
.warn { margin: 8px 14px 0; padding: 10px 14px; border-radius: 14px; background: rgba(246, 199, 164, 0.4); border: 1px solid rgba(238, 167, 124, 0.6); font-size: 12px; line-height: 1.6; color: var(--ink); }

.list { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 18px 16px 12px; display: flex; flex-direction: column; gap: 14px; -webkit-overflow-scrolling: touch; }
.day { align-self: center; font-family: var(--mincho); font-size: 11px; color: var(--muted); letter-spacing: 0.14em; padding: 4px 0; }
.empty { margin: auto; font-family: var(--script); font-size: 15px; letter-spacing: 0.1em; color: var(--muted); }
.msg { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; max-width: 76%; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.bubble { padding: 12px 16px; border-radius: 20px 20px 20px 6px; background: rgba(255, 255, 255, 0.9); border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(60, 120, 110, 0.05); font-size: 15px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine .bubble { border: none; border-radius: 20px 20px 6px 20px; background: linear-gradient(160deg, #9dd1b9, #5fa98f); color: #fff; text-shadow: 0 1px 2px rgba(30, 90, 70, 0.3); box-shadow: 0 4px 14px rgba(63, 154, 115, 0.3); }
.bubble.text[role="button"] { cursor: pointer; }
.bubble.note { font-size: 12px; color: var(--muted); background: transparent; border: 1px dashed var(--line); box-shadow: none; }
.meta { font-size: 10px; color: var(--muted-2); padding: 0 8px; }
.photo { display: block; width: 210px; min-height: 120px; max-width: 100%; border-radius: 18px; border: 1px solid var(--line); background: linear-gradient(135deg, #bfe9df, #f6dcc8); object-fit: cover; -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; cursor: zoom-in; }
.photo.broken { min-height: 60px; }

.composer { display: flex; align-items: flex-end; gap: 10px; padding: 10px 12px max(18px, env(safe-area-inset-bottom)); }
.input { flex: 1; min-width: 0; min-height: 44px; max-height: 140px; padding: 10px 18px; border-radius: 22px; border: 1px solid var(--line); background: #fff; color: var(--ink); font-size: 16px; line-height: 1.5; resize: none; }
.input::placeholder { color: #8da39c; }
.send { flex: none; width: 44px; height: 44px; border-radius: 22px; border: none; color: #fff; background: linear-gradient(135deg, var(--peach-soft), var(--peach)); box-shadow: 0 3px 12px rgba(255, 143, 107, 0.45); display: inline-flex; align-items: center; justify-content: center; }
.hidden-file { display: none; }

/* ---------- ダイアログ・トースト ---------- */
.layer { position: fixed; inset: 0; z-index: 20; background: rgba(44, 58, 48, 0.4); display: flex; align-items: flex-end; justify-content: center; padding: 16px 16px max(24px, env(safe-area-inset-bottom)); }
.sheet { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 16px; padding: 24px 20px 20px; border-radius: 28px; background: #fffdf8; border: 1px solid var(--line); box-shadow: 0 -10px 40px rgba(60, 120, 110, 0.22); max-height: 88dvh; overflow-y: auto; }
.sheet-title { margin: 0; text-align: center; font-family: var(--mincho); font-weight: 500; font-size: 19px; letter-spacing: 0.06em; }
.sheet-body { margin: 0; font-size: 14px; line-height: 1.8; color: var(--ink); }
.sheet .field { max-width: none; }
.sheet-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.sheet-actions.one { grid-template-columns: minmax(0, 1fr); }
.preview { margin: 0; padding: 13px 16px; border-radius: 16px; background: rgba(157, 209, 185, 0.2); font-size: 14px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 40dvh; overflow-y: auto; }
.preview-img { display: block; max-width: 100%; max-height: 50dvh; margin: 0 auto; border-radius: 16px; }
.viewer { position: fixed; inset: 0; z-index: 30; background: rgba(28, 38, 32, 0.92); display: flex; align-items: center; justify-content: center; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; border-radius: 12px; -webkit-touch-callout: none; user-select: none; }
.viewer .icon-btn { position: absolute; top: max(14px, env(safe-area-inset-top)); right: 14px; color: #fff; }
.toast { position: fixed; left: 50%; bottom: 96px; z-index: 40; transform: translateX(-50%); max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 22px; background: #fff; border: 1px solid var(--line); font-size: 13px; color: var(--ink); text-align: center; box-shadow: 0 8px 30px rgba(60, 120, 110, 0.25); }

/* ---------- 設定 ---------- */
.layer.full { align-items: stretch; padding: 0; background: var(--bg); }
.settings { position: relative; width: 100%; max-width: 560px; margin: 0 auto; min-height: 100%; overflow-y: auto; display: flex; flex-direction: column; gap: 22px; padding: max(18px, env(safe-area-inset-top)) 20px max(32px, env(safe-area-inset-bottom)); }
.set-head { display: flex; align-items: center; gap: 8px; }
.set-title { margin: 0; font-family: var(--mincho); font-weight: 500; font-size: 22px; letter-spacing: 0.1em; }
.group { display: flex; flex-direction: column; gap: 10px; }
.group .field { max-width: none; }
.group .btn { align-self: flex-start; }
.card { display: flex; flex-direction: column; gap: 10px; padding: 18px; border-radius: 22px; background: #fff; border: 1px solid var(--line); }
.row { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.muted { color: var(--muted); font-size: 13px; }
.bar { height: 4px; border-radius: 2px; background: rgba(60, 120, 110, 0.14); overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 2px; background: var(--peach); }
.spacer { flex: 1; min-height: 12px; }

@media (prefers-reduced-motion: reduce) { .shake { animation: none; } }

/* ---------- メモ帳（ロック画面） ---------- */
.memo { min-height: 100dvh; max-width: 560px; margin: 0 auto; background: #fbf8ef; color: #333; padding: max(14px, env(safe-area-inset-top)) 16px max(28px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 14px; }
.memo-top { display: flex; align-items: center; justify-content: space-between; padding: 6px 2px; }
.memo-title { margin: 0; font-family: var(--sans); font-weight: 500; font-size: 24px; letter-spacing: 0.04em; }
.memo-actions { display: flex; align-items: center; gap: 2px; }
.memo-clear { min-height: 40px; padding: 0 12px; border: none; background: transparent; color: #7a918a; font-size: 14px; }
.memo-save { min-height: 40px; padding: 0 18px; border-radius: 20px; border: none; background: transparent; color: var(--accent); font-size: 16px; }
.memo-field { position: relative; }
.memo-x { position: absolute; right: 4px; bottom: 6px; min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid rgba(95, 169, 143, 0.35); background: #fff; color: var(--accent); font-size: 13px; }
.memo-input { width: 100%; min-height: 200px; padding: 6px 4px 8px; border: none; border-top: 1px solid rgba(95, 169, 143, 0.35); border-bottom: 1px solid rgba(95, 169, 143, 0.35); background: linear-gradient(transparent 31px, rgba(95, 169, 143, 0.25) 32px) 0 0 / 100% 32px local; color: #333; font-size: 16px; line-height: 32px; resize: none; outline: none; }
.memo-input::placeholder { color: #9bb0a8; }
.memo-list { display: flex; flex-direction: column; gap: 10px; }
.memo-card { padding: 12px 14px; border-radius: 14px; background: #fff; border: 1px solid rgba(95, 169, 143, 0.2); box-shadow: 0 1px 4px rgba(60, 120, 110, 0.06); }
.memo-text { margin: 0 0 6px; font-size: 15px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.memo-foot { display: flex; align-items: center; justify-content: space-between; font-size: 11px; color: #7a918a; }
.memo-del { min-height: 32px; padding: 0 8px; border: none; background: transparent; color: #7a918a; font-size: 12px; }
.memo-empty { margin: 14px 0 0; text-align: center; font-size: 13px; color: #8da39c; }

/* 消されたメッセージ（持ち主の画面だけ） */
.bubble.gone { opacity: 0.55; border: 1px dashed rgba(60, 120, 110, 0.4) !important; background: transparent !important; box-shadow: none !important; color: var(--ink) !important; text-shadow: none !important; }
.gone-tag { font-size: 10px; color: var(--accent); padding: 0 8px; opacity: 0.9; }

/* 入力中・オンライン表示 */
.typing { margin: 0; padding: 0 22px 4px; font-size: 12px; color: var(--muted); letter-spacing: 0.04em; animation: breathe 1.4s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.45; } }
@media (prefers-reduced-motion: reduce) { .typing { animation: none; } }

.peer-row { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.dot-status { flex: none; width: 9px; height: 9px; border-radius: 50%; background: #b7c2bd; }
.dot-status.on { background: #3fc08a; box-shadow: 0 0 8px rgba(63, 192, 138, 0.8); }
.log { list-style: none; margin: 0 0 8px; padding: 14px 18px; border-radius: 18px; background: #fff; border: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.log li { display: flex; justify-content: space-between; gap: 12px; }

/* 返信 */
.quote { max-width: 100%; display: flex; flex-direction: column; gap: 1px; padding: 6px 12px; border-left: 3px solid var(--mint-soft); border-radius: 4px 12px 12px 4px; background: rgba(157, 209, 185, 0.22); font-size: 12px; line-height: 1.5; color: var(--muted); cursor: pointer; }
.quote.lost { cursor: default; font-style: italic; }
.quote-who { font-size: 11px; color: var(--accent); }
.quote-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; white-space: pre-wrap; }
.reply-bar { display: flex; align-items: center; gap: 8px; margin: 0 12px; padding: 8px 8px 8px 14px; border-radius: 16px; background: #fff; border: 1px solid var(--line); border-left: 3px solid var(--mint-soft); }
.reply-bar[hidden] { display: none; }
.reply-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; font-size: 12px; color: var(--muted); }
.reply-text .quote-text { -webkit-line-clamp: 1; }
.msg.flash .bubble { animation: flash 1.2s ease; }
@keyframes flash { 0%, 100% { filter: none; } 30% { filter: brightness(1.12) saturate(1.3); } }
