/* Each learning mode colours the whole workspace, not just its selected button. */
:root {
  color-scheme: light;
  --ink: #293f46;
  --muted: #596d73;
  --accent: #286756;
  --accent-soft: #dff5e9;
  --tint: #bfe8d5;
  --glow: #cfeee0;
  --secondary: #fbe9c9;
  --paper: #f0f8f2;
  --line: #c9e1d5;
  --surface: #f8fffa;
  font-family: 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
body {
  margin: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column;
  background: radial-gradient(ellipse at 5% 85%, var(--glow), transparent 55%),
    radial-gradient(ellipse at 95% 5%, var(--secondary), transparent 50%), var(--paper);
}
body[data-mode="wordhelper"] {
  --accent: #654595; --accent-soft: #eee4fc; --tint: #d9c7f3;
  --glow: #e1d2f7; --secondary: #f9dfe9; --paper: #f6f0fc;
  --line: #ddcfea; --surface: #fcf8ff;
}
body[data-mode="writinghelper"] {
  --accent: #984b61; --accent-soft: #fce4e6; --tint: #f6cbd5;
  --glow: #f6d6da; --secondary: #ffe7c8; --paper: #fff3ed;
  --line: #edd1d5; --surface: #fff9f6;
}
body[data-mode="imagegen"] {
  --accent: #2c6396; --accent-soft: #e0f1fe; --tint: #bfdef6;
  --glow: #cce7fb; --secondary: #e7ddfa; --paper: #eef7fe;
  --line: #c9dded; --surface: #f7fcff;
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; border: 0; }
button, .image-upload-label { transition: background .15s, border-color .15s, transform .15s; }
button:disabled { cursor: wait; opacity: .6; }
button:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible, .generated-image:focus-visible { outline: 3px solid #d48b43; outline-offset: 4px; }
button:hover:not(:disabled) { transform: translateY(-1px); }
.hidden { display: none !important; }
#header { display: flex; gap: 14px; align-items: center; padding: 20px max(24px, calc((100vw - 1100px)/2)); border-bottom: 1px solid var(--line); background: linear-gradient(110deg, var(--accent-soft), var(--surface) 65%, var(--secondary)); flex-shrink: 0; position: relative; }
#header::before { content: ""; position: absolute; inset: 0 0 auto; height: 4px; background: linear-gradient(90deg, #a1d9c1 0% 25%, #cdb4ee 25% 50%, #f3b9c5 50% 75%, #add5f5 75%); }
#logo { width: 48px; height: 48px; padding: 5px; background: white; border: 1px solid var(--line); border-radius: 14px; flex-shrink: 0; }
#logo img { width: 100%; height: 100%; object-fit: contain; }
.school-name, .eyebrow { color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
#header h1 { margin: 4px 0 0; font-size: 19px; letter-spacing: -.5px; font-weight: 700; }
#header p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.header-note { margin-left: auto; display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; white-space: nowrap; }
.header-note::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
#chat-container { display: flex; flex-direction: column; flex: 1; min-height: 0; max-width: 1100px; width: 100%; margin: 0 auto; padding: 22px 24px 14px; }
.space-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; min-height: 24px; }
.year-badge { padding: 5px 11px; border: 1px solid var(--line); background: var(--accent-soft); border-radius: 99px; color: var(--accent); font-size: 11px; }
.mode-toggle-container { display: none; margin-bottom: 16px; }
.mode-toggle-container.visible { display: block; }
.mode-toggle { display: flex; gap: 8px; }
.mode-toggle-slider { display: none; }
.mode-toggle-option { flex: 1; min-height: 51px; display: flex; align-items: center; justify-content: center; gap: 9px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 13px; background: var(--card-bg); color: var(--card-ink); font-size: 13px; font-weight: 600; }
[data-mode="learning"].mode-toggle-option, [data-mode="learning"].mode-btn { --card-bg: #e4f5eb; --card-ink: #286756; --card-line: #b7dbc9; }
[data-mode="wordhelper"].mode-toggle-option, [data-mode="wordhelper"].mode-btn { --card-bg: #eee5fa; --card-ink: #654595; --card-line: #d8c6ed; }
[data-mode="writinghelper"].mode-toggle-option, [data-mode="writinghelper"].mode-btn { --card-bg: #fce6e9; --card-ink: #984b61; --card-line: #f1c9d3; }
[data-mode="imagegen"].mode-toggle-option, [data-mode="imagegen"].mode-btn { --card-bg: #e3f1fe; --card-ink: #2c6396; --card-line: #c0ddf3; }
.mode-toggle-option, .mode-btn { border-color: var(--card-line); }
.mode-toggle-option.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent), 0 5px 14px #35435c0a; }
.mode-icon { display: inline-flex; justify-content: center; align-items: center; font-size: 19px; }
#chat { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; background: radial-gradient(ellipse at 95% 0%, var(--accent-soft), transparent 65%), linear-gradient(160deg, #ffffff 25%, var(--surface)); border: 1px solid var(--line); border-radius: 22px 22px 0 0; padding: 24px 28px; scroll-behavior: smooth; transition: opacity .18s, transform .18s; }
#chat.swipe-out-left, #chat.swipe-out-right { opacity: 0; transform: translateY(5px); }
#chat.swipe-in-left, #chat.swipe-in-right { opacity: 0; transform: translateY(-5px); }
.welcome-message { text-align: center; margin: clamp(20px, 6vh, 70px) auto 28px; max-width: 490px; }
.welcome-symbol { display: inline-flex; align-items: center; justify-content: center; width: 84px; height: 84px; border-radius: 27px; background: linear-gradient(135deg, var(--accent-soft), var(--tint)); color: var(--accent); margin-bottom: 19px; transform: rotate(-5deg); position: relative; box-shadow: 7px 7px 0 var(--secondary); }
.welcome-symbol::after { content: "✦"; position: absolute; top: -12px; right: -19px; color: var(--accent); font-size: 21px; }
.welcome-symbol svg { width: 47px; height: 47px; transform: rotate(5deg); }
.welcome-message .eyebrow { color: var(--accent); }
.welcome-message h2 { font-size: clamp(26px, 3vw, 36px); font-weight: 650; letter-spacing: -1.1px; line-height: 1.15; margin: 10px 0 12px; }
.welcome-message p { font-size: 14px; line-height: 1.7; color: var(--muted); margin: 0 auto; max-width: 430px; }
.suggested-questions { display: flex; flex-wrap: wrap; justify-content: center; gap: 9px; max-width: 650px; margin: 0 auto 24px; }
.question-bubble { background: var(--accent-soft); border: 1px solid var(--line); border-radius: 12px; color: var(--ink); font-size: 12px; line-height: 1.5; padding: 11px 15px; text-align: left; }
.question-bubble:nth-child(3n + 2) { background: var(--secondary); }
.question-bubble:nth-child(3n + 3) { background: var(--tint); }
.question-bubble::after { content: ' ↗'; color: var(--accent); }
.question-bubble:hover { border-color: var(--accent); background: var(--accent-soft); }
.msg { border-radius: 16px; margin-bottom: 18px; padding: 16px 20px; font-size: 15px; line-height: 1.7; overflow-wrap: anywhere; animation: fadeIn .2s ease; }
.msg.user { margin-left: auto; max-width: 76%; background: linear-gradient(135deg, var(--accent-soft), var(--tint)); color: var(--ink); border: 1px solid var(--line); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.msg.assistant { max-width: 88%; background: var(--surface); border: 1px solid var(--line); color: var(--ink); border-bottom-left-radius: 4px; }
.thinking-dots { display: inline-flex; gap: 5px; margin-right: 10px; vertical-align: middle; }
.thinking-dots span { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: dotPulse 1.2s infinite; }
.thinking-dots span:nth-child(2) { animation-delay: .2s; }
.thinking-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes dotPulse { 50% { opacity: .3; } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
#chatForm { flex-shrink: 0; max-height: 50dvh; overflow-y: auto; display: none; flex-wrap: wrap; align-items: flex-end; gap: 12px; padding: 16px 20px; border: 1px solid var(--line); border-top: 0; border-radius: 0 0 22px 22px; background: linear-gradient(110deg, var(--accent-soft), var(--surface)); box-shadow: 0 12px 30px #203c3108; }
#userInput { flex: 1; min-width: 0; width: 100%; resize: vertical; min-height: 48px; max-height: 140px; padding: 12px 14px; line-height: 1.5; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); }
#userInput::placeholder, .image-prompt::placeholder { color: #71817b; }
#chatForm button[type="submit"] { background: var(--accent); color: white; min-height: 48px; border-radius: 12px; padding: 12px 22px; font-size: 14px; font-weight: 650; }
#chatForm button[type="submit"]::after { content: ' ↑'; margin-left: 8px; }
.composer-hint { margin: 10px 0 0; text-align: center; color: var(--muted); font-size: 10px; line-height: 1.5; }
.image-upload-container { display: none; width: 100%; border: 1px dashed var(--accent); border-radius: 13px; padding: 12px 14px; background: var(--accent-soft); position: relative; }
.image-upload-container.visible { display: block; }
.image-upload-label { color: var(--accent); font-size: 13px; font-weight: 650; cursor: pointer; display: inline-block; }
#imageInput { position: absolute; width: 1px; height: 1px; overflow: hidden; opacity: 0; }
.image-upload-container:focus-within { outline: 3px solid #d48b43; outline-offset: 3px; }
#writingPhotoStatus { color: var(--muted); font-size: 11px !important; line-height: 1.5; }
.image-preview-container { display: none; position: relative; width: fit-content; margin-top: 12px; }
.image-preview-container.visible { display: block; }
.image-preview { max-width: 100%; max-height: 125px; display: block; border: 1px solid var(--line); border-radius: 8px; }
.remove-image-btn { position: absolute; right: -12px; top: -12px; width: 32px; height: 32px; border: 1px solid var(--line); border-radius: 50%; background: white; color: var(--ink); font-size: 20px; }
.image-generation-container { display: none; flex-direction: column; gap: 8px; width: 100%; }
.image-generation-container.visible { display: flex; }
.field-label { color: var(--muted); font-size: 11px; font-weight: 650; }
.image-prompt, .image-style-select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; background: var(--surface); color: var(--ink); }
.image-prompt { min-height: 75px; max-height: 130px; resize: vertical; font-size: 14px; line-height: 1.5; }
.image-style-select { font-size: 13px; }
.generated-image { display: block; width: min(100%, 340px); border-radius: 12px; margin-top: 14px; cursor: zoom-in; }
.image-thumb-label { font-size: 11px; margin-top: 8px; color: var(--muted); }
.drawing-icons { display: flex; gap: 12px; font-size: 24px; margin-bottom: 9px; }
.drawing-status { color: var(--muted); font-size: 13px; }
.image-overlay { display: none; position: fixed; inset: 0; z-index: 2000; align-items: center; justify-content: center; padding: 24px; background: #142b28e8; }
.image-overlay.visible { display: flex; }
.image-overlay img { max-width: 95vw; max-height: 85dvh; border-radius: 14px; }
.overlay-close { position: absolute; right: 20px; top: 20px; width: 44px; height: 44px; background: white; color: var(--ink); border-radius: 50%; font-size: 24px; }
.year-level-modal { position: fixed; inset: 0; z-index: 1000; display: flex; justify-content: center; align-items: center; padding: 24px; background: radial-gradient(ellipse at 5% 10%, #dfd3f4cc, transparent 55%), radial-gradient(ellipse at 95% 85%, #fbded6cc, transparent 55%), #edf6f0f2; backdrop-filter: blur(8px); overflow: auto; }
.year-level-content { width: min(100%, 600px); border: 1px solid var(--line); background: linear-gradient(155deg, #fff 35%, #f4ecfc); border-radius: 28px; padding: 38px; text-align: center; box-shadow: 0 22px 80px #274c3e0d; position: relative; }
.year-level-content::before { content: ''; position: absolute; width: 70px; height: 7px; top: -1px; left: calc(50% - 35px); border-radius: 0 0 6px 6px; background: linear-gradient(90deg, #a1d9c1, #cdb4ee, #f3b9c5, #add5f5); }
.modal-mark { display: inline-flex; width: 65px; height: 65px; background: linear-gradient(135deg, #dff5e9, #bfe8d5); color: #286756; border-radius: 20px; align-items: center; justify-content: center; margin-bottom: 18px; }
.modal-mark svg { width: 38px; height: 38px; }
.year-level-content h2 { margin: 12px 0; font-size: clamp(29px, 4vw, 38px); line-height: 1.1; font-weight: 650; letter-spacing: -1.2px; }
.year-level-content p { color: var(--muted); font-size: 14px; line-height: 1.6; margin: 0 auto 26px; }
.step-label { font-size: 10px; text-transform: uppercase; letter-spacing: .12em; color: var(--accent); font-weight: 700; margin-bottom: 13px; }
.year-level-buttons { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; }
.year-level-btn { min-height: 74px; background: #e4f5eb; border: 1px solid var(--line); border-radius: 13px; color: var(--ink); font-size: 14px; font-weight: 650; }
.year-level-btn:nth-child(2) { background: #eee5fa; border-color: #d8c6ed; }
.year-level-btn:nth-child(3) { background: #fce6e9; border-color: #f1c9d3; }
.year-level-btn:nth-child(4) { background: #e3f1fe; border-color: #c0ddf3; }
.year-level-btn:nth-child(5) { background: #fff0cf; border-color: #ead7a7; }
.year-level-btn:hover { background: #eaf4ed; border-color: #246957; }
.mode-selector { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.mode-btn { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left; padding: 17px; border: 1px solid var(--card-line); border-radius: 15px; background: var(--card-bg); color: var(--card-ink); }
.mode-btn .mode-icon { font-size: 25px; margin-bottom: 5px; }
.mode-btn strong { font-size: 14px; font-weight: 650; }
.mode-btn small { font-size: 11px; line-height: 1.5; color: var(--muted); }
.mode-btn:hover { border-color: var(--card-ink); box-shadow: 0 5px 15px #35435c0a; }
.modal-footer { border-top: 1px solid var(--line); padding-top: 19px; margin-top: 25px; color: var(--muted); font-size: 10px; letter-spacing: .03em; }
.back-year { margin-top: 15px; background: transparent; color: var(--muted); font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }
/* A quiet shimmer while thinking, followed by one short reveal. */
.msg.assistant { position: relative; }
.msg.is-thinking {
  min-height: 64px;
  border-color: var(--tint);
  background: linear-gradient(115deg, var(--surface), var(--accent-soft), var(--surface));
  background-size: 200% 100%;
  animation: thinkingGlow 3s ease-in-out infinite;
  box-shadow: 0 0 22px var(--accent-soft);
}
.magic-sparkles { position: absolute; inset: 0; pointer-events: none; user-select: none; }
.magic-sparkles > span { position: absolute; color: var(--accent); font-size: 19px; opacity: 0; line-height: 1; }
.magic-sparkles > span:nth-child(1) { left: 10%; top: -9px; }
.magic-sparkles > span:nth-child(2) { left: 46%; top: -7px; font-size: 14px; }
.magic-sparkles > span:nth-child(3) { right: -7px; top: 26%; }
.magic-sparkles > span:nth-child(4) { right: 17%; bottom: -8px; font-size: 15px; }
.magic-sparkles > span:nth-child(5) { left: 27%; bottom: -8px; }
.magic-sparkles > span:nth-child(6) { left: -8px; top: 48%; font-size: 14px; }
.is-thinking .magic-sparkles > span { animation: sparkleTwinkle 2.4s ease-in-out infinite; }
.is-thinking .magic-sparkles > span:nth-child(2n) { animation-delay: .6s; }
.is-thinking .magic-sparkles > span:nth-child(3n) { animation-delay: 1.2s; }
.msg.answer-reveal { animation: answerAppear .8s cubic-bezier(.2,.7,.3,1) both; }
.answer-reveal .magic-sparkles > span { animation: answerSparkle .75s ease-out both; }
.answer-reveal .magic-sparkles > span:nth-child(2n) { animation-delay: .08s; }
@keyframes thinkingGlow {
  0%, 100% { background-position: 0% 50%; box-shadow: 0 0 12px var(--accent-soft); }
  50% { background-position: 100% 50%; box-shadow: 0 0 25px var(--tint); }
}
@keyframes sparkleTwinkle {
  0%, 100% { opacity: 0; transform: translateY(3px) scale(.65) rotate(-12deg); }
  45% { opacity: .65; transform: translateY(-2px) scale(1) rotate(8deg); }
}
@keyframes answerAppear {
  from { opacity: 0; transform: translateY(8px) scale(.985); filter: blur(3px); }
  to { opacity: 1; transform: none; filter: blur(0); }
}
@keyframes answerSparkle {
  0% { opacity: 0; transform: scale(.5) translateY(3px); }
  30% { opacity: .75; }
  100% { opacity: 0; transform: scale(1.3) translateY(-9px); }
}
@media (max-width: 640px) {
  #header { padding: 13px 16px; gap: 10px; }
  #header h1 { font-size: 16px; }
  #header p { font-size: 11px; }
  #logo { width: 42px; height: 42px; }
  .school-name { font-size: 8px; letter-spacing: .11em; }
  .header-note { display: none; }
  #chat-container { padding: 13px 12px 10px; }
  .space-heading { margin-bottom: 10px; }
  .mode-toggle { flex-wrap: wrap; gap: 6px; }
  .mode-toggle-option { flex: 1 1 calc(50% - 6px); min-height: 42px; padding: 9px 5px; font-size: 11px; }
  .mode-toggle-container { margin-bottom: 10px; }
  #chat { padding: 18px 14px; border-radius: 16px 16px 0 0; }
  .welcome-message { margin: 20px auto; }
  .welcome-symbol { width: 64px; height: 64px; border-radius: 21px; margin-bottom: 11px; }
  .welcome-symbol svg { width: 37px; height: 37px; }
  .welcome-message h2 { font-size: 28px; }
  .welcome-message p { font-size: 13px; }
  .question-bubble { font-size: 11px; padding: 9px 11px; }
  #chatForm { padding: 12px; gap: 8px; border-radius: 0 0 16px 16px; }
  #userInput { padding: 11px; font-size: 16px; min-height: 72px; }
  #chatForm button[type="submit"] { padding: 12px 14px; font-size: 12px; }
  .msg { font-size: 14px; padding: 13px 15px; }
  .msg.user { max-width: 88%; }
  .msg.assistant { max-width: 96%; }
  .year-level-modal { padding: 16px; }
  .year-level-content { padding: 28px 20px; border-radius: 22px; }
  .year-level-buttons { gap: 5px; }
  .year-level-btn { min-height: 62px; font-size: 12px; }
  .mode-btn { padding: 14px 12px; }
  .composer-hint { font-size: 9px; }
}
@media (max-height: 650px) {
  #header { padding-top: 10px; padding-bottom: 10px; }
  #chat-container { padding-top: 10px; }
  .welcome-message { margin: 14px auto; }
  .welcome-symbol { width: 54px; height: 54px; margin-bottom: 6px; }
  .welcome-message h2 { font-size: 25px; }
  .year-level-modal { align-items: flex-start; }
  .year-level-content { margin: auto; padding-top: 24px; padding-bottom: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
