/* Yuki — messenger-style chat. Colors live here as "tokens" so they're easy to change. */
:root {
  --bg-chat: #9db4d3;          /* snowy blue chat background */
  --bg-page: #24324a;
  --topbar: #24324a;
  --topbar-text: #ffffff;
  --bubble-me: #a6e88f;        /* your bubbles (green) */
  --bubble-me-text: #1d2a17;
  --bubble-yuki: #ffffff;
  --bubble-yuki-text: #1f2328;
  --meta: #3a4a63;             /* time / read marks */
  --fix-bg: #fff6df;           /* correction box */
  --fix-border: #f1c75b;
  --fix-accent: #b07800;
  --chip: #eef2f8;
  --en: #3d5a8a;               /* English translation text */
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #6b7686;
  --accent: #3b7dd8;
  --danger: #d94848;
  --composer: #ffffff;
  --radius: 18px;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg-chat: #1f2a3b;
    --bg-page: #111827;
    --topbar: #151d2b;
    --bubble-me: #4f9e3c;
    --bubble-me-text: #f2fff0;
    --bubble-yuki: #2c3647;
    --bubble-yuki-text: #eef1f6;
    --meta: #9fb0c8;
    --fix-bg: #3a3220;
    --fix-border: #a8842c;
    --fix-accent: #f3c55a;
    --chip: #3a4558;
    --en: #9ec2ff;
    --surface: #1b2433;
    --text: #e8edf4;
    --muted: #9aa6b8;
    --composer: #151d2b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg-page); color: var(--text); }
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.app { height: 100dvh; display: flex; justify-content: center; }

/* ---------- PC "stage" (future 3D avatar spot) ---------- */
.stage { display: none; }
@media (min-width: 900px) {
  .app { padding: 24px; gap: 24px; }
  .stage {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    width: 320px; border-radius: 24px; color: #fff; text-align: center; padding: 24px;
    background: linear-gradient(160deg, #31456a, #1b2638);
  }
  .stage-avatar { font-size: 96px; width: 180px; height: 180px; display: grid; place-items: center;
    border-radius: 50%; background: rgba(255,255,255,.08); box-shadow: 0 0 0 6px rgba(255,255,255,.05); }
  .stage h2 { margin: 20px 0 4px; font-size: 28px; }
  .stage .jp { font-weight: 400; opacity: .7; font-size: 18px; }
  .stage-status { margin: 0; opacity: .8; font-size: 14px; }
  .stage-note { margin-top: 32px; font-size: 13px; opacity: .55; }
  .chat { border-radius: 24px; overflow: hidden; }
}

/* ---------- Chat column ---------- */
.chat { width: 100%; max-width: 640px; display: flex; flex-direction: column; background: var(--bg-chat); position: relative; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px; background: var(--topbar); color: var(--topbar-text); }
.who { display: flex; align-items: center; gap: 10px; }
.mini-avatar { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  background: #e8f0fb; font-size: 22px; flex: none; }
.name { font-weight: 700; font-size: 17px; }
.mode-label { font-size: 12px; opacity: .75; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { background: none; border: 0; font-size: 22px; width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(127,127,127,.18); }

.messages { flex: 1; overflow-y: auto; padding: 16px 12px 8px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }

.day { align-self: center; font-size: 12px; color: #fff; background: rgba(0,0,0,.18); padding: 3px 10px; border-radius: 10px; }

.row { display: flex; align-items: flex-end; gap: 6px; max-width: 100%; }
.row.me { justify-content: flex-end; }
.row.yuki { align-items: flex-start; }
.row .avatar { width: 36px; height: 36px; border-radius: 50%; background: #e8f0fb; display: grid; place-items: center; font-size: 20px; flex: none; }
.stack { display: flex; flex-direction: column; gap: 6px; min-width: 0; max-width: min(78%, 480px); }
.row.yuki .who-name { font-size: 12px; color: var(--meta); margin-left: 4px; }
.line { display: flex; align-items: flex-end; gap: 6px; }
.row.me .line { flex-direction: row-reverse; }

.bubble { position: relative; padding: 9px 13px; border-radius: var(--radius); line-height: 1.6; font-size: 16px;
  word-break: break-word; white-space: pre-wrap; min-width: 0; }
.row.me .bubble { background: var(--bubble-me); color: var(--bubble-me-text); border-top-right-radius: 6px; }
.row.yuki .bubble { background: var(--bubble-yuki); color: var(--bubble-yuki-text); border-top-left-radius: 6px; }
.meta { font-size: 11px; color: var(--meta); white-space: nowrap; display: flex; flex-direction: column; align-items: flex-end; line-height: 1.3; flex: none; }
.row.yuki .meta { align-items: flex-start; }

ruby rt { font-size: .58em; opacity: .8; }
.no-furi rt { display: none; }

/* English translation shown in parallel */
.en { display: none; font-size: 14px; color: var(--en); border-top: 1px dashed rgba(127,127,127,.35); margin-top: 6px; padding-top: 5px; line-height: 1.45; }
.show-en .en { display: block; }
@media (min-width: 700px) {
  .show-en.bubble.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .show-en.bubble.pair .en { margin-top: 0; padding-top: 0; border-top: 0; border-left: 1px dashed rgba(127,127,127,.35); padding-left: 12px; }
}

/* Correction box */
.fix { background: var(--fix-bg); border: 1.5px solid var(--fix-border); color: var(--text); border-radius: 14px; padding: 10px 12px; font-size: 15px; line-height: 1.55; }
.fix-title { font-size: 13px; font-weight: 700; color: var(--fix-accent); margin-bottom: 4px; }
.fix-title-en { display: block; font-weight: 600; opacity: .8; }
.fix-sentence { font-size: 17px; font-weight: 600; margin: 2px 0 6px; }
.fix-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.fix-list li { background: rgba(255,255,255,.55); border-radius: 10px; padding: 7px 9px; }
@media (prefers-color-scheme: dark) { .fix-list li { background: rgba(0,0,0,.18); } }
.chip { display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; background: var(--chip); color: var(--muted); border-radius: 6px; padding: 1px 6px; margin-right: 6px; vertical-align: 2px; }
.wrong { text-decoration: line-through; text-decoration-color: var(--danger); opacity: .8; }
.arrow { margin: 0 4px; color: var(--muted); }
.right { font-weight: 600; }
.why { display: block; font-size: 14px; color: var(--muted); margin-top: 2px; }
.clarify { background: #e7f0ff; border: 1.5px solid #9dbcf0; color: #1f3d6b; border-radius: 14px; padding: 10px 12px; font-size: 15px; }
@media (prefers-color-scheme: dark) { .clarify { background: #1f3150; border-color: #3f5f96; color: #d7e6ff; } }

.tools { display: flex; gap: 6px; margin-left: 2px; }
.tool { font-size: 12px; background: rgba(255,255,255,.75); color: #2b3a52; border: 0; border-radius: 12px; padding: 3px 10px; }
.tool[aria-pressed="true"] { background: #2b3a52; color: #fff; }

.typing .bubble { display: flex; gap: 4px; align-items: center; padding: 14px 16px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: #9aa6b8; animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

.system-msg { align-self: center; max-width: 90%; text-align: center; font-size: 13px; color: #fff; background: rgba(0,0,0,.28); padding: 6px 12px; border-radius: 12px; }

/* ---------- Composer ---------- */
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px max(8px, env(safe-area-inset-bottom)); background: var(--composer); }
.composer textarea { flex: 1; resize: none; border: 0; border-radius: 20px; background: rgba(127,127,127,.13); color: var(--text);
  font: inherit; font-size: 16px; padding: 10px 14px; max-height: 120px; line-height: 1.4; outline: none; }
.send-btn { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 18px; flex: none; }
.send-btn:disabled { opacity: .45; cursor: default; }

.emoji-panel { background: var(--composer); border-top: 1px solid rgba(127,127,127,.2); padding: 8px; display: grid;
  grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 2px; max-height: 190px; overflow-y: auto; }
.emoji-panel button { border: 0; background: none; font-size: 24px; height: 40px; border-radius: 8px; }
.emoji-panel button:hover { background: rgba(127,127,127,.15); }

/* ---------- 📚 Study link ---------- */
.study-btn.on { background: var(--accent); color: #fff; border-radius: 50%; }
.study-panel { background: var(--composer); border-top: 1px solid rgba(127,127,127,.2); padding: 8px; display: grid; gap: 6px; max-height: 50dvh; overflow-y: auto; }
.study-opt { display: flex; align-items: center; gap: 10px; text-align: left; border: 1px solid rgba(127,127,127,.25); background: none;
  color: var(--text); border-radius: 14px; padding: 9px 12px; font: inherit; cursor: pointer; }
.study-opt:hover { background: rgba(127,127,127,.1); }
.study-opt.on { border-color: var(--accent); background: rgba(59,125,216,.12); }
.study-opt strong { display: block; font-size: 15px; }
.study-opt small { display: block; color: var(--muted); font-size: 12.5px; }
.study-ico { font-size: 22px; flex: none; width: 28px; text-align: center; }
.study-note { margin: 2px 4px 0; font-size: 12px; color: var(--muted); }
.study-bar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--composer); border-top: 1px solid rgba(127,127,127,.2);
  font-size: 13px; color: var(--text); }
.study-bar #studyText { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Yuki's picture ---------- */
/* When a picture is chosen, every avatar shows it as a background and hides the ❄️ text. */
body.av-img .avatar, body.av-img .mini-avatar, body.av-img .stage-avatar, body.av-img .login-avatar, body.av-img .av-big {
  background: var(--yuki-av) center / cover no-repeat; font-size: 0; color: transparent; }

/* Tap Yuki's photo anywhere to see it big, like a contact photo on your phone */
.mini-avatar, .stage-avatar, .row .avatar { cursor: pointer; transition: transform .12s; }
.mini-avatar:active, .stage-avatar:active, .row .avatar:active { transform: scale(.92); }
.mini-avatar:focus-visible, .stage-avatar:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.av-viewer { position: fixed; inset: 0; z-index: 15; background: #000; color: #fff; display: flex; flex-direction: column;
  animation: avFade .18s ease-out; }
.av-viewer-bar { display: flex; align-items: center; gap: 8px; padding: max(10px, env(safe-area-inset-top)) 8px 10px; }
.av-viewer .icon-btn { color: #fff; }
.av-viewer .icon-btn:hover { background: rgba(255,255,255,.15); }
.av-viewer-name { flex: 1; font-weight: 700; font-size: 18px; }
.av-viewer-name .jp { font-weight: 400; opacity: .6; font-size: 15px; }
.av-stage { flex: 1; display: grid; place-items: center; padding: 16px 0 max(32px, env(safe-area-inset-bottom)); }
.av-big { width: min(100vw, 72dvh, 560px); aspect-ratio: 1; display: grid; place-items: center;
  font-size: min(40vw, 30dvh, 220px); background: #1b2638; animation: avZoom .22s ease-out; }
@media (min-width: 700px) { .av-big { border-radius: 12px; } }
@keyframes avFade { from { opacity: 0; } }
@keyframes avZoom { from { transform: scale(.6); opacity: 0; } }

/* "Change picture" menu (slides up from the bottom, like a phone's photo options) */
.av-menu { position: absolute; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 700px) { .av-menu { align-items: center; } }
.av-menu-card { width: 100%; max-width: 420px; background: var(--surface); color: var(--text); border-radius: 22px 22px 0 0;
  padding: 16px 12px max(14px, env(safe-area-inset-bottom)); animation: avUp .2s ease-out; }
@media (min-width: 700px) { .av-menu-card { border-radius: 22px; } }
@keyframes avUp { from { transform: translateY(40px); opacity: 0; } }
.av-menu-title { font-weight: 700; text-align: center; margin: 0 0 10px; }
.av-opt { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border: 0; border-radius: 14px;
  background: none; color: var(--text); font: inherit; font-size: 16px; text-align: left; cursor: pointer; }
.av-opt:hover { background: rgba(127,127,127,.12); }
.av-opt[aria-checked="true"]::after { content: "✓"; margin-left: auto; color: var(--accent); font-weight: 700; }
.av-opt.cancel { justify-content: center; margin-top: 6px; color: var(--muted); background: rgba(127,127,127,.12); }
.av-dot { width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center; font-size: 22px;
  background: #e8f0fb center / cover no-repeat; }
.crop canvas { display: block; width: min(300px, 100%); aspect-ratio: 1; margin: 6px auto 10px; border-radius: 12px; background: #111; touch-action: none; cursor: grab; }
.crop-zoom { display: flex; align-items: center; gap: 10px; }
.crop-zoom input { flex: 1; accent-color: var(--accent); }
.crop-btns { display: flex; gap: 10px; align-items: center; margin-top: 12px; }
.crop-btns .tool { padding: 12px 16px; background: rgba(127,127,127,.15); color: var(--text); }
.crop-btns .primary { flex: 1; }
.crop-btns .primary:disabled { opacity: .5; }
#cropSheet { z-index: 20; }

/* ---------- Settings sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
@media (min-width: 700px) { .sheet-backdrop { align-items: center; } }
.sheet { width: 100%; max-width: 460px; background: var(--surface); color: var(--text); border-radius: 22px 22px 0 0; padding: 20px 18px max(20px, env(safe-area-inset-bottom)); max-height: 90dvh; overflow-y: auto; }
@media (min-width: 700px) { .sheet { border-radius: 22px; } }
.sheet h3 { margin: 0 0 14px; }
.field { display: block; margin-bottom: 18px; }
.field-label { font-weight: 600; display: block; margin-bottom: 6px; }
.hint { font-size: 13px; color: var(--muted); font-weight: 400; }
.field input[type="password"] { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid rgba(127,127,127,.35); background: transparent; color: var(--text); font: inherit; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch-row input { width: 22px; height: 22px; accent-color: var(--accent); }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode-btn { position: relative; border: 1.5px solid rgba(127,127,127,.3); background: transparent; border-radius: 12px; padding: 10px 6px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.mode-btn small { font-weight: 400; font-size: 11px; color: var(--muted); }
.mode-btn[aria-checked="true"] { border-color: var(--accent); background: rgba(59,125,216,.12); }
.alpha-badge { position: absolute; top: -8px; right: -6px; width: 20px; height: 20px; border-radius: 50%; background: #f0a020; color: #fff; font-size: 13px; font-weight: 800; display: grid; place-items: center; }
.alpha-note { font-size: 13px; background: #fff3d6; color: #6b4a00; border-radius: 10px; padding: 8px 10px; margin: 10px 0 0; }
@media (prefers-color-scheme: dark) { .alpha-note { background: #3a3220; color: #f3d48a; } }
.primary { width: 100%; border: 0; border-radius: 12px; padding: 12px; background: var(--accent); color: #fff; font-weight: 700; }

/* ---------- Saved chats ---------- */
.viewing-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; background: #fff3d6; color: #6b4a00; font-size: 13px; font-weight: 600; }
@media (prefers-color-scheme: dark) { .viewing-bar { background: #3a3220; color: #f3d48a; } }
.viewing-bar #viewingTitle { flex: 1; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.archive-list { list-style: none; margin: 12px 0 16px; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.archive-list li { display: flex; align-items: center; gap: 8px; border: 1px solid rgba(127,127,127,.25); border-radius: 12px; padding: 10px 12px; }
.archive-open { flex: 1; min-width: 0; text-align: left; background: none; border: 0; padding: 0; }
.archive-open strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.archive-open small { color: var(--muted); }
.archive-del { border: 0; background: none; font-size: 18px; border-radius: 8px; padding: 4px 8px; flex: none; }
.archive-del.confirm { background: var(--danger); color: #fff; font-size: 13px; font-weight: 700; }
.archive-empty { color: var(--muted); text-align: center; padding: 20px 0; }

/* ---------- Energy, banner, account, sign-in ---------- */
.energy { white-space: nowrap; margin-left: 6px; font-weight: 700; font-size: 11px; padding: 1px 7px; border-radius: 10px; background: rgba(255,255,255,.15); }
.energy.low { background: #f0a020; color: #2b1d00; }
.banner { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #fff3d6; color: #6b4a00; font-size: 13px; font-weight: 600; }
.banner.danger { background: #ffe1e1; color: #7a1f1f; }
@media (prefers-color-scheme: dark) { .banner { background: #3a3220; color: #f3d48a; } .banner.danger { background: #45201f; color: #ffc9c9; } }
.banner #bannerText { flex: 1; }
.banner-x { border: 0; background: none; font-size: 14px; opacity: .7; }
.account-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.account-row .tool { background: rgba(127,127,127,.15); color: var(--text); }
#syncStatus { margin-top: 4px; }

.login { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: linear-gradient(160deg, #31456a, #1b2638); color: #fff; }
.login-card { width: 100%; max-width: 380px; text-align: center; }
.login-avatar { font-size: 72px; width: 140px; height: 140px; margin: 0 auto; display: grid; place-items: center; border-radius: 50%; background: rgba(255,255,255,.08); }
.login h1 { margin: 18px 0 6px; font-size: 32px; }
.login h1 .jp { font-weight: 400; opacity: .7; font-size: 20px; }
.login p { opacity: .85; line-height: 1.5; }
.login .hint { color: rgba(255,255,255,.7); }
.google-btn { display: inline-flex; align-items: center; gap: 10px; margin-top: 12px; border: 0; border-radius: 24px; padding: 12px 22px; background: #fff; color: #1f2328; font-weight: 700; font-size: 16px; }
.google-btn:disabled { opacity: .6; }
.login-error { background: rgba(217,72,72,.25); border-radius: 10px; padding: 8px 10px; font-size: 14px; }

/* Furigana on/off button in the top bar */
.furi-btn { font-size: 20px; font-weight: 700; color: var(--topbar-text); opacity: .45; }
.furi-btn rt { font-size: 9px; }
.furi-btn[aria-pressed="true"] { opacity: 1; background: rgba(255,255,255,.14); }

/* Kanji tips (hiragana that's usually written in kanji) — friendly, not an error */
.fix.tip { background: #e9f6ff; border-color: #8cc4ec; }
.fix.tip .fix-title { color: #1f5f8f; }
@media (prefers-color-scheme: dark) { .fix.tip { background: #1d3142; border-color: #3f6f96; } .fix.tip .fix-title { color: #9fd0ff; } }
.kanji-tip .chip { background: #dff0ff; color: #1f5f8f; }
.kana { opacity: .85; }
