:root {
  --brand-ink: #2f3d36;
  --bg: #f4f6f2;
  --leaf: #8fb89a;
  --radius: 18px;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  color: var(--brand-ink);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
}
a { color: inherit; }
.page { min-height: 100dvh; }

.brand-mark {
  font-size: 1.85rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #3a5348;
  margin: 0;
}
.brand-mini {
  margin: 0;
  font-size: 0.72rem;
  opacity: 0.55;
}

/* login */
.login-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at top left, #e7f3ec, transparent 50%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 24px;
  padding: 28px 24px;
  border: 1px solid #d7e4dc;
}
.login-card h1 { margin: 12px 0 8px; font-size: 1.35rem; }
.muted { opacity: 0.7; font-size: 0.9rem; }
.error { color: #b42318; background: #fef3f2; padding: 10px 12px; border-radius: 12px; }
.stack { display: grid; gap: 14px; margin-top: 18px; }
label { display: grid; gap: 6px; font-size: 0.88rem; }
input[type="text"], input[type="password"], textarea {
  width: 100%;
  border: 1px solid #c9d6cf;
  border-radius: 12px;
  padding: 12px;
  font: inherit;
  background: #fff;
}
.btn.primary, .send {
  border: 0;
  background: #3d5c4d;
  color: #fff;
  border-radius: 999px;
  padding: 12px 18px;
  font: inherit;
  cursor: pointer;
}

/* character select — 横並び2択（legacy / parts） */
.select-screen {
  max-width: 920px;
  margin: 0 auto;
  padding: 28px 18px 40px;
  min-height: 100dvh;
}
.select-screen--legacy {
  background:
    radial-gradient(ellipse at top left, rgba(143, 184, 154, 0.25), transparent 45%),
    radial-gradient(ellipse at top right, rgba(143, 184, 154, 0.18), transparent 40%),
    var(--bg);
}
.select-header { text-align: center; margin-bottom: 28px; }
.select-sub { margin: 8px 0 0; opacity: 0.7; }
.hello { margin-top: 14px; font-size: 0.9rem; opacity: 0.75; }
.logout { margin-left: 10px; font-size: 0.82rem; }

.character-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}
@media (max-width: 640px) {
  .character-grid { grid-template-columns: 1fr; }
}

.character-panel {
  display: block;
  text-decoration: none;
  border-radius: 28px;
  padding: 28px 18px 24px;
  min-height: 360px;
  border: 1px solid rgba(80, 110, 95, 0.12);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.character-panel:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(60, 90, 75, 0.08);
}
.character-panel.accent-companion {
  background: linear-gradient(180deg, #edf6ef 0%, #e4f0e7 100%);
}
.character-panel.accent-tutor {
  background: linear-gradient(180deg, #e8f1f6 0%, #dde8f2 100%);
}
.character-panel.accent-default {
  background: linear-gradient(180deg, #f0f2f4 0%, #e6eaee 100%);
}
.character-art {
  display: block;
  width: min(200px, 78%);
  height: auto;
  aspect-ratio: 1;
  object-fit: contain;
  margin: 8px auto 18px;
  border-radius: 18px;
}
.character-panel.accent-companion .character-art,
.character-panel.accent-tutor .character-art,
.character-panel.accent-default .character-art {
  background: transparent;
}
.character-panel h2 {
  text-align: center;
  margin: 0;
  font-size: 1.35rem;
}
.character-panel.accent-companion h2 { color: #3d5c4d; }
.character-panel.accent-tutor h2 { color: #2a4f6e; }
.character-panel.accent-default h2 { color: #4a5560; }
.character-panel hr {
  border: 0;
  border-top: 1px dashed rgba(80, 110, 95, 0.28);
  margin: 12px 24px;
}
.character-panel p {
  text-align: center;
  font-size: 0.88rem;
  line-height: 1.6;
  margin: 0 8px;
  opacity: 0.85;
}
.select-foot {
  text-align: center;
  margin-top: 28px;
  opacity: 0.65;
  font-size: 0.88rem;
}
.leaf { color: var(--leaf); }
.hello .admin-link {
  margin-right: 10px;
  color: #2a4f6e;
  text-decoration: none;
  font-size: 0.9em;
}
.hello .admin-link:hover { text-decoration: underline; }

/* profile */
.profile-screen {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(ellipse at top left, #e7f3ec, transparent 50%),
    var(--bg);
}
.profile-card {
  width: min(440px, 100%);
  background: #fff;
  border-radius: 24px;
  padding: 28px 24px;
  border: 1px solid #d7e4dc;
}
.profile-card h1 {
  margin: 8px 0 8px;
  font-size: 1.35rem;
}
.profile-card .field-hint {
  display: block;
  margin-top: 4px;
  font-size: 0.75rem;
  opacity: 0.65;
  font-weight: 400;
  line-height: 1.45;
}
.gender-field {
  border: 0;
  margin: 0;
  padding: 0;
}
.gender-field legend {
  font-size: 0.88rem;
  margin-bottom: 8px;
  padding: 0;
}
.profile-preview {
  padding: 12px 14px;
  border-radius: 14px;
  background: #f5f7f6;
  font-size: 0.9rem;
}
.profile-preview ul {
  margin: 6px 0 0;
  padding-left: 1.2em;
}
.profile-saved {
  color: #3d5c4d;
  background: #e7f3ec;
  padding: 10px 12px;
  border-radius: 12px;
}
.profile-back {
  text-align: center;
  margin: 4px 0 0;
}
.profile-back a {
  font-size: 0.9rem;
  opacity: 0.75;
}

/* character select — パーツ組み立て版 */
body:has(.select-screen--parts) {
  background: #fcfbf7;
}
.select-screen--parts {
  position: relative;
  overflow: hidden;
  max-width: 980px;
  padding: 32px 20px 48px;
  background: #fcfbf7;
}
.select-deco {
  position: absolute;
  pointer-events: none;
  z-index: 0;
  mix-blend-mode: multiply;
  opacity: 0.92;
  user-select: none;
}
.select-deco--left {
  left: -12px;
  bottom: 6%;
  width: min(160px, 28vw);
  height: auto;
  animation: select-deco-in 0.9s ease both;
}
.select-deco--right {
  right: -8px;
  top: 18%;
  width: min(150px, 26vw);
  height: auto;
  animation: select-deco-in 0.9s ease 0.12s both;
}
.select-header--parts {
  position: relative;
  z-index: 1;
  margin-bottom: 22px;
}
.select-title {
  display: block;
  width: min(420px, 78%);
  height: auto;
  margin: 0 auto 10px;
  mix-blend-mode: multiply;
  animation: select-rise 0.7s ease both;
}
.select-choice {
  display: block;
  width: min(320px, 82%);
  height: auto;
  margin: 0 auto;
  mix-blend-mode: multiply;
  animation: select-rise 0.7s ease 0.08s both;
}
.select-screen--parts .hello {
  margin-top: 16px;
  color: #5a655c;
}
.character-grid--parts {
  position: relative;
  z-index: 1;
  gap: 20px;
  align-items: stretch;
  animation: select-rise 0.75s ease 0.14s both;
}
.character-card {
  display: block;
  border-radius: 28px;
  overflow: hidden;
  text-decoration: none;
  box-shadow: 0 10px 28px rgba(70, 90, 70, 0.08);
  transition: transform 0.22s ease, box-shadow 0.22s ease;
  background: #f3f7f2;
}
.character-card:hover,
.character-card:focus-visible {
  transform: translateY(-4px);
  box-shadow: 0 16px 36px rgba(70, 90, 70, 0.14);
  outline: none;
}
.character-card-img {
  display: block;
  width: 100%;
  height: auto;
  vertical-align: middle;
}
.select-foot--parts {
  position: relative;
  z-index: 1;
  color: #6a756c;
  margin-top: 26px;
}
.select-bottom-nav {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 28px;
  padding-bottom: 8px;
}
.select-bottom-nav a {
  font-size: 0.88rem;
  color: #6a756c;
  text-decoration: none;
  opacity: 0.8;
}
.select-bottom-nav a:hover {
  opacity: 1;
  text-decoration: underline;
}
@keyframes select-rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes select-deco-in {
  from { opacity: 0; }
  to { opacity: 0.92; }
}
@media (max-width: 640px) {
  .select-deco--left { width: 110px; bottom: 2%; }
  .select-deco--right { width: 100px; top: 12%; }
  .character-grid--parts { gap: 14px; }
}

/* admin */
.admin-screen {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 18px 48px;
}
.admin-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 16px;
}
.admin-header h1 {
  margin: 4px 0 6px;
  font-size: 1.45rem;
}
.admin-nav {
  display: flex;
  gap: 14px;
  flex-shrink: 0;
}
.admin-nav a {
  text-decoration: none;
  opacity: 0.75;
  font-size: 0.92rem;
}
.admin-nav a:hover { opacity: 1; text-decoration: underline; }
.admin-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-bottom: 28px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(80, 110, 95, 0.14);
  font-size: 0.9rem;
}
.admin-toc a {
  text-decoration: none;
  color: #2a4f6e;
}
.admin-toc a:hover { text-decoration: underline; }
.admin-section {
  margin-bottom: 40px;
  scroll-margin-top: 16px;
}
.admin-section h2 {
  margin: 0 0 6px;
  font-size: 1.2rem;
}
.admin-subhead {
  margin: 22px 0 8px;
  font-size: 1rem;
}
.admin-minihead {
  margin: 14px 0 6px;
  font-size: 0.88rem;
  opacity: 0.75;
  font-weight: 600;
}
.section-note {
  margin: 0 0 10px;
  font-size: 0.82rem;
  opacity: 0.65;
}
.cost-note {
  margin: 12px 0 4px;
  font-size: 0.78rem;
  line-height: 1.55;
  opacity: 0.7;
  max-width: 52rem;
}
.token-stack {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  line-height: 1.25;
}
.token-total {
  font-variant-numeric: tabular-nums;
}
.token-detail {
  font-size: 0.72em;
  opacity: 0.55;
  white-space: nowrap;
}
.rate {
  opacity: 0.55;
  font-size: 0.92em;
}
.muted-cell { opacity: 0.35; }
.char-subtable {
  margin: 0 0 12px;
}
.char-subtable-title {
  margin: 0 0 6px;
  font-size: 0.9rem;
  font-weight: 650;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
}
.char-kind {
  font-size: 0.75rem;
  font-weight: 500;
  opacity: 0.55;
}
.char-share {
  font-size: 0.75rem;
  font-weight: 500;
  opacity: 0.65;
}
.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 14px 0 8px;
}
.summary-card {
  background: #fff;
  border: 1px solid rgba(80, 110, 95, 0.14);
  border-radius: 14px;
  padding: 14px 14px 12px;
}
.summary-card.muted-card { background: #f7f8f7; }
.summary-card h3 {
  margin: 0 0 8px;
  font-size: 0.82rem;
  opacity: 0.7;
  font-weight: 600;
}
.summary-metric { margin: 0 0 8px; }
.summary-num {
  font-size: 1.55rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.summary-list {
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.78rem;
  opacity: 0.7;
  line-height: 1.55;
}
.admin-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 720px) {
  .admin-split { grid-template-columns: 1fr; }
}
.admin-rank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}
.admin-details {
  margin: 10px 0 16px;
  border: 1px solid rgba(80, 110, 95, 0.14);
  border-radius: 14px;
  background: #fff;
  padding: 0 14px 12px;
}
.admin-details > summary {
  cursor: pointer;
  font-weight: 600;
  padding: 12px 2px;
  list-style: none;
}
.admin-details > summary::-webkit-details-marker { display: none; }
.admin-details > summary::before {
  content: "▸ ";
  opacity: 0.5;
}
.admin-details[open] > summary::before { content: "▾ "; }
.user-block { margin: 8px 0 14px; }
.user-block-title {
  margin: 0 0 6px;
  font-size: 0.92rem;
}
.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.7rem;
  background: #eceff1;
  color: #5a6570;
}
.admin-table tr.is-zero td { opacity: 0.45; }
.admin-table-wrap {
  overflow-x: auto;
  border: 1px solid rgba(80, 110, 95, 0.14);
  border-radius: 14px;
  background: #fff;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.admin-table.compact { font-size: 0.82rem; }
.admin-table th,
.admin-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid rgba(80, 110, 95, 0.1);
  white-space: nowrap;
  vertical-align: middle;
}
.admin-table.compact th,
.admin-table.compact td { padding: 8px 10px; }
.admin-table th {
  background: #f4f6f5;
  font-weight: 600;
  font-size: 0.8rem;
}
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table th.num,
.admin-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.admin-table .empty {
  text-align: center;
  opacity: 0.55;
  padding: 18px;
}

/* chat — 入力欄を下端固定。ログだけがスクロール */
html:has(body.chat-page) {
  height: 100%;
  overflow: hidden;
}
body.chat-page {
  height: var(--vvh, 100dvh);
  max-height: var(--vvh, 100dvh);
  min-height: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}
.chat-page {
  display: flex;
  flex-direction: column;
  height: var(--vvh, 100dvh);
  max-height: var(--vvh, 100dvh);
  max-width: 720px;
  margin: 0 auto;
  overflow: hidden;
  background:
    radial-gradient(ellipse at top left, rgba(143, 184, 154, 0.22), transparent 42%),
    radial-gradient(ellipse at bottom right, rgba(143, 184, 154, 0.16), transparent 40%),
    #f7f8f5;
}
.chat-page[data-character="tutor"] {
  background:
    radial-gradient(ellipse at top left, rgba(90, 140, 190, 0.14), transparent 42%),
    radial-gradient(ellipse at bottom right, rgba(90, 140, 190, 0.1), transparent 40%),
    #f5f7fa;
}
.chat-page[data-character="default"] {
  background:
    radial-gradient(ellipse at top left, rgba(120, 130, 140, 0.12), transparent 42%),
    radial-gradient(ellipse at bottom right, rgba(120, 130, 140, 0.08), transparent 40%),
    #f6f7f8;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  min-height: 56px;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid rgba(80, 110, 95, 0.12);
  backdrop-filter: blur(8px);
}
.chat-header .back {
  flex-shrink: 0;
  text-decoration: none;
  font-size: 1.15rem;
  line-height: 1;
  padding: 8px;
  opacity: 0.7;
}
.chat-header .avatar {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #e7f3ec;
}
.chat-page[data-character="tutor"] .chat-header .avatar { background: #e4eef8; }
.chat-header .head-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}
.chat-header .head-text h1 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-header .tagline {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.2;
  opacity: 0.65;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.settings-btn {
  flex-shrink: 0;
  margin-left: auto;
  border: 0;
  background: transparent;
  color: #6a7a72;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}
.settings-btn svg {
  display: block;
  width: 22px;
  height: 22px;
}
.settings-btn:hover { background: rgba(0, 0, 0, 0.04); color: #1e3a5f; }
.chat-page[data-character="tutor"] .settings-btn:hover { color: #1e3a5f; }

.settings-sheet {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(400px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 48px);
  position: fixed;
  top: 50%;
  left: 50%;
  right: auto;
  bottom: auto;
  margin: 0;
  transform: translate(-50%, -50%);
}
.settings-sheet::backdrop {
  background: rgba(30, 40, 40, 0.4);
}
.settings-panel {
  background: #fff;
  border-radius: 20px;
  padding: 18px 18px 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.14);
  max-height: calc(100dvh - 48px);
  overflow: auto;
}
.settings-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.settings-head h2 {
  margin: 0;
  font-size: 1.05rem;
  color: #2c3a35;
}
.settings-close {
  border: 0;
  background: #f0f2f1;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  color: #5a6a63;
}
.settings-saved {
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #e7f3ec;
  color: #3d5c4d;
  font-size: 0.86rem;
}
.settings-saved[hidden] { display: none !important; }
.toast-settings {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  padding: 10px 16px;
  border-radius: 999px;
  background: #2c3a35;
  color: #fff;
  font-size: 0.88rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}
.toast-settings[hidden] { display: none !important; }
.settings-field {
  border: 0;
  margin: 0 0 16px;
  padding: 0;
}
.settings-field legend {
  font-size: 0.82rem;
  opacity: 0.7;
  margin-bottom: 8px;
  padding: 0;
}
.choice {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: 12px;
  background: #f5f7f6;
  cursor: pointer;
  font-size: 0.95rem;
}
.choice input { accent-color: #3d5c4d; }
.chat-page[data-character="tutor"] .choice input { accent-color: #1e3a5f; }
.settings-actions { margin-top: 8px; }
.settings-save { width: 100%; border-radius: 14px; }
.chat-page[data-character="tutor"] .settings-save {
  background: #1e3a5f;
}
.chat-page[data-character="tutor"] .settings-save:hover {
  background: #274d78;
}
.chat-page[data-character="tutor"] .settings-head h2 {
  color: #1e3a5f;
}
.chat-page[data-character="tutor"] .choice {
  background: #eef3f8;
}

.chat-log {
  flex: 1 1 auto;
  min-height: 0; /* flex 子が縮小し、内側だけスクロールできるようにする */
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.row { display: flex; gap: 8px; align-items: flex-end; }
.row.user { justify-content: flex-end; }
.row.ai { justify-content: flex-start; }
.bubble-wrap {
  display: flex;
  flex-direction: row;
  align-items: flex-end;
  gap: 6px;
  max-width: min(92%, 560px);
  min-width: 0;
}
.row.user .bubble-wrap {
  flex-direction: row-reverse; /* 吹き出しの外側（左）に時刻 */
}
.row.ai .bubble-wrap {
  flex-direction: row; /* 吹き出しの外側（右）に時刻 */
}
.msg-time {
  flex-shrink: 0;
  margin: 0 0 2px;
  padding: 0;
  font-size: 0.65rem;
  font-weight: 300;
  color: #b0b7c0;
  line-height: 1;
  white-space: nowrap;
}
.avatar.sm {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  background: #e7f3ec;
  flex-shrink: 0;
}
.bubble {
  min-width: 0;
  width: fit-content;
  max-width: min(100%, 480px);
  padding: 12px 14px;
  border-radius: 18px;
  line-height: 1.65;
  font-size: 0.95rem;
  overflow: hidden;
  box-sizing: border-box;
}
.bubble:has(.attach-preview) {
  width: min(70vw, 260px);
  max-width: min(70vw, 260px);
}
.bubble.user {
  background: #d9ddd6;
  border-bottom-right-radius: 6px;
}
.bubble.ai {
  background: #fff;
  border: 1px solid rgba(80, 110, 95, 0.1);
  border-bottom-left-radius: 6px;
}
/* keep-all だとスペースのない日本語が折り返せずはみ出す */
.bubble > div,
.bubble .md,
.bubble .md p,
.bubble .md li {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}
/* companion は nl2br 済みなので pre-wrap だと空行が二重に見える */
.bubble > div:not(.md) {
  white-space: normal;
}
.bubble .md {
  white-space: normal;
}
.bubble .md p,
.bubble .md li {
  white-space: pre-wrap;
}
.attach-preview {
  display: block;
  max-width: 100%;
  width: 100%;
  height: auto;
  border-radius: 12px;
  margin: 0 0 8px;
  object-fit: contain;
  vertical-align: top;
}
.empty-hint {
  text-align: center;
  font-size: 0.9rem;
  opacity: 0.65;
}
.flash-error {
  flex-shrink: 0;
  margin: 0;
  padding: 10px 14px;
  text-align: center;
  font-size: 0.88rem;
  color: #b42318;
  background: #fef3f2;
  border-top: 1px solid #f5c2c0;
}
.sticky-error {
  /* 入力欄の直上・スクロール外に固定 */
}

.chat-page[data-character="tutor"] .bubble.ai {
  border-color: rgba(30, 58, 95, 0.1);
}

.bubble.ai .md h2.major,
.bubble.ai .md h3.major {
  margin: 0 0 10px;
  font-size: 1.05rem;
  color: #1e3a5f;
  font-weight: 700;
}
.bubble.ai .md h4.subhead,
.bubble.ai .md h3.subhead,
.bubble.ai .md h2.subhead {
  margin: 14px 0 8px;
  font-size: 0.95rem;
  color: #1e3a5f;
  font-weight: 700;
}
.bubble.ai .md p { margin: 0 0 8px; }
.bubble.ai .md .point {
  background: #d9e8ff;
  border-radius: 12px;
  padding: 10px 12px;
  margin: 10px 0;
  color: #1e3a5f;
}
.bubble.ai .md .point p { margin: 0; }
.bubble.ai .md .section-rule {
  border: 0;
  border-top: 1px dashed rgba(30, 58, 95, 0.28);
  margin: 14px 0;
}
.bubble.ai .md ul {
  margin: 0 0 8px;
  padding-left: 1.2em;
  font-weight: 400;
  color: var(--brand-ink);
}
.bubble.ai .md ol.steps {
  list-style: none;
  margin: 0;
  padding: 0;
}
.bubble.ai .md ol.steps > li {
  margin: 0 0 14px;
  padding: 0;
  font-weight: 400;
  color: var(--brand-ink);
}
.bubble.ai .md .step-line,
.bubble.ai .md .step-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin: 12px 0 8px;
  min-width: 0;
}
.bubble.ai .md .step-num {
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
  min-width: 1.55em;
  height: 1.55em;
  padding: 0 0.2em;
  border-radius: 6px;
  background: #1e3a5f;
  color: #fff;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1;
}
.bubble.ai .md .step-title {
  min-width: 0;
  flex: 1;
  color: #1e3a5f;
  font-weight: 700;
  font-size: 0.95rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.bubble.ai .md ol.steps > li > p {
  margin: 6px 0 6px 0;
}
.bubble.ai .md pre {
  overflow: auto;
  background: #f3f6fa;
  padding: 10px;
  border-radius: 10px;
  font-size: 0.85rem;
}
.bubble.ai .md .math-block {
  overflow-x: auto;
  margin: 10px 0;
  padding: 4px 0;
  text-align: center;
}
.bubble.ai .md strong {
  color: #1e3a5f;
}

.composer {
  flex-shrink: 0;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid rgba(80, 110, 95, 0.12);
  z-index: 2;
}
.composer-tools { margin-bottom: 8px; font-size: 0.82rem; }
.hard-mode { display: inline-flex; align-items: center; gap: 6px; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  border-radius: 18px;
  resize: none;
}
.composer textarea::placeholder {
  color: rgba(80, 95, 90, 0.38);
  opacity: 1; /* Safari が独自 opacity を掛けても薄く見えるように固定 */
}
.composer textarea::-webkit-input-placeholder {
  color: rgba(80, 95, 90, 0.38);
  opacity: 1;
}
.composer textarea::-moz-placeholder {
  color: rgba(80, 95, 90, 0.38);
  opacity: 1;
}
.attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  height: 44px;
  border-radius: 14px;
  background: #e8f0f8;
  color: #1e3a5f;
  font-size: 0.82rem;
  cursor: pointer;
}
.attach-btn.has-file {
  background: #1e3a5f;
  color: #fff;
}
.attach-selected {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: 14px;
  background: #eef4fa;
  border: 1px solid #c9d8e8;
}
.attach-selected[hidden] { display: none !important; }
.attach-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 10px;
  background: #fff;
  flex-shrink: 0;
}
.attach-meta { flex: 1; min-width: 0; }
.attach-label {
  margin: 0;
  font-size: 0.72rem;
  opacity: 0.65;
}
.attach-name {
  margin: 2px 0 0;
  font-size: 0.86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-clear {
  border: 0;
  background: #fff;
  color: #1e3a5f;
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  flex-shrink: 0;
}
.send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  padding: 0;
  display: grid;
  place-items: center;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.send:disabled,
.send.is-sending {
  opacity: 0.55;
  cursor: wait;
}
.chat-page[data-character="tutor"] .send { background: #1e3a5f; }
.chat-page[data-character="companion"] .send.is-sending,
.chat-page[data-character="tutor"] .send.is-sending {
  background: #7a8a96;
}
.send-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.attach-btn.is-disabled {
  pointer-events: none;
  opacity: 0.5;
}
.bubble.ai.typing {
  min-width: 64px;
  padding: 14px 16px;
}
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 1em;
}
.typing-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9aa7b5;
  opacity: 0.45;
  animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-4px); opacity: 1; }
}
