@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800;900&display=swap');

:root {
  --ink: #28334a;
  --muted: #68748d;
  --pink: #d94c55;
  --pink-dark: #b83b48;
  --pink-soft: #fff0f1;
  --yellow: #ffd166;
  --blue: #287fae;
  --blue-soft: #edf8fe;
  --green: #3e9b63;
  --green-soft: #edf9f1;
  --danger: #bd3343;
  --paper: #fff;
  --bg: #f7f8fc;
  --line: #dde2ec;
  --shadow: 0 12px 30px #33426a14;
  --radius: 18px;
  --control-radius: 13px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { color-scheme: light; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: Nunito, Arial, sans-serif; }
button, input, textarea, select, summary { font: inherit; }
button { cursor: pointer; border: 0; color: inherit; }
button:disabled { cursor: not-allowed; opacity: .55; box-shadow: none !important; transform: none !important; }
:where(button, input, textarea, select, summary):focus-visible { outline: 3px solid #17688f; outline-offset: 2px; }

.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; background: linear-gradient(135deg,#fff2bc,#ffd5dd 48%,#c8edff); padding: 20px; }
.login-card { background: var(--paper); border-radius: 28px; padding: 42px; max-width: 420px; width: 100%; box-shadow: 0 25px 60px #7d587933; text-align: center; }
.logo { font-size: 34px; font-weight: 900; letter-spacing: -1px; }
.logo span, .brand-copy > span { color: var(--pink); }
.login-card > p { color: var(--muted); margin: 5px 0 26px; }
.stack-form, .settings-form, #noteForm { display: grid; gap: 16px; }
.form-error { min-height: 20px; margin: 0; color: var(--danger); font-size: 14px; font-weight: 800; }

header { min-height: 76px; background: var(--paper); display: flex; align-items: center; padding: 10px 32px; gap: 24px; box-shadow: 0 2px 15px #2632500d; position: sticky; top: 0; z-index: 30; }
.brand { display: flex; align-items: center; gap: 10px; background: transparent; font-weight: 900; font-size: 19px; line-height: 17px; text-align: left; flex: 0 0 auto; }
.brand-copy small { display: block; color: var(--muted); font-size: 11px; font-weight: 700; }
.brand-mark { display: grid; place-items: center; background: var(--yellow); width: 42px; height: 42px; border-radius: 13px; font-size: 24px; transform: rotate(-7deg); }
.weather { margin: auto; color: var(--muted); font-size: 14px; text-align: center; }
.profile { display: flex; align-items: center; gap: 10px; min-width: 0; font-weight: 800; }
#childName { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.layout { display: grid; grid-template-columns: 235px minmax(0,1fr); min-height: calc(100vh - 76px); }
nav { background: var(--paper); padding: 22px 14px; display: flex; flex-direction: column; gap: 5px; border-right: 1px solid #edf0f5; }
nav button { background: transparent; border-radius: 13px; padding: 12px 14px; text-align: left; display: flex; align-items: center; gap: 11px; min-height: 46px; font-weight: 800; color: var(--muted); transition: background .16s,color .16s,transform .16s; }
nav button:hover { background: #f3f5fa; color: var(--ink); }
nav button.active { background: var(--pink-soft); color: var(--pink-dark); box-shadow: inset 4px 0 var(--pink); }

main { padding: 34px; max-width: 1200px; width: 100%; min-width: 0; }
h1 { margin: 0 0 4px; font-size: clamp(26px,4vw,36px); letter-spacing: -.5px; }
h2, h3 { margin-top: 0; }
.subtitle { margin: 0 0 24px; color: var(--muted); }
.card { background: var(--paper); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 20px; }
.hero { position: relative; overflow: hidden; background: linear-gradient(130deg,#fff9d6,#fff); }
.hero > * { position: relative; z-index: 1; }
.hero:after { content: '★'; position: absolute; right: 22px; top: -42px; color: #ffd16655; font-size: 140px; z-index: 0; pointer-events: none; }
.pill, .today-mark { display: inline-flex; align-items: center; background: var(--blue); color: white; border-radius: 999px; padding: 5px 11px; font-size: 12px; font-weight: 900; }

.form-row { display: flex; align-items: end; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.form-row > * { flex: 1 1 150px; min-width: 0; }
.form-row > button { flex: 0 1 auto; min-width: 150px; }
.form-group { display: grid; gap: 6px; min-width: 0; text-align: left; }
.form-group > label, .field-label { color: var(--ink); font-size: 14px; font-weight: 800; }
.field { display: block; width: 100%; min-height: 48px; padding: 11px 14px; border: 2px solid var(--line); border-radius: var(--control-radius); outline: none; background: var(--paper); color: var(--ink); transition: border-color .16s,box-shadow .16s; }
.field:hover { border-color: #bbc5d5; }
.field:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #55b7e824; }
textarea.field { resize: vertical; min-height: 150px; line-height: 1.55; }
::placeholder { color: #8b96aa; opacity: 1; }

.primary, .secondary { min-height: 46px; border-radius: var(--control-radius); padding: 11px 18px; font-weight: 900; transition: background .16s,transform .12s,box-shadow .12s; }
.primary { background: var(--pink); color: #fff; box-shadow: 0 5px 0 var(--pink-dark); }
.primary:not(:disabled):hover { background: #cb414e; }
.primary:not(:disabled):active { transform: translateY(3px); box-shadow: 0 2px 0 var(--pink-dark); }
.secondary { background: #eef1f7; color: var(--ink); }
.secondary:not(:disabled):hover { background: #dfe5ef; }
.secondary.danger { background: var(--pink-soft); color: var(--danger); }
.icon-btn { width: 44px; min-width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 12px; background: #f1f3f8; font-size: 20px; }
.icon-btn:hover { background: #e3e8f1; }
.icon-btn.danger { background: var(--pink-soft); color: var(--danger); }
.icon-btn.danger:hover { background: #ffdfe3; }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-top: 16px; }

.custom-select { position: relative; min-width: 0; }
.custom-select summary { list-style: none; display: flex; align-items: center; justify-content: space-between; cursor: pointer; font-weight: 800; user-select: none; }
.custom-select summary::-webkit-details-marker { display: none; }
.custom-select summary:after { content: ''; width: 9px; height: 9px; flex: 0 0 auto; margin: 0 5px 5px 12px; border-right: 3px solid var(--pink); border-bottom: 3px solid var(--pink); transform: rotate(45deg); transition: transform .2s; }
.custom-select[open] summary { border-color: var(--blue); box-shadow: 0 0 0 3px #55b7e824; }
.custom-select[open] summary:after { margin-bottom: -5px; transform: rotate(225deg); }
.custom-select-menu { position: absolute; top: calc(100% + 8px); left: 0; right: 0; min-width: 210px; max-height: 300px; overflow-y: auto; z-index: 40; background: var(--paper); border: 2px solid var(--line); border-radius: 15px; padding: 7px; box-shadow: 0 14px 34px #33426a28; }
.custom-select-option { display: block; width: 100%; min-height: 42px; padding: 9px 12px; border-radius: 10px; background: transparent; text-align: left; font-weight: 800; }
.custom-select-option:hover, .custom-select-option.active { background: var(--pink-soft); color: var(--pink-dark); }

.lesson { display: flex; align-items: center; justify-content: space-between; gap: 14px; border: 1px solid #e7eaf2; border-radius: 14px; padding: 12px 14px; margin: 8px 0; background: #fff; }
.lesson > :first-child { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.lesson strong { display: block; }
.lesson small { display: block; color: var(--muted); margin-top: 2px; }
.day-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 16px 0 8px; font-size: 18px; font-weight: 900; }
.schedule-day { border: 2px solid transparent; border-radius: 18px; padding: 2px 12px 12px; margin-top: 12px; }
.schedule-day.current-day { border-color: var(--blue); background: var(--blue-soft); box-shadow: 0 8px 20px #55b7e820; }
.empty { padding: 22px; color: var(--muted); text-align: center; border: 2px dashed var(--line); border-radius: 14px; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit,minmax(90px,1fr)); gap: 10px; }
.stat { min-width: 0; text-align: center; background: #fff6cf; border-radius: 14px; padding: 14px 8px; }
.stat b { display: block; font-size: 24px; }
.stat small { color: var(--muted); }
.grade-badge { display: grid; place-items: center; width: 42px; height: 42px; flex: 0 0 auto; border-radius: 50%; background: var(--yellow); font-size: 20px; font-weight: 900; }

.preview { min-height: 240px; padding: 14px; border: 2px dashed var(--line); border-radius: 14px; background: #fafbfe; }
.markdown { overflow-wrap: anywhere; line-height: 1.6; }
.markdown > :first-child { margin-top: 0; }
.timer { text-align: center; font-size: clamp(38px,10vw,76px); font-weight: 900; color: var(--pink); font-variant-numeric: tabular-nums; line-height: 1.2; }
.progress { height: 12px; overflow: hidden; background: #e8ecf3; border-radius: 999px; }
.progress i { display: block; height: 100%; background: var(--green); border-radius: inherit; }
.chest-count { font-size: clamp(30px,8vw,46px); }

.timeline { position: relative; display: grid; gap: 14px; }
.achievement { display: grid; grid-template-columns: 52px minmax(0,1fr); gap: 0 14px; padding: 14px; border: 1px solid #e7eaf2; border-radius: 14px; }
.achievement .emoji { grid-row: 1 / span 3; display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; background: #fff6cf; font-size: 28px; }
.achievement h3, .achievement p { margin: 0; }
.achievement small { color: var(--muted); }
.achievement-avatar { font-size: 60px; text-align: center; margin-bottom: 18px; }

.checkbox { display: flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; min-width: 0; }
.checkbox input { width: 21px; height: 21px; flex: 0 0 auto; accent-color: var(--pink); }
.checkbox span { min-width: 0; overflow-wrap: anywhere; }
.checkbox.check span { text-decoration: line-through; color: var(--muted); }
.settings-form { max-width: 600px; }

.toast { position: fixed; left: 50%; bottom: 28px; z-index: 100; max-width: min(440px,calc(100vw - 32px)); padding: 12px 18px; border-radius: 13px; background: var(--ink); color: white; box-shadow: 0 12px 32px #25304740; font-weight: 800; text-align: center; opacity: 0; pointer-events: none; transform: translate(-50%,18px); transition: opacity .2s,transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%,0); }
.page-error { color: var(--danger); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 800px) {
  header { min-height: 66px; padding: 8px 14px; gap: 10px; }
  .weather { display: none; }
  #childName { max-width: 7rem; }
  .layout { display: block; min-height: calc(100vh - 66px); }
  main { padding: 22px 14px calc(94px + env(safe-area-inset-bottom)); }
  nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; flex-direction: row; gap: 4px; overflow-x: auto; border: 0; border-top: 1px solid var(--line); padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); scrollbar-width: none; box-shadow: 0 -4px 18px #33426a14; }
  nav::-webkit-scrollbar { display: none; }
  nav button { flex: 0 0 76px; min-height: 56px; padding: 5px; justify-content: center; flex-direction: column; gap: 2px; text-align: center; font-size: 20px; }
  nav button span:last-child { display: block; font-size: 10px; line-height: 1.1; }
  nav button.active { box-shadow: inset 0 3px var(--pink); }
  .grid { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; align-items: stretch; }
  .form-row > *, .form-row > button { flex: none; width: 100%; min-width: 0; }
  .custom-select-menu { min-width: 100%; }
  .card { padding: 18px; }
  .hero:after { right: -20px; font-size: 110px; }
}

@media (max-width: 420px) {
  .login-card { padding: 30px 20px; }
  .brand-copy small { display: none; }
  .brand-copy { font-size: 16px; }
  .brand-mark { width: 38px; height: 38px; }
  #childName { max-width: 5rem; }
  .profile { gap: 6px; }
  h1 { font-size: 27px; }
  .lesson { align-items: flex-start; }
  .stat-row { grid-template-columns: repeat(2,minmax(0,1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *:before, *:after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
