:root {
  --navy: #142230;
  --navy-2: #1e3246;
  --red: #d8262f;
  --bg: #f3f4f6;
  --card: #ffffff;
  --line: #e2e5ea;
  --text: #1b2430;
  --muted: #6b7684;
  --mine: #fff3f3;
  --read: #1f7a4d;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { overscroll-behavior-y: none; }
a { color: #1a5fb4; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.icon { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.app { min-height: 100%; display: flex; flex-direction: column; max-width: 760px; margin: 0 auto; background: var(--bg); }
.loading { margin: 40vh auto 0; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.block { display: block; }

/* 上の帯 */
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px; min-height: calc(56px + var(--safe-top));
  padding: var(--safe-top) 6px 0; background: var(--navy); color: #fff; }
.bar-title { flex: 1; min-width: 0; padding: 0 4px; }
.bar-title h1 { margin: 0; font-size: 1.08rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title p { margin: 0; font-size: .75rem; opacity: .75; }
.bar-button { display: inline-grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent; color: #fff; text-decoration: none; }
.bar-button:active { background: rgba(255,255,255,.12); }
.brand-dot { width: 14px; height: 14px; margin: 0 6px 0 12px; border-radius: 50%; background: var(--red); box-shadow: 0 0 0 4px rgba(216,38,47,.25); }

/* 入口 */
.entry { flex: 1; display: flex; flex-direction: column; gap: 18px; padding: calc(40px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  background: linear-gradient(180deg, var(--navy) 0 calc(190px + var(--safe-top)), var(--bg) calc(190px + var(--safe-top))); }
.entry > .logo { margin-bottom: 18px; }
.logo { display: flex; align-items: center; gap: 14px; color: #fff; }
.logo img { border-radius: 18px; box-shadow: 0 6px 18px rgba(0,0,0,.3); }
.logo strong { display: block; font-size: 1.35rem; letter-spacing: .02em; }
.logo span { font-size: .85rem; opacity: .8; }
.notice { margin: 0; padding: 10px 14px; border-radius: 10px; background: #fff7e0; color: #6b4b00; font-size: .92rem; }
.hint { margin: 0; color: var(--muted); font-size: .88rem; text-align: center; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-size: .9rem; font-weight: 600; }
input:not([type=checkbox]), select, textarea { width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid #cfd5dd; border-radius: 10px; background: #fff; font-size: 16px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #3d7bd9; outline-offset: 0; border-color: transparent; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 46px; padding: 10px 18px; border-radius: 12px; border: 1px solid transparent; font-weight: 700; text-decoration: none; }
.button.primary { background: var(--red); color: #fff; }
.button.primary:active { background: #b81e26; }
.button.ghost { background: #fff; border-color: #cfd5dd; color: var(--text); }
.button.danger { background: #fff; border-color: #e7a1a5; color: #b3121b; }
.button.small { min-height: 36px; padding: 6px 12px; font-size: .88rem; }
.button.wide { width: 100%; }
.button:disabled { opacity: .55; }
.buttons { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; margin-top: 12px; }
.buttons.column { flex-direction: column; align-items: stretch; }

/* 一覧 */
.page { display: grid; gap: 14px; padding: 14px 12px calc(28px + var(--safe-bottom)); align-content: start; }
.rooms { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.rooms li + li { border-top: 1px solid var(--line); }
.room-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 14px; border: 0; background: none; text-align: left; color: inherit; text-decoration: none; }
.room-row:active { background: #f1f3f6; }
.room-text { flex: 1; min-width: 0; display: grid; }
.room-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-name small { font-weight: 500; color: var(--muted); font-size: .72rem; }
.room-last { color: var(--muted); font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-row.unread .room-last { color: var(--text); }
.room-meta { display: grid; justify-items: end; gap: 4px; color: var(--muted); font-size: .75rem; }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--red); color: #fff; font-size: .75rem; font-weight: 700; line-height: 22px; text-align: center; }
.empty { padding: 28px 16px; color: var(--muted); text-align: center; list-style: none; }
.avatar { flex: none; display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: hsl(var(--hue, 210) 45% 46%); color: #fff; font-weight: 700; font-size: 1rem; }
.avatar.group { border-radius: 12px; background: var(--navy-2); }
.hint-card p { margin: 6px 0 10px; color: var(--muted); font-size: .9rem; }

/* ルーム */
.room-screen { display: flex; flex-direction: column; height: 100dvh; }
.scroller { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 8px 10px 12px; background: var(--bg); }
.more { display: block; margin: 6px auto 10px; }
.day { display: flex; justify-content: center; margin: 14px 0 8px; }
.day span { padding: 3px 12px; border-radius: 12px; background: #e3e7ec; color: #4b5563; font-size: .75rem; }
.message { display: flex; gap: 10px; padding: 8px 8px 4px; border-radius: 12px; }
.message.continued { padding-top: 0; }
.message.mine { background: var(--mine); }
.message.mine + .message.mine.continued { border-top-left-radius: 0; border-top-right-radius: 0; }
.avatar-space { flex: none; width: 40px; }
.message-main { flex: 1; min-width: 0; }
.message-head { display: flex; align-items: baseline; gap: 8px; }
.message-head strong { font-size: .92rem; }
.message-head time, .message-foot time { color: var(--muted); font-size: .72rem; }
.message-body { margin: 2px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; min-height: 6px; }
.receipt { border: 0; background: none; padding: 2px 4px; color: var(--muted); font-size: .72rem; }
.receipt.read { color: var(--read); font-weight: 700; }
.photos { display: grid; gap: 4px; margin-top: 6px; max-width: 420px; }
.photos.n1 { grid-template-columns: 1fr; }
.photos.n2, .photos.n4 { grid-template-columns: 1fr 1fr; }
.photos.n3 { grid-template-columns: 1fr 1fr 1fr; }
.photo { padding: 0; border: 0; border-radius: 10px; overflow: hidden; background: #dfe3e8; aspect-ratio: 1; }
.photos.n1 .photo { aspect-ratio: auto; max-height: 360px; }
.photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.photos.n1 .photo img { height: auto; max-height: 360px; }

.tray { display: flex; gap: 8px; overflow-x: auto; padding: 8px 10px; background: #fff; border-top: 1px solid var(--line); }
.tray-item { position: relative; flex: none; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; background: #dfe3e8; }
.tray-item img { width: 100%; height: 100%; object-fit: cover; }
.tray-item.uploading img { opacity: .45; }
.tray-item.uploading::after { content: ""; position: absolute; inset: 22px; border: 3px solid #fff; border-top-color: var(--red); border-radius: 50%; animation: spin .8s linear infinite; }
.tray-item button { position: absolute; top: 2px; right: 2px; display: grid; place-items: center; width: 22px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; }
.tray-item button .icon { width: 14px; height: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(8px + var(--safe-bottom)); background: #fff; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; min-height: 44px; max-height: 160px; resize: none; border-radius: 22px; padding: 10px 14px; line-height: 1.4; }
.attach, .send { flex: none; display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: transparent; color: var(--navy); }
.send { background: var(--red); color: #fff; }
.send .icon { width: 20px; height: 20px; }
.send:disabled { opacity: .5; }

/* 写真の拡大 */
.viewer { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.94); display: flex; flex-direction: column; }
.viewer[hidden] { display: none; }
.viewer-bar { display: flex; align-items: center; gap: 12px; padding: calc(8px + var(--safe-top)) 10px 8px 16px; color: #fff; }
.viewer-bar span { flex: 1; font-size: .9rem; }
.viewer-bar a { color: #fff; font-size: .85rem; }
.viewer-bar button, .viewer-prev, .viewer-next { display: grid; place-items: center; width: 44px; height: 44px; border: 0; border-radius: 50%; background: rgba(255,255,255,.14); color: #fff; }
.viewer-stage { flex: 1; display: grid; place-items: center; min-height: 0; padding: 0 0 var(--safe-bottom); }
.viewer-stage img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-prev, .viewer-next { position: absolute; top: 50%; }
.viewer-prev { left: 8px; }
.viewer-next { right: 8px; }

/* ダイアログ */
dialog { width: min(440px, calc(100% - 24px)); max-height: calc(100dvh - 40px); padding: 0; border: 0; border-radius: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10,18,28,.55); }
.dialog-body { padding: 18px; overflow-y: auto; }
.dialog-body h2 { margin: 0 0 12px; font-size: 1.1rem; }
.dialog-body h3 { margin: 14px 0 6px; font-size: .9rem; color: var(--muted); }
.people-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.people-list li { display: flex; align-items: center; gap: 10px; }
.people-list .avatar { width: 32px; height: 32px; font-size: .85rem; }
.people-list.muted .avatar { filter: grayscale(1) opacity(.6); }
.qr { display: grid; place-items: center; padding: 10px; background: #fff; }
.qr svg { width: min(260px, 70vw); height: auto; }
.url { font-size: .8rem !important; margin-top: 8px; }

/* 設定・管理 */
.card h2 { margin: 0 0 8px; font-size: 1.05rem; }
.card h3 { margin: 16px 0 6px; font-size: .88rem; color: var(--muted); }
.card > p.muted { margin: 0 0 12px; font-size: .9rem; }
.me { display: flex; align-items: center; gap: 12px; }
.me p { margin: 0; font-size: .88rem; }
.setting + .setting { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line); }
.setting p { margin: 6px 0 10px; font-size: .88rem; }
.switch { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.switch input { width: 22px; height: 22px; accent-color: var(--red); }
.quiet { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.quiet select { width: auto; min-width: 96px; }
.link-card { display: flex; align-items: center; justify-content: space-between; color: inherit; text-decoration: none; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.row-person { display: flex; align-items: center; gap: 10px; min-width: 0; }
.row-person .muted { overflow-wrap: anywhere; font-size: .78rem; }
.tag { margin-left: 6px; padding: 1px 7px; border-radius: 8px; background: #e8eef7; color: #24496e; font-size: .7rem; font-weight: 700; }
.tag.off { background: #fbe7e8; color: #9d1a21; }
.checks { display: grid; gap: 8px; margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.checks legend { padding: 0 4px; font-size: .88rem; font-weight: 600; }
.checks label { display: flex; align-items: center; gap: 10px; font-weight: 500; }
.checks input { width: 20px; height: 20px; accent-color: var(--red); }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); z-index: 60; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px;
  background: #1f2a37; color: #fff; font-size: .9rem; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #a3131b; }

@media (min-width: 761px) {
  .app { border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
}
.dialog-body > .button { margin-top: 14px; }
