:root {
  --bg: #170a10;
  --bg-deep: #13080d;
  --ink: #fbefe9;
  --muted: #d0aab3;
  --muted-2: #b9949e;
  --accent: #ffbccb;
  --wine: #b8325c;
  --wine-deep: #8a1f48;
  --line: rgba(255, 188, 203, 0.18);
  --soft: rgba(251, 239, 233, 0.06);
  --danger: #ff9fb2;
  --sans: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', 'Hiragino Sans', sans-serif;
  --mincho: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', sans-serif;
  --script: 'Zen Maru Gothic', 'Hiragino Maru Gothic ProN', sans-serif;
  color-scheme: dark;
}

* { 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(--accent); 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: -40px; width: 480px; height: 480px; margin-left: -240px; border-radius: 50%; background: radial-gradient(closest-side, rgba(214, 60, 107, 0.5), rgba(214, 60, 107, 0)); pointer-events: none; }
.script { margin: 0; font-family: var(--script); font-weight: 700; font-size: 28px; 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.16em; }
.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: var(--soft); 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: transparent; color: var(--accent); font-size: 14px; letter-spacing: 0.06em; }
.btn.wide { width: 100%; max-width: 300px; }
.btn.primary { border: none; color: #fff5f2; background: radial-gradient(circle at 35% 30%, #e0577f, #a52a55 80%); box-shadow: 0 0 18px rgba(224, 87, 127, 0.45); }
.btn.primary:disabled { opacity: 0.4; box-shadow: none; }
.btn.danger { border-color: rgba(255, 122, 156, 0.45); color: var(--danger); }
.code { display: block; max-width: 340px; padding: 14px 16px; border-radius: 14px; background: var(--soft); 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: #e0577f; }

/* ---------- ロック画面 ---------- */
.screen.lock { align-items: center; padding-top: 110px; gap: 30px; background: var(--bg-deep); }
.dots { display: flex; gap: 20px; height: 20px; align-items: center; }
.dot { width: 11px; height: 11px; border-radius: 50%; border: 1px solid rgba(255, 188, 203, 0.45); }
.dot.on { border: none; background: #ff7a9c; box-shadow: 0 0 12px rgba(255, 122, 156, 0.8); }
.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 rgba(255, 188, 203, 0.12); background: rgba(251, 239, 233, 0.035); color: var(--ink); font-family: var(--sans); font-size: 26px; font-weight: 500; }
.key:active { background: rgba(224, 87, 127, 0.35); }
.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 > :not(.glow) { position: relative; }
.glow.a { left: -120px; top: -80px; margin: 0; width: 420px; height: 420px; background: radial-gradient(closest-side, rgba(214, 60, 107, 0.55), rgba(214, 60, 107, 0)); }
.glow.b { left: auto; right: -140px; top: auto; bottom: 120px; margin: 0; width: 380px; height: 380px; background: radial-gradient(closest-side, rgba(255, 170, 140, 0.16), rgba(255, 170, 140, 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%, #ff8fab, #b8325c 70%); box-shadow: 0 0 18px rgba(255, 143, 171, 0.45); }
.who-text { display: flex; flex-direction: column; min-width: 0; }
.peer { font-family: var(--mincho); font-size: 19px; font-weight: 700; 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: 12px; letter-spacing: 0.06em; color: var(--muted); }
.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(--accent); display: inline-flex; align-items: center; justify-content: center; }
.icon-btn.round { border: 1px solid rgba(255, 188, 203, 0.22); background: rgba(23, 10, 16, 0.5); flex: none; }
.pill { display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid rgba(255, 188, 203, 0.28); background: rgba(23, 10, 16, 0.4); 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: var(--soft); border: 1px solid rgba(255, 188, 203, 0.14); color: var(--accent); text-decoration: none; -webkit-touch-callout: default; }
.folder-name { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; letter-spacing: 0.14em; }
.folder-hint { font-size: 10px; color: var(--muted); text-align: right; }
.warn { margin: 8px 14px 0; padding: 10px 14px; border-radius: 14px; background: rgba(224, 87, 127, 0.18); border: 1px solid rgba(255, 122, 156, 0.35); 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(251, 239, 233, 0.07); border: 1px solid rgba(251, 239, 233, 0.06); 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, var(--wine), var(--wine-deep)); box-shadow: 0 6px 22px rgba(184, 50, 92, 0.35); }
.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 rgba(251, 239, 233, 0.08); background: radial-gradient(circle at 70% 30%, rgba(255, 170, 140, 0.3), rgba(90, 24, 50, 0.9) 70%); 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 rgba(255, 188, 203, 0.2); background: rgba(251, 239, 233, 0.05); color: var(--ink); font-size: 16px; line-height: 1.5; resize: none; }
.input::placeholder { color: var(--muted-2); }
.send { flex: none; width: 44px; height: 44px; border-radius: 22px; border: none; color: #fff5f2; background: radial-gradient(circle at 35% 30%, #e0577f, #a52a55 75%); box-shadow: 0 0 16px rgba(224, 87, 127, 0.5); display: inline-flex; align-items: center; justify-content: center; }
.hidden-file { display: none; }

/* ---------- ダイアログ・トースト ---------- */
.layer { position: fixed; inset: 0; z-index: 20; background: rgba(12, 4, 8, 0.62); 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: linear-gradient(170deg, #2b1220, #1b0c14); border: 1px solid rgba(255, 188, 203, 0.16); box-shadow: 0 -10px 40px rgba(184, 50, 92, 0.3); max-height: 88dvh; overflow-y: auto; }
.sheet-title { margin: 0; text-align: center; font-family: var(--mincho); font-size: 19px; letter-spacing: 0.08em; }
.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: var(--soft); 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(12, 4, 8, 0.94); 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; }
.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: #2b1220; border: 1px solid var(--line); font-size: 13px; color: var(--ink); text-align: center; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5); }

/* ---------- 設定 ---------- */
.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-size: 22px; letter-spacing: 0.12em; }
.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: rgba(251, 239, 233, 0.045); border: 1px solid rgba(255, 188, 203, 0.1); }
.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(251, 239, 233, 0.1); overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 2px; background: #ff8fab; box-shadow: 0 0 10px rgba(255, 143, 171, 0.7); }
.spacer { flex: 1; min-height: 12px; }

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

/* 消されたメッセージ（持ち主の画面だけ） */
.bubble.gone { opacity: 0.45; border: 1px dashed rgba(255, 188, 203, 0.35) !important; background: transparent !important; box-shadow: none !important; }
.gone-tag { font-size: 10px; color: var(--accent); padding: 0 8px; opacity: 0.8; }

/* 入力中・オンライン表示 */
.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: #6f6a6d; }
.dot-status.on { background: #4fd68a; box-shadow: 0 0 8px rgba(79, 214, 138, 0.8); }
.log { list-style: none; margin: 0 0 8px; padding: 14px 18px; border-radius: 18px; background: rgba(251, 239, 233, 0.045); 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 rgba(255, 188, 203, 0.5); border-radius: 4px 12px 12px 4px; background: rgba(251, 239, 233, 0.05); 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: var(--soft); border-left: 3px solid rgba(255, 188, 203, 0.5); }
.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.7); } }

/* ---------- メモ帳（夜） ---------- */
.memo { min-height: 100dvh; max-width: 560px; margin: 0 auto; background: #1b1216; color: #eadfe0; 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: #a8979b; font-size: 14px; }
.memo-save { min-height: 40px; padding: 0 18px; border-radius: 20px; border: none; background: transparent; color: #ffbccb; 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(255, 188, 203, 0.3); background: #241a1f; color: #ffbccb; font-size: 13px; }
.memo-input { width: 100%; min-height: 200px; padding: 6px 4px 8px; border: none; border-top: 1px solid rgba(255, 188, 203, 0.3); border-bottom: 1px solid rgba(255, 188, 203, 0.3); background: linear-gradient(transparent 31px, rgba(255, 188, 203, 0.14) 32px) 0 0 / 100% 32px local; color: #eadfe0; font-size: 16px; line-height: 32px; resize: none; outline: none; }
.memo-input::placeholder { color: #8d7b80; }
.memo-list { display: flex; flex-direction: column; gap: 10px; }
.memo-card { padding: 12px 14px; border-radius: 14px; background: #241a1f; border: 1px solid rgba(255, 188, 203, 0.14); }
.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: #a8979b; }
.memo-del { min-height: 32px; padding: 0 8px; border: none; background: transparent; color: #a8979b; font-size: 12px; }
.memo-empty { margin: 14px 0 0; text-align: center; font-size: 13px; color: #8d7b80; }
