/* 本の虫もぐ — 1画面の会話。上にもぐ、下に入力欄、右から本棚が出てくる */
:root {
  --bg: #F2F0F6;
  --surface: #FFFFFF;
  --fg: #2B2838;
  --muted: #6F6A80;
  --line: #DEDAE8;
  --lamp: #E3AE3C;
  --lamp-soft: #FBF0D6;
  --worm: #F0A3B3;
  --worm-deep: #D97C90;
  --me: #3E3A55;
  --me-fg: #F6F4FB;
  --care: #E9F1EC;
  --care-line: #9CC2AA;
  --warn: #C2554A;
  --font-display: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Yu Gothic", sans-serif;
  --font-body: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", sans-serif;
  --font-book: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1C1A25; --surface: #282534; --fg: #ECE8F4; --muted: #A8A2BA; --line: #3A3649;
    --lamp: #EDBE55; --lamp-soft: #3A3222; --worm: #F0A3B3; --worm-deep: #E58FA2;
    --me: #4B4666; --me-fg: #F6F4FB; --care: #1F2E26; --care-line: #4F7A60; --warn: #E07A70;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--fg);
  font-family: var(--font-body); font-size: 15px; line-height: 1.75;
  display: flex; justify-content: center;
  padding-top: env(safe-area-inset-top, 0px);
}
a { color: var(--worm-deep); }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--lamp); outline-offset: 2px; }

.app { width: 100%; max-width: 680px; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; padding-inline: 16px; }

header {
  display: flex; align-items: center; gap: 10px;
  padding-block: 14px 10px; border-bottom: 1px dashed var(--line);
  position: sticky; top: 0; z-index: 2; background: var(--bg);
}
.mogu-face { width: 52px; height: 52px; flex: none; }
.who { flex: 1; min-width: 0; }
.who h1 { margin: 0; font-family: var(--font-display); font-size: 1.25rem; font-weight: 700; line-height: 1.3; }
.who p { margin: 0; color: var(--muted); font-size: .8rem; }
.pill {
  font: 500 .85rem var(--font-display); background: var(--lamp-soft); border: 1px solid var(--lamp); border-radius: 999px;
  padding: 6px 12px; cursor: pointer; display: flex; align-items: center; gap: 6px; white-space: nowrap;
}
.pill.quiet { background: transparent; border-color: var(--line); }
.pill b { font-variant-numeric: tabular-nums; }

.talk { flex: 1; padding-block: 18px; display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; align-items: flex-end; }
.msg.me { justify-content: flex-end; }
.msg .mini { width: 30px; height: 30px; flex: none; }
.bubble { min-width: 0; max-width: 82%; padding: 10px 14px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.mogu .bubble { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; font-family: var(--font-display); font-weight: 500; }
.me .bubble { background: var(--me); color: var(--me-fg); border-bottom-right-radius: 6px; }
.thinking { color: var(--muted); }
.thinking span { display: inline-block; animation: hop 1.2s infinite; }
.thinking span:nth-child(2) { animation-delay: .15s; } .thinking span:nth-child(3) { animation-delay: .3s; }
@keyframes hop { 0%, 60%, 100% { transform: none; } 30% { transform: translateY(-4px); } }

.book {
  margin-left: 40px; display: grid; grid-template-columns: 54px 1fr;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.book .spine {
  background: var(--worm); color: #3A2230; writing-mode: vertical-rl; font-family: var(--font-book); font-size: .82rem;
  padding: 12px 0; display: flex; align-items: center; overflow: hidden; letter-spacing: .08em;
}
.book .body { padding: 12px 14px; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.label { font: 700 .7rem var(--font-display); letter-spacing: .12em; color: var(--worm-deep); }
.book h3 { margin: 0; font-family: var(--font-book); font-size: 1.1rem; line-height: 1.45; text-wrap: balance; }
.meta { color: var(--muted); font-size: .85rem; }
.because { margin: 6px 0 0; font-size: .85rem; color: var(--muted); }
.because q { color: var(--fg); quotes: "「" "」"; }
.why { margin: 2px 0 0; font-size: .92rem; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.chip {
  font: 500 .8rem var(--font-display); border-radius: 999px; padding: 5px 12px; cursor: pointer;
  border: 1px solid var(--line); background: transparent; text-decoration: none; color: var(--fg); white-space: nowrap;
}
.chip.on { background: var(--lamp-soft); border-color: var(--lamp); }
.chip.warn { border-color: var(--warn); color: var(--warn); }
.starters { display: flex; flex-wrap: wrap; gap: 8px; margin-left: 40px; }

.care { margin-left: 40px; background: var(--care); border: 1px solid var(--care-line); border-radius: 10px; padding: 12px 14px; }
.care p { margin: 0 0 6px; }
.care-title { font: 700 .95rem var(--font-display); }
.small { font-size: .78rem; color: var(--muted); }

.bottom { position: sticky; bottom: 0; z-index: 2; background: var(--bg); padding-bottom: env(safe-area-inset-bottom, 0px); }
.composer { padding-block: 10px 6px; border-top: 1px dashed var(--line); display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; font-size: 16px; line-height: 1.6;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; max-height: 140px;
}
.send { flex: none; height: 44px; padding: 0 18px; border-radius: 999px; border: none; cursor: pointer; background: var(--lamp); color: #2B2410; font: 700 .95rem var(--font-display); }
.send:disabled { opacity: .45; cursor: default; }
.note { font-size: .74rem; color: var(--muted); text-align: center; margin: 0; padding-bottom: 6px; }
.turnstile { display: flex; justify-content: center; padding-bottom: 8px; }

.scrim { position: fixed; inset: 0; background: rgba(20,16,40,.35); z-index: 4; }
.drawer {
  position: fixed; inset: 0 0 0 auto; width: min(380px, 92vw); background: var(--surface); border-left: 1px solid var(--line);
  padding: calc(16px + env(safe-area-inset-top, 0px)) 16px calc(16px + env(safe-area-inset-bottom, 0px));
  display: flex; flex-direction: column; gap: 12px; overflow-y: auto;
  transform: translateX(105%); transition: transform .25s ease; z-index: 5;
}
.drawer.open { transform: none; }
.drawer-head { display: flex; justify-content: space-between; align-items: center; }
.drawer-head h2 { margin: 0; font: 700 1.1rem var(--font-display); }
.close { background: none; border: none; color: var(--muted); font-size: 1.4rem; cursor: pointer; line-height: 1; }
.tabs { display: flex; gap: 6px; }
.tab { flex: 1; font: 500 .85rem var(--font-display); background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 6px; cursor: pointer; }
.tab.on { background: var(--lamp-soft); border-color: var(--lamp); }
.rack { display: flex; flex-direction: column; gap: 10px; min-height: 120px; }
.rack-item { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.rack-item h4 { margin: 0; font: 600 .98rem/1.45 var(--font-book); }
.rack-item p { margin: 2px 0 0; font-size: .8rem; color: var(--muted); }
.rack-item .side { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.rack-item a { font-size: .78rem; white-space: nowrap; }
.empty { color: var(--muted); font-size: .9rem; text-align: center; padding: 24px 8px; white-space: pre-wrap; }

.transfer { border-top: 1px dashed var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.transfer h3 { margin: 0; font: 700 .95rem var(--font-display); }
.transfer p { margin: 0; font-size: .82rem; color: var(--muted); }
.code-row { display: flex; gap: 8px; align-items: center; }
.code-row code { flex: 1; min-width: 0; font-size: .95rem; letter-spacing: .06em; background: var(--bg); border-radius: 6px; padding: 6px 8px; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.code-row input { flex: 1; min-width: 0; font-size: 16px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.msg[role="status"] { min-height: 1.2em; }
.danger { margin-top: 8px; }
.danger p { color: var(--warn); margin-bottom: 6px; }
.link-btn { background: none; border: none; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: .8rem; }

.modal { position: fixed; inset: 0; z-index: 6; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(20,16,40,.35); }
.modal-body { background: var(--surface); border-radius: 14px; max-width: 520px; width: 100%; max-height: 88vh; overflow-y: auto; padding: 16px 20px 20px; }
.modal h3 { font: 700 .95rem var(--font-display); margin: 14px 0 4px; }
.modal ul { margin: 0; padding-left: 1.2em; }
.modal li, .modal p { font-size: .9rem; }

.eye { transform-origin: center; transform-box: fill-box; animation: blink 5s infinite; }
.mogu-face .body-g { transform-origin: 50% 90%; transform-box: fill-box; animation: sway 4s ease-in-out infinite; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
@keyframes sway { 0%, 100% { transform: rotate(-3deg); } 50% { transform: rotate(3deg); } }
@media (prefers-reduced-motion: reduce) {
  .eye, .mogu-face .body-g, .thinking span { animation: none; }
  .drawer { transition: none; }
}
@media (max-width: 420px) {
  .bubble { max-width: 88%; }
  .pill { padding: 6px 10px; }
  .who p { display: none; }
}
