:root {
  --bg: #eef1f4; --surface: #ffffff; --ink: #1b2430; --sub: #5d6b7a; --line: #d8dee5;
  --accent: #2f4bc0; --accent-ink: #ffffff; --mine: #2f4bc0; --mine-ink: #ffffff; --other: #ffffff;
  --err: #b3261e; --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161c; --surface: #1b212a; --ink: #e8edf3; --sub: #98a5b3; --line: #2c3541;
    --accent: #7d93ff; --accent-ink: #10162e; --mine: #4a63e0; --mine-ink: #ffffff; --other: #232b36;
    --err: #ff8a80;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.6 "Hiragino Sans", "Noto Sans JP", "Yu Gothic", "Meiryo", system-ui, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
#app { max-width: 640px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; }
.page { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
h1 { font-size: 1.5rem; margin: 8px 0 0; letter-spacing: .02em; }
h2 { font-size: 1.05rem; margin: 0 0 8px; }
p { margin: 0; }
.sub { color: var(--sub); font-size: .9rem; }
.err { color: var(--err); font-size: .9rem; min-height: 1.4em; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--sub); }
input[type=text], input[type=password], input[type=email], input[type=search] {
  font: inherit; color: var(--ink); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; width: 100%; min-height: 44px;
}
input:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
button {
  font: inherit; font-weight: 600; min-height: 44px; padding: 0 16px; border-radius: 8px; border: 0;
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
}
button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
button.link { background: none; color: var(--accent); padding: 0 4px; min-height: 36px; font-weight: 500; }
button:disabled { opacity: .5; cursor: default; }
.form { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.tabs { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.tabs button { flex: 1; border-radius: 0; background: transparent; color: var(--sub); }
.tabs button[aria-selected=true] { background: var(--accent); color: var(--accent-ink); }
.list { display: flex; flex-direction: column; }
.item {
  display: flex; justify-content: space-between; gap: 12px; align-items: center; text-align: left;
  background: none; color: var(--ink); border: 0; border-top: 1px solid var(--line); border-radius: 0;
  padding: 12px 4px; min-height: 52px; font-weight: 500; width: 100%;
}
.item:first-child { border-top: 0; }
.item .sub { font-weight: 400; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 2px 4px 2px 12px; display: flex; align-items: center; gap: 4px; font-size: .9rem; }
.chip button { min-height: 32px; padding: 0 8px; background: none; color: var(--sub); }

/* チャット画面 */
.chat { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-height: -webkit-fill-available; }
.chat-head { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 4px; background: var(--surface); border-bottom: 1px solid var(--line); }
.chat-head .title { flex: 1; min-width: 0; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
.log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.msg { display: flex; flex-direction: column; max-width: 82%; align-self: flex-start; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg .meta { font-size: .75rem; color: var(--sub); padding: 0 4px 2px; }
.bubble { background: var(--other); border: 1px solid var(--line); border-radius: 14px 14px 14px 4px; padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine .bubble { background: var(--mine); color: var(--mine-ink); border-color: var(--mine); border-radius: 14px 14px 4px 14px; }
.empty { color: var(--sub); text-align: center; margin: auto; padding: 24px; }
.compose { background: var(--surface); border-top: 1px solid var(--line); padding: 8px 12px 12px; }
.compose form { display: flex; gap: 8px; }
.compose .err { padding: 0 2px 4px; min-height: 1.3em; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); padding: 20px; width: min(92vw, 420px); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog form, dialog .body { display: flex; flex-direction: column; gap: 12px; }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: .9rem; z-index: 10; }
.toast[hidden] { display: none; }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
