:root {
  --bg: #FFF8F0;
  --card: #FFFFFF;
  --text: #3A2A22;
  --muted: #8A7468;
  --line: #F1E2D3;
  --primary: #F2694F;
  --primary-2: #FF8A4C;
  --good: #2E9E6A;
  --good-bg: #E3F6EC;
  --bad: #D64545;
  --bad-bg: #FDEAEA;
  --words: #FFE7A3;
  --quiz: #E4DAFF;
  --topics: #CDEFE6;
  --chat: #D6EBFF;
  --diary: #FFDCE5;
  --radius: 22px;
  --shadow: 0 4px 16px rgba(120, 70, 40, 0.08);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  font-size: 18px; line-height: 1.5;
}
button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--primary); }

.screen { max-width: 640px; margin: 0 auto; padding: calc(12px + var(--safe-t)) 16px calc(28px + var(--safe-b)); }

/* Top bar */
.topbar { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; min-height: 48px; }
.topbar h1 { font-size: 22px; margin: 0; flex: 1; }
.icon-btn { width: 46px; height: 46px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; background: var(--card); box-shadow: var(--shadow); flex: none; }
.icon-btn:active { transform: scale(0.95); }

/* Home */
.hello { display: flex; align-items: center; gap: 10px; margin: 4px 0 6px; }
.hello h1 { font-size: 28px; margin: 0; flex: 1; line-height: 1.2; }
.sub { color: var(--muted); margin: 0 0 18px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip { background: var(--card); border-radius: 999px; padding: 8px 14px; font-weight: 600; font-size: 16px; box-shadow: var(--shadow); }
.install-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 14px; border-radius: 16px; color: #fff; font-weight: 700; background: linear-gradient(135deg, var(--primary-2), var(--primary)); box-shadow: var(--shadow); margin-bottom: 16px; font-size: 18px; }
.banner { background: #FFF1D6; border: 2px dashed #F5C26B; border-radius: 16px; padding: 12px 14px; margin-bottom: 16px; font-size: 16px; }
.banner b { display: block; margin-bottom: 2px; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.box { border-radius: var(--radius); padding: 18px 16px; text-align: left; box-shadow: var(--shadow); min-height: 140px; display: flex; flex-direction: column; justify-content: space-between; }
.box:active { transform: scale(0.98); }
.box .emoji { font-size: 38px; line-height: 1; }
.box .name { font-size: 20px; font-weight: 800; margin-top: 10px; line-height: 1.2; }
.box .meta { font-size: 15px; color: rgba(58, 42, 34, 0.72); margin-top: 4px; }
.box.wide { grid-column: span 2; min-height: 0; flex-direction: row; align-items: center; gap: 14px; justify-content: flex-start; }
.box.wide .name { margin-top: 0; }
.b-words { background: var(--words); } .b-quiz { background: var(--quiz); } .b-topics { background: var(--topics); }
.b-chat { background: var(--chat); } .b-fav { background: #FFE3DC; } .b-diary { background: var(--diary); } .b-progress { background: var(--card); }

/* Cards */
.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card h2 { margin: 0 0 4px; font-size: 26px; }
.pos { color: var(--muted); font-style: italic; font-size: 16px; }
.label { font-size: 14px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 12px 0 2px; }
.example { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; }
.example span { flex: 1; }
.mini-btn { padding: 6px 12px; border-radius: 999px; background: #FFF1E6; font-size: 15px; font-weight: 600; flex: none; }
.mini-btn:active { background: #FFE0C9; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.btn { padding: 14px 20px; border-radius: 16px; font-weight: 700; background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; box-shadow: var(--shadow); font-size: 18px; }
.btn.secondary { background: var(--card); color: var(--text); border: 2px solid var(--line); box-shadow: none; }
.btn.done { background: var(--good-bg); color: var(--good); box-shadow: none; }
.btn.block { width: 100%; }
.btn:disabled { opacity: 0.5; }
.help-box { background: #FFF6EC; border-radius: 14px; padding: 10px 12px; margin-top: 10px; font-size: 16px; }
.help-box div + div { margin-top: 4px; }
.progress-bar { height: 12px; background: #F3E4D6; border-radius: 999px; overflow: hidden; margin: 6px 0 16px; }
.progress-bar > div { height: 100%; background: linear-gradient(90deg, var(--primary-2), var(--primary)); border-radius: 999px; transition: width 0.3s; }
.muted { color: var(--muted); }
.center { text-align: center; }
.big-emoji { font-size: 56px; text-align: center; margin: 10px 0; }

/* Quiz */
.q-text { font-size: 22px; font-weight: 700; margin: 6px 0 16px; }
.option { display: block; width: 100%; text-align: left; padding: 16px; border-radius: 16px; background: var(--card); border: 2px solid var(--line); margin-bottom: 10px; font-size: 18px; }
.option.correct { border-color: var(--good); background: var(--good-bg); }
.option.wrong { border-color: var(--bad); background: var(--bad-bg); }
.feedback { border-radius: 14px; padding: 12px 14px; margin: 6px 0 14px; font-size: 17px; }
.feedback.good { background: var(--good-bg); }
.feedback.bad { background: var(--bad-bg); }

/* Topics */
.topic { display: block; width: 100%; text-align: left; border-radius: var(--radius); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); background: var(--card); }
.topic .tag { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 14px; font-weight: 700; background: var(--topics); }
.topic .tag.story { background: var(--words); }
.topic .tag.fun { background: var(--quiz); }
.topic h3 { margin: 8px 0 4px; font-size: 21px; }
.topic .status { font-size: 15px; font-weight: 700; margin-top: 8px; color: var(--muted); }
.topic .status.done { color: var(--good); }

/* Lists */
.list-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--card); border-radius: 18px; padding: 14px 16px; margin-bottom: 10px; box-shadow: var(--shadow); }
.list-item .t { font-weight: 700; }
.list-item .s { font-size: 15px; color: var(--muted); }
.list-item .grow { flex: 1; min-width: 0; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search { width: 100%; padding: 14px 16px; border-radius: 16px; border: 2px solid var(--line); background: var(--card); margin-bottom: 12px; }

/* Conversation */
.convo { display: flex; flex-direction: column; height: 100vh; height: 100dvh; max-width: 640px; margin: 0 auto; }
.convo .topbar { padding: calc(10px + var(--safe-t)) 14px 8px; margin: 0; background: var(--bg); border-bottom: 1px solid var(--line); }
.convo .topbar h1 { font-size: 19px; line-height: 1.25; }
.messages { flex: 1; overflow-y: auto; padding: 16px 14px 8px; -webkit-overflow-scrolling: touch; }
.msg { display: flex; margin-bottom: 12px; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 86%; padding: 12px 15px; border-radius: 20px; font-size: 18px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user .bubble { background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; border-bottom-right-radius: 6px; }
.msg.ai .bubble { background: var(--card); box-shadow: var(--shadow); border-bottom-left-radius: 6px; }
.bubble-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.correction { background: #FFF6D8; border-left: 5px solid #F5B83D; border-radius: 14px; padding: 10px 12px; margin: 0 0 12px auto; max-width: 92%; font-size: 17px; }
.correction .wrong { text-decoration: line-through; color: var(--bad); }
.correction .right { color: var(--good); font-weight: 700; }
.correction .why { color: var(--muted); font-size: 16px; margin-top: 4px; }
.typing { display: inline-flex; gap: 5px; padding: 16px 18px; }
.typing i { width: 9px; height: 9px; border-radius: 50%; background: #D9C2B0; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: 0.2s; } .typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px calc(10px + var(--safe-b)); background: var(--bg); border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; border: 2px solid var(--line); border-radius: 22px; padding: 11px 16px; background: var(--card); max-height: 140px; min-height: 48px; font-size: 18px; line-height: 1.35; }
.composer textarea:focus { outline: none; border-color: var(--primary-2); }
.round { width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; flex: none; background: var(--card); box-shadow: var(--shadow); }
.round.send { background: linear-gradient(135deg, var(--primary-2), var(--primary)); color: #fff; }
.round.rec { background: var(--bad); color: #fff; animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(214, 69, 69, 0.5); } 100% { box-shadow: 0 0 0 14px rgba(214, 69, 69, 0); } }
.suggestions { display: grid; gap: 10px; margin-top: 8px; }
.suggestion { text-align: left; background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 12px 14px; font-size: 17px; }
.empty { text-align: center; padding: 30px 10px 10px; }
.empty .big-emoji { margin-bottom: 4px; }
.note { font-size: 14px; color: var(--muted); text-align: center; margin: 4px 0 10px; }
.error-bubble { background: var(--bad-bg); color: var(--bad); border-radius: 14px; padding: 10px 14px; margin: 0 0 12px; font-size: 16px; }

/* Settings */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 700; margin-bottom: 6px; }
.field input[type=text], .field input[type=password], .field select { width: 100%; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); background: var(--card); }
.seg { display: flex; background: #F3E4D6; border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; padding: 10px; border-radius: 11px; font-weight: 700; }
.seg button.on { background: var(--card); box-shadow: var(--shadow); }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch input { width: 26px; height: 26px; }
ol.steps { padding-left: 22px; margin: 6px 0; }
ol.steps li { margin-bottom: 6px; }

/* Stats */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.stat { background: var(--card); border-radius: 18px; padding: 14px; box-shadow: var(--shadow); text-align: center; }
.stat .n { font-size: 30px; font-weight: 800; }
.stat .l { font-size: 15px; color: var(--muted); }

/* Modal + toast */
.modal-bg { position: fixed; inset: 0; background: rgba(40, 20, 10, 0.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.modal { background: var(--bg); width: 100%; max-width: 560px; border-radius: 26px 26px 0 0; padding: 22px 20px calc(24px + var(--safe-b)); max-height: 88vh; overflow-y: auto; }
.modal h2 { margin: 0 0 10px; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: #3A2A22; color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 16px; opacity: 0; pointer-events: none; transition: all 0.25s; z-index: 60; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.update-banner { position: fixed; left: 50%; top: calc(12px + var(--safe-t)); transform: translateX(-50%) translateY(-20px); width: min(560px, calc(100vw - 32px)); display: flex; align-items: center; gap: 10px; background: #FFF1D6; border: 2px dashed #F5C26B; border-radius: 16px; padding: 12px 14px; font-size: 16px; font-weight: 600; box-shadow: var(--shadow); opacity: 0; transition: all 0.25s; z-index: 70; }
.update-banner.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.update-banner span { flex: 1; }
.update-banner button { font-size: 18px; width: 36px; height: 36px; border-radius: 50%; background: var(--card); flex: none; }

@media (max-width: 360px) {
  .grid { gap: 10px; }
  .box { padding: 14px 12px; min-height: 124px; }
  .box .name { font-size: 18px; }
}

/* Space for the free hosting badge (added on *.netlify.app only) */
.has-badge .composer { padding-bottom: calc(64px + var(--safe-b)); }
.has-badge .screen { padding-bottom: calc(90px + var(--safe-b)); }
.has-badge .modal { padding-bottom: calc(80px + var(--safe-b)); }
.has-badge .toast { bottom: calc(140px + var(--safe-b)); }
