:root {
  --night: #1E1B3A;
  --wall: #2A2650;
  --wall-2: #34305F;
  --fluorite: #9C8CFF;
  --water: #7FE3D4;
  --paper: #ECE9FF;
  --muted: #A39FC9;
  --line: rgba(236, 233, 255, 0.12);
  --danger: #FF9FB2;
  --round: "Zen Maru Gothic", system-ui, sans-serif;
  --hand: "Klee One", "Zen Maru Gothic", serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--night);
  color: var(--paper);
  font: 400 16px/1.75 var(--round);
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100dvh;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--water); outline-offset: 2px; border-radius: 8px; }

/* 上の帯 */
.top {
  display: flex; justify-content: flex-end; gap: 4px;
  padding: max(10px, env(safe-area-inset-top)) 12px 0;
}
.tab {
  background: none; border: 0; padding: 6px 12px; border-radius: 999px;
  color: var(--muted); font-size: 14px; cursor: pointer;
}
.tab:active { background: var(--wall); }
.tab.icon { padding: 6px 8px; display: grid; place-items: center; }
.tab .count {
  display: inline-block; min-width: 1.4em; margin-left: 4px; padding: 0 5px;
  border-radius: 999px; background: var(--wall-2); color: var(--paper); font-size: 12px; line-height: 1.6;
}

/* 顔 */
.stage { display: grid; justify-items: center; padding: 0 16px 6px; }
#face { width: min(46vw, 190px); aspect-ratio: 1; transition: width .4s ease; }
body.talked #face { width: min(36vw, 140px); }
body.compact #face { width: min(26vw, 104px); }
.status { margin: 0; min-height: 1.6em; color: var(--muted); font-size: 13px; letter-spacing: .04em; }

.face { width: 100%; height: 100%; overflow: visible; }
.face .body { transform-box: fill-box; transform-origin: 50% 90%; animation: breathe 5.5s ease-in-out infinite; }
.face .halo { opacity: .55; transform-box: fill-box; transform-origin: center; transition: opacity .6s; }
.face .eyes { transform: translate(var(--lx, 0), var(--ly, 0)); transition: transform .35s ease; }
.face .eye { transform-box: fill-box; transform-origin: center; animation: blink 6s infinite; }
.face .eye:nth-child(2) { animation-delay: .04s; }
.face .mouth { transition: d .25s ease; }

.face[data-state="thinking"] .eyes { transform: translate(5px, -7px); }
.face[data-state="thinking"] .halo { animation: pulse 1.6s ease-in-out infinite; }
.face[data-state="thinking"] .body { animation-duration: 2.4s; }
.face[data-state="talking"] .halo { opacity: .85; }
.face[data-state="talking"] .mouth { transition: none; }
.face[data-state="happy"] .eye { animation: none; transform: scaleY(.35) translateY(-6px); transition: transform .3s; }
.face[data-state="happy"] .spark { opacity: 0; }

@keyframes breathe { 50% { transform: translateY(-3px) scale(1.012); } }
@keyframes blink { 0%, 95%, 100% { transform: scaleY(1); } 97% { transform: scaleY(.08); } }
@keyframes pulse { 50% { opacity: 1; transform: scale(1.06); } }

@media (prefers-reduced-motion: reduce) {
  .face .body, .face .eye, .face[data-state="thinking"] .halo { animation: none; }
}

/* 会話 */
.log {
  overflow-y: auto; padding: 8px 16px 16px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth; overscroll-behavior: contain;
}
.msg { max-width: 34em; white-space: pre-wrap; word-break: break-word; }
.msg.claude { align-self: flex-start; }
.msg.kei {
  align-self: flex-end; background: var(--wall); padding: 8px 14px;
  border-radius: 18px 18px 4px 18px; max-width: 82%;
}
.msg.error { color: var(--danger); font-size: 14px; }
.empty { margin: auto; text-align: center; color: var(--muted); font-size: 14px; }

/* 承認カード: Claudeの提案 */
.proposal {
  align-self: stretch; border: 1px dashed var(--fluorite); border-radius: 14px;
  padding: 12px 14px; background: rgba(156, 140, 255, 0.07);
}
.proposal .kind { margin: 0 0 4px; color: var(--fluorite); font-size: 13px; }
.proposal .body { margin: 0 0 10px; font-family: var(--hand); font-size: 16px; line-height: 1.8; white-space: pre-wrap; }
.proposal .why { margin: -6px 0 10px; color: var(--muted); font-size: 13px; }
.proposal .actions { display: flex; gap: 8px; }
.proposal.decided { border-style: solid; border-color: var(--line); background: none; }
.proposal.decided .actions { display: none; }
.proposal .verdict { margin: 0; font-size: 13px; color: var(--muted); }

.primary, .ghost {
  border-radius: 999px; padding: 7px 16px; cursor: pointer; font-size: 14px;
}
.primary { background: var(--fluorite); color: var(--night); border: 0; font-weight: 700; }
.ghost { background: none; border: 1px solid var(--line); }
.ghost.danger { color: var(--danger); }

/* 入力欄 */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 12px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--night);
}
.composer textarea {
  flex: 1; resize: none; max-height: 9em; background: var(--wall);
  border: 0; border-radius: 20px; padding: 9px 16px; line-height: 1.5;
}
.composer textarea::placeholder { color: var(--muted); }
.composer button {
  width: 42px; height: 42px; border-radius: 50%; border: 0; flex: none;
  background: var(--fluorite); color: var(--night); display: grid; place-items: center; cursor: pointer;
}
.composer button:disabled { opacity: .4; }

/* シート */
.sheet {
  width: 100%; max-width: 560px; max-height: 86dvh; margin: auto auto 0;
  border: 0; border-radius: 22px 22px 0 0; padding: 18px 18px max(18px, env(safe-area-inset-bottom));
  background: var(--wall); color: var(--paper); overflow-y: auto;
}
.sheet::backdrop { background: rgba(10, 8, 30, 0.6); }
.sheet[open] { animation: rise .28s ease-out; }
@keyframes rise { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; }
.sheet h2 { margin: 0; font-size: 20px; font-weight: 700; }
.close { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 14px; }

.notes { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 10px; }
.notes li { border-bottom: 1px solid var(--line); padding-bottom: 10px; }
.notes .date { display: block; color: var(--muted); font-size: 12px; }
.notes .text { white-space: pre-wrap; }
.notes .remove { background: none; border: 0; color: var(--muted); font-size: 12px; cursor: pointer; padding: 0; }
.diary-notes .text { font-family: var(--hand); font-size: 17px; line-height: 1.85; }
.notes:empty::before { content: "まだ何もありません。"; color: var(--muted); font-size: 14px; }

.letter summary { cursor: pointer; color: var(--fluorite); font-size: 14px; }
.letter-text { font-family: var(--hand); font-size: 15px; line-height: 1.9; white-space: pre-wrap; margin-top: 10px; }

.settings { display: grid; gap: 14px; }
.settings label { display: grid; gap: 4px; font-size: 14px; }
.settings input {
  background: var(--night); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
.settings small { color: var(--muted); font-size: 12px; }
.settings-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.file { display: inline-block; }
