:root {
  --ink: #3B2512;
  --ink-soft: #6B4A2B;
  --paper: #FFFDF6;
  --cream: #FFF8E7;
  --frame: #8A5A2E;
  --red: #B8232A;
  --cork: #C99A63;
  --hand: 'Gaegu', cursive;
  --title: 'Jua', sans-serif;
  --tab-h: 64px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--hand);
  font-size: 19px;
  color: var(--ink);
  background-color: var(--cork);
  background-image:
    radial-gradient(rgba(90,55,20,.28) 1px, transparent 1.5px),
    radial-gradient(rgba(255,240,210,.28) 1px, transparent 1.5px);
  background-size: 7px 7px, 11px 11px;
  background-position: 0 0, 3px 5px;
  border: 8px solid var(--frame);
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--title); font-weight: 400; margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 21px; }

#app {
  max-width: 720px;
  margin: 0 auto;
  padding: 22px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ---------- 종이 ---------- */
.paper {
  position: relative;
  background: var(--paper);
  padding: 20px 16px 16px;
  box-shadow: 2px 5px 8px rgba(60,35,10,.35);
  border-radius: 3px;
}
.lined { background-image: repeating-linear-gradient(var(--paper) 0 33px, #D6E6F2 33px 34px); }
.tilt-l { transform: rotate(-1deg); }
.tilt-r { transform: rotate(.8deg); }
.tape {
  position: absolute; width: 74px; height: 22px; top: -11px;
  background-color: rgba(255,255,255,.5);
  background-image: repeating-linear-gradient(45deg, rgba(255,150,175,.55) 0 6px, transparent 6px 12px);
}
.tape.c { left: 50%; margin-left: -37px; transform: rotate(-3deg); }
.tape.l { left: 14px; transform: rotate(-7deg); }
.tape.r { right: 14px; transform: rotate(6deg); }
.pin {
  position: absolute; top: 6px; left: 50%; margin-left: -7px;
  width: 15px; height: 15px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #FF8F8F, #C92E2E);
  box-shadow: 1px 2px 2px rgba(0,0,0,.35);
}
.on-cork { color: var(--cream); text-shadow: 0 1px 2px rgba(0,0,0,.35); }
.muted { color: var(--ink-soft); font-size: 17px; }

.avatar {
  flex: none; width: 42px; height: 42px; border-radius: 50%;
  border: 2px solid var(--ink); background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--title); font-size: 15px;
}
.row { display: flex; align-items: center; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 8px; }

/* ---------- 헤더 ---------- */
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.head .who { display: flex; align-items: center; gap: 10px; }
.link-btn {
  min-height: 44px; padding: 0 14px; border-radius: 22px;
  border: 2px solid var(--cream); background: rgba(0,0,0,.15);
  color: var(--cream); font-family: var(--title); font-size: 15px;
}

.link-btn.icon { width: 44px; padding: 0; display: flex; align-items: center; justify-content: center; }

/* ---------- 가족 카드 ---------- */
.people { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.person { padding-top: 24px; min-height: 180px; display: flex; flex-direction: column; gap: 6px; }
.person:nth-child(4n+1) { transform: rotate(-1.6deg); }
.person:nth-child(4n+2) { transform: rotate(1.4deg); }
.person:nth-child(4n+3) { transform: rotate(.8deg); }
.person:nth-child(4n+4) { transform: rotate(-1.2deg); }
.person .label { font-family: var(--title); font-size: 16px; line-height: 1.15; }
.bar { height: 12px; border: 1.5px solid var(--ink); border-radius: 7px; background: rgba(255,255,255,.65); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--ink); }
.chip {
  display: inline-block; padding: 1px 9px; border-radius: 12px;
  background: rgba(255,255,255,.6); border: 1.5px solid var(--ink); font-size: 15px;
}
.stamp {
  align-self: flex-start; margin-top: auto; padding: 2px 10px;
  border: 2.5px solid var(--red); color: var(--red); border-radius: 6px;
  font-family: var(--title); font-size: 16px; transform: rotate(-8deg);
}

/* ---------- 스티커판 ---------- */
.week { display: grid; grid-template-columns: 46px repeat(7, minmax(0, 1fr)); gap: 6px 2px; align-items: center; }
.week .d { text-align: center; font-weight: 700; font-size: 17px; }
.week .n { font-family: var(--title); font-size: 15px; }
.week .cell { display: flex; justify-content: center; }
.dash { width: 22px; height: 22px; border-radius: 50%; border: 1.5px dashed #9C7C5C; }
.star { width: 28px; height: 28px; }

/* ---------- 할 일 ---------- */
.task { display: flex; align-items: flex-start; gap: 12px; min-height: 44px; padding: 4px 0; }
.task input { width: 28px; height: 28px; margin: 0; flex: none; accent-color: #2E7D5B; }
.task .t { font-size: 21px; font-weight: 700; line-height: 1.15; }
.task.done .t { text-decoration: line-through; }
.big-btn {
  width: 100%; min-height: 60px; border: 3px solid var(--ink); border-radius: 14px;
  background: #FFE873; font-family: var(--title); font-size: 22px;
  box-shadow: 2px 4px 0 var(--ink);
}
.big-btn:active { transform: translate(2px, 3px); box-shadow: 0 1px 0 var(--ink); }
.big-btn:disabled { background: #EDE3CF; box-shadow: none; cursor: default; }
.btn {
  min-height: 46px; padding: 0 16px; border: 2.5px solid var(--ink); border-radius: 10px;
  background: var(--paper); font-family: var(--title); font-size: 17px;
}
.btn.ghost { border-style: dashed; background: transparent; }
.btn.go { background: #A8E6CF; }

/* ---------- 글쓰기 ---------- */
textarea {
  width: 100%; min-height: 96px; resize: vertical; padding: 10px 12px;
  border: 2px solid var(--ink); border-radius: 8px; background: var(--paper);
  font-size: 20px; line-height: 1.3;
}
.subjects { display: flex; gap: 8px; flex-wrap: wrap; }
.subjects button {
  min-height: 44px; padding: 0 16px; border-radius: 22px; border: 2px solid var(--ink);
  background: var(--paper); font-family: var(--title); font-size: 16px;
}
.subjects button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }

/* ---------- Grammar in Use ---------- */
.gtable { border-collapse: collapse; width: 100%; font-size: 17px; }
.gtable th, .gtable td { border: 1.5px solid var(--ink); padding: 6px 8px; text-align: left; vertical-align: top; }
.gtable th { background: rgba(0,0,0,.06); font-family: var(--title); font-weight: 400; }
.gpoints { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.gq { padding: 10px 0; border-top: 1.5px dashed rgba(0,0,0,.2); }
.choice { min-width: 64px; font-family: var(--hand); font-size: 18px; }
.choice.right { background: #A8E6CF; }
.choice.wrong { background: #FFB3B8; text-decoration: line-through; }
.choice:disabled { cursor: default; opacity: 1; }
.ok { color: #1F6B46; font-weight: 700; }

/* ---------- 쪽지 ---------- */
.feed { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 14px; align-items: start; }
.post { padding: 16px 12px 10px; min-width: 0; }
.post:nth-child(3n+1) { transform: rotate(-1.4deg); }
.post:nth-child(3n+2) { transform: rotate(1.2deg); }
.post:nth-child(3n) { transform: rotate(-.6deg); }
.post .text { font-size: 18px; line-height: 1.25; white-space: pre-wrap; overflow-wrap: anywhere; }
.day-line { display: flex; align-items: center; gap: 10px; color: var(--cream); font-family: var(--title); font-size: 15px; margin-top: 6px; }
.day-line::before, .day-line::after { content: ""; flex: 1; border-top: 2px dashed rgba(255,248,231,.7); }
.sys-list { display: flex; flex-direction: column; gap: 2px; margin-top: -10px; }
.planner .day-line { color: var(--ink-soft); }
.planner .day-line::before, .planner .day-line::after { border-top-color: rgba(31,42,68,.25); }
@media (min-width: 700px) { .feed { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.post .by { text-align: right; font-size: 15px; font-weight: 700; margin-top: 4px; }
.del {
  position: absolute; top: 2px; right: 2px; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: 0; background: transparent; color: var(--ink-soft); border-radius: 50%;
}
.del:hover { background: rgba(0,0,0,.08); color: var(--ink); }
.post { padding-right: 40px !important; }
.post.system { position: relative; }
.post.system .del { position: static; display: inline-flex; width: 32px; height: 32px; vertical-align: middle; color: var(--cream); }
.post.system { max-width: 100%; align-self: center; transform: none !important; background: transparent; box-shadow: none; padding: 0; }
.post.system .text { font-family: var(--title); font-size: 15px; color: var(--cream); text-align: center; }
.post.sticker { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; background: #FFE873; }

/* ---------- 탭 ---------- */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  background: var(--cream); border-top: 3px solid var(--frame);
  padding-bottom: env(safe-area-inset-bottom);
}
#tabs button {
  position: relative; min-height: var(--tab-h); border: 0; background: transparent;
  font-family: var(--title); font-size: 15px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
#tabs button[aria-current="page"] { background: #F3DDB3; }
#tabs svg { width: 24px; height: 24px; }
.badge {
  position: absolute; top: 6px; right: calc(50% - 22px);
  min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--red); color: #fff; font-size: 13px; line-height: 20px; font-family: var(--title);
}

/* ---------- 로그인 ---------- */
.login-people { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.login-people button {
  min-height: 120px; border: 0; border-radius: 4px; font-family: var(--title); font-size: 26px;
  box-shadow: 2px 5px 8px rgba(60,35,10,.35);
}
.login-people button:nth-child(odd) { transform: rotate(-1.5deg); }
.login-people button:nth-child(even) { transform: rotate(1.5deg); }
.pin-input {
  width: 100%; min-height: 60px; text-align: center; letter-spacing: .5em;
  font-size: 30px; border: 3px solid var(--ink); border-radius: 12px; background: var(--paper);
}
.error { color: var(--red); font-weight: 700; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 6;
  background: var(--ink); color: var(--paper); padding: 10px 18px; border-radius: 20px;
  font-family: var(--title); font-size: 16px;
}

/* ---------- 룬 (6학년): 플래너 ---------- */
body.planner {
  --ink: #1F2A44;
  --ink-soft: #4A5675;
  --paper: #FFFFFF;
  --cream: #F7F5EF;
  --frame: #1F2A44;
  --hand: 'Gowun Dodum', sans-serif;
  font-size: 17px;
  background-color: #EEF0F4;
  background-image:
    linear-gradient(rgba(31,42,68,.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(31,42,68,.07) 1px, transparent 1px);
  background-size: 20px 20px;
}
.planner .on-cork { color: var(--ink); text-shadow: none; }
.planner .paper { transform: none !important; border-radius: 10px; box-shadow: 0 1px 0 rgba(31,42,68,.12), 0 4px 14px rgba(31,42,68,.10); }
.planner .tape, .planner .pin { display: none; }
.planner .lined { background-image: none; }
.planner .link-btn { border-color: var(--ink); color: var(--ink); background: transparent; }
.planner .stamp { transform: none; border-width: 2px; font-size: 14px; }
.planner .task .t { font-size: 18px; }
.planner .post .text { font-size: 17px; }
.planner .post.system .text { color: var(--ink-soft); }
.planner .big-btn { background: var(--ink); color: #fff; box-shadow: none; border-color: var(--ink); font-size: 19px; }
.planner .big-btn:disabled { background: #C9CEDA; color: var(--ink); }
.planner #tabs button[aria-current="page"] { background: #DDE2EC; }

@media (max-width: 360px) {
  .people, .login-people { grid-template-columns: minmax(0, 1fr); }
}
@media (min-width: 700px) {
  .people { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.mini-tasks, .cheers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; font-size: 14px; line-height: 1.25; }
.mini-tasks li { display: flex; gap: 6px; align-items: flex-start; }
.mini-tasks .box { flex: none; width: 15px; height: 15px; margin-top: 1px; border: 1.5px solid currentColor; border-radius: 3px; font-size: 12px; line-height: 13px; text-align: center; font-weight: 700; }
.mini-tasks li.done > span:last-child { text-decoration: line-through; opacity: .6; }
.cheers li { font-family: var(--hand); font-size: 17px; }
.cheers li + li { border-top: 1.5px dashed rgba(0,0,0,.18); padding-top: 3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.slot { margin-top: 8px; padding: 6px 8px; border-radius: 8px; }
.slot.now { background: rgba(255, 232, 115, .55); outline: 2px dashed rgba(0,0,0,.25); }
.slot-h { font-family: var(--title); font-size: 15px; margin-bottom: 2px; }
.person .next { font-weight: 700; font-size: 14px; background: rgba(255,255,255,.55); border-radius: 6px; padding: 2px 6px; align-self: flex-start; }
.btn.small { font-size: 13px; padding: 4px 10px; min-height: 32px; align-self: flex-start; margin-top: 4px; }
.plan-day { display: flex; flex-direction: column; gap: 6px; }
.plan-day.is-today { outline: 3px dashed rgba(0,0,0,.35); }
.plan-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.plan-list li { line-height: 1.35; }
.ask { display: flex; flex-direction: column; gap: 6px; padding: 8px; border-radius: 8px; background: rgba(168, 230, 207, .45); }

.row > input { min-width: 0; } /* 폰 폭에서 입력칸이 줄어들게 (넣기 버튼이 밖으로 밀리지 않게) */

/* 도장 — 선생님 '참 잘했어요' 도장 느낌. 잉크가 고르게 안 묻은 아날로그 느낌은 마스크로, 글자는 진하게 */
.stamps { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
.stamp-mark { --r: -10deg; --mx: 0px; --my: 0px;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; width: 60px; height: 60px; padding: 4px; flex: none;
  border: 3px double #C8372D; border-radius: 50%; color: #C8372D; background: transparent;
  box-shadow: inset 0 0 0 1.5px rgba(200,55,45,.55);
  font-family: var(--title); font-size: 12.5px; font-weight: 700; line-height: 1.05; letter-spacing: -.2px;
  text-shadow: 0 0 .6px rgba(200,55,45,.9);
  transform: rotate(var(--r)); cursor: pointer; mix-blend-mode: multiply;
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%22160%22%20height%3D%22160%22%3E%3Cfilter%20id%3D%22n%22%20x%3D%220%22%20y%3D%220%22%20width%3D%22100%25%22%20height%3D%22100%25%22%3E%3CfeTurbulence%20type%3D%22fractalNoise%22%20baseFrequency%3D%221.1%22%20numOctaves%3D%222%22%20seed%3D%227%22%20result%3D%22fine%22/%3E%3CfeTurbulence%20type%3D%22fractalNoise%22%20baseFrequency%3D%220.06%22%20numOctaves%3D%222%22%20seed%3D%223%22%20result%3D%22blot%22/%3E%3CfeComposite%20in%3D%22fine%22%20in2%3D%22blot%22%20operator%3D%22arithmetic%22%20k2%3D%220.65%22%20k3%3D%220.55%22%20result%3D%22mix%22/%3E%3CfeColorMatrix%20in%3D%22mix%22%20values%3D%220%200%200%200%200%20%200%200%200%200%200%20%200%200%200%200%200%20%200%200%200%20-3.4%203.25%22/%3E%3C/filter%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20filter%3D%22url%28%23n%29%22/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A//www.w3.org/2000/svg%22%20width%3D%22160%22%20height%3D%22160%22%3E%3Cfilter%20id%3D%22n%22%20x%3D%220%22%20y%3D%220%22%20width%3D%22100%25%22%20height%3D%22100%25%22%3E%3CfeTurbulence%20type%3D%22fractalNoise%22%20baseFrequency%3D%221.1%22%20numOctaves%3D%222%22%20seed%3D%227%22%20result%3D%22fine%22/%3E%3CfeTurbulence%20type%3D%22fractalNoise%22%20baseFrequency%3D%220.06%22%20numOctaves%3D%222%22%20seed%3D%223%22%20result%3D%22blot%22/%3E%3CfeComposite%20in%3D%22fine%22%20in2%3D%22blot%22%20operator%3D%22arithmetic%22%20k2%3D%220.65%22%20k3%3D%220.55%22%20result%3D%22mix%22/%3E%3CfeColorMatrix%20in%3D%22mix%22%20values%3D%220%200%200%200%200%20%200%200%200%200%200%20%200%200%200%200%200%20%200%200%200%20-3.4%203.25%22/%3E%3C/filter%3E%3Crect%20width%3D%22100%25%22%20height%3D%22100%25%22%20filter%3D%22url%28%23n%29%22/%3E%3C/svg%3E");
  -webkit-mask-size: 160px 160px; mask-size: 160px 160px;
  -webkit-mask-position: var(--mx) var(--my); mask-position: var(--mx) var(--my); }
.stamp-mark:nth-child(3n+2) { --r: 7deg; --mx: -47px; --my: -23px; }
.stamp-mark:nth-child(3n) { --r: -4deg; --mx: -91px; --my: -60px; }
.stamp-mark { margin-right: -14px; } /* 겹쳐 찍힌 느낌 (줄이 바뀌어도 왼쪽은 안 나가게) */
.stamp-btn { position: relative; z-index: 1; }
.stamp-mark span { text-align: center; }
.stamp-mark small { font-family: var(--hand); font-size: 11px; margin-top: 2px; font-weight: 700; }
.stamp-mark.mine { border-width: 4px; }
.stamp-mark:disabled { cursor: default; opacity: 1; color: #C8372D; }
.stamp-btn { min-height: 32px; padding: 0 10px; border-radius: 16px; border: 1.5px dashed rgba(0,0,0,.4); background: rgba(255,255,255,.5);
  font-family: var(--title); font-size: 13px; color: inherit; margin-left: auto; }
.stamp-pick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.stamp-pick button { min-height: 36px; padding: 0 10px; border-radius: 18px; border: 2px solid #D2453B; color: #D2453B; background: #fff;
  font-family: var(--title); font-size: 14px; }
.stamp-pick button.on { background: #D2453B; color: #fff; }

/* 카드 열기 단계 */
.steps { list-style: none; padding: 0; margin: 8px 0; display: grid; gap: 4px; }
.steps li { display: flex; align-items: center; gap: 8px; color: #9A8F80; }
.steps li::before { content: ""; flex: none; width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; box-sizing: border-box; }
.steps li.ok { color: #2E7D4F; font-weight: 700; }
.steps li.ok::before { content: "✓"; display: grid; place-items: center; font-size: 12px; background: #2E7D4F; border-color: #2E7D4F; color: #fff; }
.steps li.now { color: inherit; font-weight: 700; }
.steps li.now::before { border-color: #E0A100; border-top-color: transparent; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .steps li.now::before { animation: none; border-top-color: #E0A100; } }
.done-card { background: #E6F4EA; position: relative; }
.done-mark { position: absolute; top: 10px; right: 12px; width: 52px; height: 52px; border-radius: 50%; border: 3px double #2E7D4F;
  color: #2E7D4F; display: grid; place-items: center; font-family: var(--title); font-size: 20px; transform: rotate(-10deg); }

/* 솔 MTH 장 퀴즈 — 손가락으로 누르기 쉽게 한 줄씩 */
.choice.wide { width: 100%; text-align: left; min-height: 52px; padding: 8px 14px; font-size: 19px; }
