:root {
  --bg: #FFF6EC;
  --card: #FFFFFF;
  --ink: #3A302B;
  --muted: #8C7F77;
  --line: #F0E4D7;
  --primary: #F08A4B;
  --primary-dark: #D9733A;
  --primary-soft: #FFE9DA;
  --ok: #3BA776;
  --ok-soft: #E2F5EA;
  --mid: #EFA62B;
  --mid-soft: #FFF2D6;
  --hard: #E58A82;
  --hard-soft: #FCE8E5;
  --radius: 18px;
  --shadow: 0 2px 10px rgba(120, 80, 40, .07);
  --tabbar-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR",
    "Hiragino Sans", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary-dark); text-decoration: none; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: 1.1rem 0 .5rem; color: var(--muted); }
code { background: var(--primary-soft); padding: 0 .3em; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.right { text-align: right; }
.pre { white-space: pre-wrap; }

/* ---------- layout ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(255, 246, 236, .92);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner {
  max-width: 760px; margin: 0 auto; padding: .8rem 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.topbar-title { font-size: 1.35rem; margin: 0; letter-spacing: -.01em; }
.container {
  max-width: 760px; margin: 0 auto;
  padding: .25rem 1rem calc(var(--tabbar-h) + var(--safe-b) + 28px);
}
.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.1rem; margin-bottom: .9rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.grid-2 .card { margin-bottom: .9rem; }
.grid-2-lg { display: grid; gap: 0; }
@media (min-width: 640px) {
  .grid-2-lg { grid-template-columns: 1fr 1fr; gap: .9rem; }
}

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); height: calc(var(--tabbar-h) + var(--safe-b));
  box-shadow: 0 -2px 12px rgba(120, 80, 40, .06);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); font-size: .72rem; gap: 2px; min-width: 0;
}
.tabbar .ti { font-size: 1.35rem; line-height: 1; filter: grayscale(.6); opacity: .75; }
.tabbar a.active { color: var(--primary-dark); font-weight: 700; }
.tabbar a.active .ti { filter: none; opacity: 1; transform: scale(1.08); }

/* ---------- buttons / form ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  border: 0; border-radius: 14px; padding: .75rem 1.1rem; font-size: 1rem; font-weight: 600;
  cursor: pointer; font-family: inherit; text-decoration: none; min-height: 48px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:active { background: var(--primary-dark); }
.btn-ghost { background: var(--primary-soft); color: var(--primary-dark); }
.btn-warn { background: var(--hard-soft); color: #B4554D; }
.btn-sm { padding: .4rem .8rem; min-height: 36px; font-size: .88rem; border-radius: 11px; }
.btn-block { display: flex; width: 100%; margin-top: .6rem; }
.btn-xl { min-height: 58px; font-size: 1.12rem; border-radius: 18px; }
.danger { color: #C05A52 !important; }
.link-btn { background: none; border: 0; color: var(--muted); font-size: .9rem; padding: .6rem; cursor: pointer; font-family: inherit; text-decoration: underline; }
.icon-btn { display: inline-flex; width: 44px; height: 44px; align-items: center; justify-content: center; border-radius: 50%; background: var(--primary-soft); font-size: 1.5rem; color: var(--primary-dark); }
.icon-btn.disabled { opacity: .3; }

.field { margin-bottom: .8rem; }
.field label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: .3rem; color: #5A4D46; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=time], select, textarea {
  width: 100%; font-size: 16px; /* iOS zoom 방지 */
  padding: .7rem .8rem; border: 1.5px solid var(--line); border-radius: 12px; background: #FFFCF8;
  color: var(--ink); font-family: inherit; min-height: 48px; -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 2rem; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.row-3 { display: grid; grid-template-columns: 1fr; gap: 0 .7rem; }
@media (min-width: 520px) { .row-3 { grid-template-columns: repeat(3, 1fr); } }
.row-btns { display: flex; gap: .5rem; flex-wrap: wrap; }
.check { display: flex; gap: .5rem; align-items: flex-start; font-size: .9rem; margin: .4rem 0; }
.check input { width: 20px; height: 20px; margin-top: 2px; }

/* chips (checkbox) */
.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip { position: relative; cursor: pointer; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-flex; align-items: center; min-height: 42px; padding: .45rem .9rem; border-radius: 999px;
  border: 1.5px solid var(--line); background: #FFFCF8; font-size: .92rem; user-select: none; -webkit-user-select: none;
  transition: all .12s;
}
.chip input:checked + span { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); font-weight: 700; }
.chip input:checked + span::before { content: "✓"; margin-right: .3rem; }
.chip-lg span { min-height: 50px; font-size: 1rem; padding: .55rem 1.05rem; }
.chips-sm .chip span { min-height: 38px; font-size: .84rem; padding: .35rem .75rem; }

/* ○△× segmented */
.evalseg { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.ev { cursor: pointer; position: relative; }
.ev input { position: absolute; opacity: 0; pointer-events: none; }
.ev span {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  min-height: 72px; border-radius: 16px; border: 2px solid var(--line); background: #FFFCF8; transition: all .12s;
}
.ev b { font-size: 1.7rem; line-height: 1.1; }
.ev small { font-size: .76rem; color: var(--muted); }
.ev.ok b { color: var(--ok); } .ev.mid b { color: var(--mid); } .ev.hard b { color: var(--hard); }
.ev.ok input:checked + span { background: var(--ok-soft); border-color: var(--ok); }
.ev.mid input:checked + span { background: var(--mid-soft); border-color: var(--mid); }
.ev.hard input:checked + span { background: var(--hard-soft); border-color: var(--hard); }
.ev input:checked + span small { color: var(--ink); font-weight: 600; }
.evalseg-sm .ev span { min-height: 54px; border-radius: 12px; }
.evalseg-sm .ev b { font-size: 1.3rem; }
.evalseg-sm .ev small { font-size: .7rem; }

.st-details { margin-top: .6rem; display: grid; gap: .6rem; }
.st-detail { border: 1.5px dashed var(--line); border-radius: 14px; padding: .7rem; background: #FFFDFA; }
.st-name { font-weight: 700; margin-bottom: .45rem; }
.causes { margin-top: .6rem; }
.causes .muted { margin-bottom: .35rem; }

/* condition */
.conditions { display: grid; grid-template-columns: repeat(5, 1fr); gap: .4rem; }
.cond { cursor: pointer; position: relative; }
.cond input { position: absolute; opacity: 0; pointer-events: none; }
.cond span { display: flex; flex-direction: column; align-items: center; padding: .55rem .1rem; border-radius: 14px; border: 2px solid var(--line); background: #FFFCF8; min-height: 76px; justify-content: center; }
.cond em { font-style: normal; font-size: 1.7rem; line-height: 1.1; }
.cond small { font-size: .68rem; text-align: center; color: var(--muted); word-break: keep-all; }
.cond input:checked + span { border-color: var(--primary); background: var(--primary-soft); }
.cond input:checked + span small { color: var(--ink); font-weight: 700; }

.duration { background: var(--primary-soft); border-radius: 12px; padding: .6rem .8rem; color: var(--primary-dark); }
.note { background: #FFF0E0; border-radius: 12px; padding: .6rem .8rem; font-size: .9rem; margin: .4rem 0 .8rem; }
.child-note { background: var(--mid-soft); }
.sticky-submit {
  position: sticky; bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px); z-index: 5;
  padding-top: .3rem;
}
.sticky-submit .btn { box-shadow: 0 6px 18px rgba(240, 138, 75, .35); }

/* flash */
.flash { border-radius: 14px; padding: .75rem 1rem; margin: .4rem 0 .9rem; font-weight: 600; }
.flash-ok { background: var(--ok-soft); color: #23704D; }
.flash-warn { background: var(--hard-soft); color: #A4473F; }

/* ---------- home ---------- */
.date-chip, .pill { display: inline-block; background: var(--primary-soft); color: var(--primary-dark); border-radius: 999px; padding: .2rem .7rem; font-size: .82rem; font-weight: 700; white-space: nowrap; }
.card-hero { display: flex; align-items: center; gap: .9rem; }
.card-hero > div:nth-child(2) { flex: 1; }
.hero-emoji { font-size: 2.3rem; width: 58px; height: 58px; display: flex; align-items: center; justify-content: center; border-radius: 18px; background: var(--primary-soft); flex-shrink: 0; }
.card-hero.done .hero-emoji { background: var(--ok-soft); }
.card-hero.rest .hero-emoji { background: #E9F4E4; }
.hero-title { font-weight: 800; font-size: 1.1rem; }
.hero-sub { color: var(--muted); font-size: .9rem; }
.stat { text-align: center; }
.stat-label { font-size: .88rem; color: var(--muted); font-weight: 600; }
.stat-value { font-size: 2.1rem; font-weight: 800; line-height: 1.2; }
.stat-value small { font-size: 1rem; margin-left: 2px; color: var(--muted); }
.stat-note { font-size: .74rem; color: var(--muted); }
.progress { height: 12px; background: #F6EBDF; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, #F6A86F, var(--primary)); border-radius: 999px; transition: width .4s; }
.week-strip { display: grid; grid-template-columns: repeat(7, 1fr); gap: .3rem; margin: .9rem 0 .6rem; }
.wd { display: flex; flex-direction: column; align-items: center; gap: .2rem; font-size: .78rem; color: var(--muted); }
.wd-dot { width: 32px; height: 32px; border-radius: 50%; background: #F6EBDF; display: flex; align-items: center; justify-content: center; font-size: .85rem; font-weight: 800; }
.wd.done .wd-dot { background: var(--ok); color: #fff; }
.wd.sun:not(.done) .wd-dot { background: #EEF6EA; font-size: .8rem; }
.wd.today .wd-dot { box-shadow: 0 0 0 2.5px var(--primary); }
.wd.today .wd-label { color: var(--primary-dark); font-weight: 800; }
.wd.future .wd-dot { opacity: .5; }
.mini-stats, .stats-4 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.mini-stats > div, .stats-4 > div { background: #FFF9F3; border-radius: 12px; padding: .6rem .7rem; display: flex; flex-direction: column; }
.mini-stats span, .stats-4 span { font-size: .78rem; }
.mini-stats b, .stats-4 b { font-size: 1.15rem; }
@media (min-width: 560px) { .stats-4 { grid-template-columns: repeat(4, 1fr); } }

.evalbar { display: flex; height: 34px; border-radius: 12px; overflow: hidden; gap: 3px; }
.evalbar-seg { display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; font-size: .85rem; min-width: 34px; }
.evalbar-seg.ok { background: var(--ok); } .evalbar-seg.mid { background: var(--mid); } .evalbar-seg.hard { background: var(--hard); }
.legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; margin-top: .6rem; font-size: .86rem; }
.legend > span { display: inline-flex; align-items: center; gap: .3rem; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.dot.ok { background: var(--ok); } .dot.mid { background: var(--mid); } .dot.hard { background: var(--hard); }

.stage { border-left: 6px solid var(--line); }
.stage-ok { border-left-color: var(--ok); }
.stage-mid { border-left-color: var(--mid); }
.stage-hard { border-left-color: var(--hard); }
.stage-title { font-size: 1.12rem; font-weight: 800; margin-bottom: .25rem; }
.stage-ok .stage-title { color: #23704D; } .stage-mid .stage-title { color: #B47812; } .stage-hard .stage-title { color: #B4554D; }
.stage-text { margin: 0 0 .4rem; }

.rank { margin: .3rem 0 0; padding: 0; list-style: none; counter-reset: rank; }
.rank li { counter-increment: rank; display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.rank li:last-child { border-bottom: 0; }
.rank li::before { content: counter(rank); width: 24px; height: 24px; border-radius: 50%; background: var(--primary-soft); color: var(--primary-dark); font-weight: 800; font-size: .8rem; display: flex; align-items: center; justify-content: center; }
.rank-name { font-weight: 700; flex: 1; }
.rank-sub { width: 100%; padding-left: 30px; font-size: .8rem; color: var(--muted); }
.tag { display: inline-block; border-radius: 999px; padding: .1rem .55rem; font-size: .8rem; font-weight: 700; margin: 0 .15rem .2rem 0; }
.tag.ok { background: var(--ok-soft); color: #23704D; }
.tag.mid { background: var(--mid-soft); color: #A86E0E; }
.tag.hard { background: var(--hard-soft); color: #B4554D; }
.empty { color: var(--muted); text-align: center; padding: .8rem 0; margin: 0; }

/* ---------- today: mode toggle & child ---------- */
.mode-toggle { display: grid; grid-template-columns: 1fr 1fr; background: #F6E8DA; border-radius: 16px; padding: 4px; margin-bottom: .9rem; }
.mode-toggle button { border: 0; background: transparent; padding: .7rem; border-radius: 12px; font-size: .98rem; font-weight: 700; color: var(--muted); font-family: inherit; min-height: 46px; cursor: pointer; }
.mode-toggle button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

.child-card { text-align: center; padding: 1.6rem 1.1rem 1.8rem; }
.child-hello { font-size: 1.35rem; font-weight: 800; margin-bottom: .5rem; }
.level-pill { display: inline-block; background: #EAF3FF; color: #3C6DB0; border-radius: 999px; padding: .2rem .9rem; font-weight: 700; font-size: .9rem; margin-bottom: 1rem; }
.goal-row { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; margin: .4rem 0 1.4rem; }
.goal { background: #FFF6EC; border-radius: 16px; padding: .9rem .5rem; display: flex; flex-direction: column; align-items: center; gap: .2rem; }
.goal span { font-size: 1.9rem; }
.goal b { font-size: 1.05rem; }
.big-btn {
  display: block; width: 100%; border: 0; border-radius: 22px; padding: 1.15rem; font-size: 1.3rem; font-weight: 800;
  background: var(--primary); color: #fff; cursor: pointer; font-family: inherit; box-shadow: 0 8px 20px rgba(240, 138, 75, .3);
  margin-top: .4rem;
}
.big-btn:active { transform: scale(.98); }
.big-btn.green { background: var(--ok); box-shadow: 0 8px 20px rgba(59, 167, 118, .3); }
.big-btn:disabled { opacity: .6; }
.timer { font-size: 4rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: .02em; color: var(--primary-dark); line-height: 1.1; margin: .4rem 0; }
.done-title { font-size: 1.6rem; font-weight: 800; margin: .3rem 0 .4rem; }
#child-done .field { text-align: left; margin-top: 1rem; }
.star-burst { font-size: 5.5rem; line-height: 1; margin: .5rem 0; }
.star-burst span { display: inline-block; animation: star-pop 1.1s cubic-bezier(.2, 1.6, .4, 1) both, star-glow 2.4s ease-in-out 1.1s infinite; }
@keyframes star-pop {
  0% { transform: scale(0) rotate(-180deg); opacity: 0; }
  70% { transform: scale(1.25) rotate(10deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}
@keyframes star-glow {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(255, 200, 60, 0)); transform: scale(1); }
  50% { filter: drop-shadow(0 0 18px rgba(255, 200, 60, .9)); transform: scale(1.06); }
}
.confetti { position: fixed; top: -10px; width: 10px; height: 14px; border-radius: 3px; z-index: 50; pointer-events: none; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); opacity: .7; } }

/* ---------- records ---------- */
.month-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: .8rem; }
.month-title { font-weight: 800; font-size: 1.1rem; text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-h { text-align: center; font-size: .78rem; color: var(--muted); padding: .2rem 0; font-weight: 700; }
.cal-h.sun { color: #7FAF6E; }
.cal-c { aspect-ratio: 1 / 1.05; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--ink); background: #FFFBF6; position: relative; }
.cal-c.out { background: transparent; }
.cal-c.sun .cal-d { color: #7FAF6E; }
.cal-d { font-size: .92rem; font-weight: 600; }
.cal-m { height: 16px; font-size: .75rem; line-height: 16px; }
.cal-m i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.cal-c.studied { background: var(--primary-soft); }
.cal-c.lv-ok { background: var(--ok-soft); } .cal-c.lv-ok .cal-m i { background: var(--ok); }
.cal-c.lv-mid { background: var(--mid-soft); } .cal-c.lv-mid .cal-m i { background: var(--mid); }
.cal-c.lv-hard { background: var(--hard-soft); } .cal-c.lv-hard .cal-m i { background: var(--hard); }
.cal-c.today { box-shadow: inset 0 0 0 2px var(--primary); }
.cal-c.sel { box-shadow: inset 0 0 0 2.5px var(--ink); }
.detail { margin: 0; display: grid; grid-template-columns: 1fr; }
.detail dt { font-size: .8rem; color: var(--muted); font-weight: 700; margin-top: .7rem; }
.detail dd { margin: .15rem 0 0; }
.sublist { margin: 0; padding: 0; list-style: none; }
.sublist li { padding: .15rem 0; }

/* ---------- reports ---------- */
.subj-table { width: 100%; border-collapse: collapse; margin-top: .9rem; font-size: .92rem; }
.subj-table th, .subj-table td { padding: .45rem .3rem; text-align: center; border-bottom: 1px solid var(--line); }
.subj-table th:first-child, .subj-table td:first-child { text-align: left; }
.subj-table th.ok { color: var(--ok); } .subj-table th.mid { color: var(--mid); } .subj-table th.hard { color: var(--hard); }
.recommend { background: linear-gradient(135deg, #FFF3E3, #FFFFFF); border: 1.5px solid #FBDDBF; }
.recommend p { margin: 0; font-size: 1rem; }
.day-list { list-style: none; margin: 0; padding: 0; }
.day-list a { display: grid; grid-template-columns: 1.4fr 1fr auto; gap: .5rem; align-items: center; padding: .7rem .2rem; border-bottom: 1px solid var(--line); color: var(--ink); min-height: 48px; }
.day-list li:last-child a { border-bottom: 0; }
.day-list a span { font-size: .88rem; color: var(--muted); }
.day-list a.current { background: var(--primary-soft); border-radius: 10px; padding-left: .5rem; padding-right: .5rem; }

/* ---------- settings ---------- */
.tb { padding: .8rem 0; border-bottom: 1px solid var(--line); }
.tb-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.tb-name { flex: 1; min-width: 0; }
.tb-meta { margin-top: .35rem; }
.tb-form { padding: .8rem; background: #FFFAF4; border-radius: 14px; margin: .6rem 0; }
.add-tb summary { cursor: pointer; padding: .8rem 0 .2rem; font-weight: 700; color: var(--primary-dark); list-style: none; }
.add-tb summary::-webkit-details-marker { display: none; }
.restore-form { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--line); }

/* ---------- login ---------- */
.login-page .container { padding-bottom: 2rem; }
.login-wrap { max-width: 340px; margin: 0 auto; text-align: center; padding-top: calc(8vh + env(safe-area-inset-top, 0px)); }
.login-logo { font-size: 3.5rem; }
.login-title { margin: .2rem 0; font-size: 1.6rem; }
.pin-dots { display: flex; justify-content: center; gap: 1rem; margin: 1.4rem 0 .6rem; }
.pin-dots span { width: 18px; height: 18px; border-radius: 50%; border: 2.5px solid var(--primary); transition: background .1s; }
.pin-dots span.on { background: var(--primary); }
.pin-input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.login-error { color: #B4554D; font-weight: 600; margin: .4rem 0; }
.pin-dots.shake { animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: .8rem; margin-top: 1.4rem; }
.key { height: 68px; border-radius: 20px; border: 0; background: #fff; box-shadow: var(--shadow); font-size: 1.6rem; font-weight: 700; color: var(--ink); font-family: inherit; cursor: pointer; }
.key:active { background: var(--primary-soft); }
.key-sub { font-size: .95rem; color: var(--muted); background: transparent; box-shadow: none; }
