/* 매일 기억 훈련 — 단순하게: 큰 글씨, 넓은 여백, 장식 최소 */
:root {
  --bg: #f6f2e9;
  --surface: #fffdf8;
  --ink: #1d2621;
  --ink-soft: #5b655f;
  --line: #e2dccd;
  --accent: #2f5d46;
  --accent-soft: #e3ece5;
  --warm: #c9852b;
  --warm-soft: #f6e7cf;
  --good: #2f7a4d;
  --bad: #b5452f;
  --tile: #e9e2d3;
  --tile-lit: #e0a33a;
  --radius: 16px;
  /* 글자 크기: 브라우저 기본(16px)의 131% ≈ 21px × 시스템 배율(--sys) × 앱 설정(--user) */
  --sys: 1;
  --user: 1;
  --tabbar-h: 3.7rem;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { font-size: calc(131.25% * var(--sys) * var(--user)); -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); line-height: 1.5;
  word-break: keep-all; overflow-wrap: anywhere; -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; }
p { margin: 0 0 .6rem; }
a { color: var(--accent); }
img { -webkit-user-drag: none; }

.view {
  max-width: 560px; margin: 0 auto; outline: none;
  padding: 24px 18px calc(var(--tabbar-h) + var(--safe-b) + 28px);
}

/* ---------- 탭바 ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--ink-soft); font-size: .78rem; font-weight: 700;
}
.tabbar .ti { width: 1.35rem; height: 1.35rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a[aria-current="page"] { color: var(--accent); }
.tabbar a[aria-current="page"] .ti { stroke-width: 2.6; }

/* ---------- 공통 ---------- */
.muted { color: var(--ink-soft); }
.small { font-size: .85rem; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.stack > * + * { margin-top: 10px; }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 64px; padding: 12px 20px;
  border: 2px solid transparent; border-radius: 14px;
  background: var(--accent); color: #fff;
  font-size: 1.1rem; font-weight: 800; text-decoration: none;
  cursor: pointer; touch-action: manipulation;
}
.btn:active { transform: scale(.98); }
.btn.big { min-height: 76px; font-size: 1.3rem; }
.btn.secondary { background: var(--surface); color: var(--accent); border-color: var(--accent); }
.btn.ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn.warm { background: var(--warm); }
.btn.danger { background: var(--surface); color: var(--bad); border-color: var(--bad); }
.btn.inline { width: auto; min-height: 52px; font-size: 1rem; }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ---------- 오늘 ---------- */
.h-date { color: var(--ink-soft); font-weight: 700; margin: 0; }
.h-title { font-size: 1.6rem; font-weight: 800; margin: 2px 0 16px; }
.sec { font-size: 1.05rem; font-weight: 800; color: var(--ink-soft); margin: 30px 0 10px; }

.plan { list-style: none; margin: 0 0 14px; padding: 0; }
.plan li {
  display: flex; align-items: center; gap: 14px; padding: 10px 0;
  border-bottom: 1px solid var(--line); font-size: 1.15rem; font-weight: 800;
}
.plan li:last-child { border-bottom: 0; }
.plan li img { width: 3rem; height: 3rem; object-fit: contain; }
.plan li span { flex: 1; }
.plan .ck, .habit .ck {
  font-style: normal; flex: none; width: 2rem; height: 2rem; border-radius: 50%;
  display: grid; place-items: center; font-size: .95rem; color: transparent; border: 2.5px solid var(--line);
}
.plan li.done .ck { background: var(--accent); border-color: var(--accent); color: #fff; }
.plan li.done span { color: var(--ink-soft); }
.done-line { text-align: center; font-size: 1.2rem; font-weight: 800; color: var(--accent); padding: 18px 0; margin: 0; background: var(--accent-soft); border-radius: 14px; }

.habits { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.habit {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 7.2rem; padding: 10px 6px; border-radius: 16px;
  border: 2px solid var(--line); background: var(--surface);
  font-weight: 800; cursor: pointer; touch-action: manipulation;
}
.habit img { width: 3.2rem; height: 3.2rem; object-fit: contain; }
.habit .ck { position: absolute; top: 8px; right: 8px; width: 1.6rem; height: 1.6rem; font-size: .8rem; }
.habit[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }
.habit[aria-pressed="true"] .ck { background: var(--accent); border-color: var(--accent); color: #fff; }

.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.wd b { display: block; font-size: .78rem; color: var(--ink-soft); }
.wd i { display: block; width: 1.5rem; height: 1.5rem; margin: 4px auto 0; border-radius: 50%; background: var(--tile); }
.wd.on i { background: var(--accent); }
.wd.today b { color: var(--ink); }
.wd.today i { box-shadow: 0 0 0 3px var(--bg), 0 0 0 5px var(--warm); }

/* ---------- 게임 목록 ---------- */
.tiles-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  aspect-ratio: 1; padding: 12px 8px; border-radius: 20px;
  border: 2px solid var(--line); background: var(--surface);
  font-size: 1.05rem; font-weight: 800; cursor: pointer; touch-action: manipulation;
}
.tile:active { transform: scale(.97); border-color: var(--accent); }
.tile img { width: 58%; height: auto; aspect-ratio: 1; object-fit: contain; }
.badge { display: inline-block; min-width: 1.5em; padding: 0 .35em; border-radius: 99px; background: var(--bad); color: #fff; font-size: .8rem; }

/* ---------- 기록 ---------- */
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 18px; }
.stat-row div { background: var(--surface); border: 2px solid var(--line); border-radius: 16px; padding: 14px; text-align: center; }
.stat-row b { display: block; font-size: 2rem; color: var(--accent); line-height: 1.1; }
.stat-row span { color: var(--ink-soft); font-weight: 700; font-size: .9rem; }
.rec { list-style: none; margin: 0; padding: 0; }
.rec li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.rec li:last-child { border-bottom: 0; }
.rec .rn { flex: 1; font-weight: 700; }
.rec b { font-size: 1.1rem; }
.rec .rec-ic { width: 2.2rem; height: 2.2rem; object-fit: contain; }
.spark { width: 4.5rem; height: 1.4rem; }
.spark .ln { fill: none; stroke: var(--accent); stroke-width: 3; stroke-linejoin: round; stroke-linecap: round; }

/* ---------- 설정 ---------- */
.set-list { background: var(--surface); border: 2px solid var(--line); border-radius: 16px; padding: 0 16px; margin-bottom: 16px; }
.set-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 64px; padding: 10px 0; border-bottom: 1px solid var(--line);
  font-weight: 700; color: var(--ink); text-decoration: none;
}
.set-row:last-child { border-bottom: 0; }
.set-row.col { flex-direction: column; align-items: stretch; }
.set-row input:not([type=checkbox]) { width: 9rem; min-height: 48px; padding: 8px 12px; border-radius: 10px; border: 2px solid var(--line); background: var(--bg); text-align: right; }
.set-row input[type=checkbox] { width: 30px; height: 30px; accent-color: var(--accent); }
.set-row.link b { color: var(--ink-soft); font-weight: 700; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.seg button { min-height: 52px; border: 2px solid var(--line); border-radius: 12px; background: var(--bg); font-weight: 800; cursor: pointer; padding: 4px; }
.seg button:nth-child(2) { font-size: 1.1em; }
.seg button:nth-child(3) { font-size: 1.2em; }
.seg button[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.more { border-bottom: 1px solid var(--line); padding: 4px 0; }
.more summary { cursor: pointer; font-weight: 800; padding: 14px 4px; list-style: none; display: flex; justify-content: space-between; }
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: '+'; color: var(--ink-soft); font-size: 1.2rem; line-height: 1; }
.more[open] summary::after { content: '−'; }
.more p { font-size: .92rem; padding: 0 4px; }
.more .btn { margin-bottom: 10px; }
.ref { font-size: .75rem !important; color: var(--ink-soft); }
.field { display: block; }
.field span { display: block; font-weight: 700; margin-bottom: 4px; }
.field input { width: 100%; min-height: 56px; padding: 12px 14px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); }
.field input:focus, .set-row input:focus { outline: 3px solid var(--accent-soft); border-color: var(--accent); }

/* ---------- 게임 무대 ---------- */
.stage { position: fixed; inset: 0; z-index: 20; background: var(--bg); display: flex; flex-direction: column; padding-bottom: var(--safe-b); }
.stage[hidden] { display: none; }
.stage-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px;
  border-bottom: 1px solid var(--line); background: var(--surface);
}
.stage-title { font-weight: 800; font-size: 1rem; }
.btn-quit {
  min-height: 48px; padding: 6px 16px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--surface); color: var(--ink-soft); font-size: .9rem; font-weight: 700; cursor: pointer;
}
.stage-body {
  flex: 1; overflow-y: auto; width: 100%; max-width: 560px; margin: 0 auto;
  padding: 18px 16px 28px; display: flex; flex-direction: column;
}
.stage-body > .grow { flex: 1; }

.intro { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 12px 6px; }
.intro .intro-img { width: min(46vw, 11rem); height: auto; aspect-ratio: 1; object-fit: contain; margin-bottom: 14px; }
.intro h1 { font-size: 1.6rem; margin-bottom: 12px; }
.intro p { font-size: 1.15rem; margin: 0 0 4px; }
.speak-btn { margin-top: 18px; border: 2px solid var(--line); border-radius: 99px; background: var(--surface); color: var(--ink-soft); font-weight: 700; font-size: .9rem; padding: 8px 18px; cursor: pointer; }
.result-title { font-size: 1.25rem; font-weight: 800; margin: 0; }
.result-big { font-size: 2.6rem; font-weight: 900; color: var(--accent); margin: 6px 0 10px; }

.prompt { font-size: 1.3rem; font-weight: 800; text-align: center; margin: 4px 0 14px; }
.sub { text-align: center; color: var(--ink-soft); margin-bottom: 14px; }
.progress { height: 10px; border-radius: 99px; background: var(--tile); overflow: hidden; margin-bottom: 14px; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }

/* 큰 선택 버튼 */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice {
  min-height: 7.5rem; border-radius: 16px; border: 3px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  cursor: pointer; touch-action: manipulation;
}
.choice small { font-size: 1rem; font-weight: 800; color: var(--ink); }
.choice img { width: 4.4rem; height: 4.4rem; object-fit: contain; }
.choice:disabled { cursor: default; }
.choice.chosen { border-color: var(--accent); }
.choice.right { border-color: var(--good); background: #e2f1e7; }
.choice.wrong { border-color: var(--bad); background: #f7e3de; }

/* ---- 순간 포착: 카드 뒤집기 ---- */
.sp-status {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 3.3em; margin: 0 0 8px; text-align: center; font-weight: 800; font-size: 1.15rem; line-height: 1.3;
}
.sp-status small { font-size: .8rem; color: var(--ink-soft); font-weight: 700; }
.sp-status.ok { color: var(--good); }
.sp-status.bad { color: var(--bad); }
.sp-board {
  position: relative; aspect-ratio: 1; margin: 0 auto;
  width: min(100%, 400px, calc(100dvh - 23rem));
  background: var(--surface); border: 2px solid var(--line); border-radius: 20px;
  user-select: none; -webkit-user-select: none;
}
.sp-card {
  position: absolute; transform: translate(-50%, -50%); padding: 0; overflow: hidden;
  display: grid; place-items: center; border: 3px solid #fff; border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
  background-color: var(--accent);
  background-image:
    repeating-linear-gradient(45deg, rgba(255,255,255,.13) 0 6px, transparent 6px 12px),
    repeating-linear-gradient(-45deg, rgba(255,255,255,.13) 0 6px, transparent 6px 12px);
}
.sp-center { left: 50%; top: 50%; width: 27%; aspect-ratio: 3 / 4; }
.sp-board.solo .sp-center { width: 42%; }
.sp-slot { width: 16%; aspect-ratio: 3 / 4; cursor: default; }
.sp-slot:disabled { opacity: 1; }
.sp-card .face { position: absolute; inset: 0; display: grid; place-items: center; background: #fffdf8; opacity: 0; }
.sp-board.up .sp-card .face { opacity: 1; }
.sp-board.reveal .sp-card .face { transition: opacity .3s; }
.sp-card .face img { width: 84%; height: 84%; object-fit: contain; }
.sp-card .dis { display: block; width: 55%; aspect-ratio: 1; border-radius: 6px; background: #9b9384; }
.sp-card .cd { position: relative; color: #fff; font-size: 2.6rem; font-weight: 900; text-shadow: 0 2px 4px rgba(0,0,0,.35); }
.sp-slot.pickable { cursor: pointer; box-shadow: 0 0 0 4px var(--warm), 0 2px 6px rgba(0,0,0,.25); animation: pick-pulse 1.4s ease-in-out infinite; }
.sp-slot.pickable:active { transform: translate(-50%, -50%) scale(.94); }
.sp-slot.mark-ok { box-shadow: 0 0 0 5px var(--good), 0 2px 6px rgba(0,0,0,.25); }
.sp-slot.mark-bad { box-shadow: 0 0 0 5px var(--bad), 0 2px 6px rgba(0,0,0,.25); }
@keyframes pick-pulse { 50% { box-shadow: 0 0 0 7px rgba(201,133,43,.45), 0 2px 6px rgba(0,0,0,.25); } }
.sp-answer { min-height: 8.5rem; margin-top: 12px; }

/* ---- 장보기 기억 ---- */
.item-show { text-align: center; padding: 10px 0; }
.item-show .nm { font-size: 1.8rem; font-weight: 800; }
.item-show .emo-img { width: min(60vw, 15rem); height: min(60vw, 15rem); object-fit: contain; display: block; margin: 0 auto 6px; }
.grid-pick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid-pick.cols4 { grid-template-columns: repeat(4, 1fr); }
.pick {
  min-height: 96px; border-radius: 14px; border: 3px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  cursor: pointer; padding: 6px 4px; touch-action: manipulation;
}
.pick img { width: 3.4rem; height: 3.4rem; object-fit: contain; }
.pick small { font-size: .82rem; font-weight: 700; color: var(--ink); line-height: 1.2; }
.pick.sel { border-color: var(--accent); background: var(--accent-soft); }
.pick.ok { border-color: var(--good); background: #e2f1e7; }
.pick.miss { border-color: var(--warm); border-style: dashed; }
.pick.wrong { border-color: var(--bad); background: #f7e3de; }

/* ---- 어디 뒀더라: 방 그림 ---- */
.scene {
  position: relative; aspect-ratio: 2 / 3; margin: 0 auto;
  width: min(100%, calc((100dvh - 15rem) * 2 / 3)); max-width: 460px;
  border-radius: 16px; overflow: hidden; border: 2px solid var(--line);
  user-select: none; -webkit-user-select: none;
}
.scene-bg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.scene-obj, .scene-spot {
  position: absolute; width: 19%; aspect-ratio: 1; transform: translate(-50%, -50%);
  display: flex; align-items: center; justify-content: center;
}
.scene-obj img, .scene-spot img { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 0 3px #fff) drop-shadow(0 2px 3px rgba(0,0,0,.35)); }
/* 외우는 화면: 방은 한 톤 죽이고, 물건은 흰 원 배지로 띄운다 */
.scene.study .scene-bg { filter: saturate(.45) brightness(.82); }
.scene-obj {
  width: 24%; border-radius: 50%; background: #fff; border: 4px solid #d9771f;
  box-shadow: 0 0 0 3px rgba(255,255,255,.85), 0 4px 12px rgba(0,0,0,.45);
  animation: obj-pop .45s cubic-bezier(.2, 1.6, .4, 1) both;
}
.scene-obj img { width: 80%; height: 80%; filter: none; }
@keyframes obj-pop {
  0% { transform: translate(-50%, -50%) scale(.2); opacity: 0; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}
.scene .tag {
  position: absolute; left: 50%; top: 100%; transform: translate(-50%, -30%);
  white-space: nowrap; font-size: .74rem; font-weight: 800; line-height: 1.2;
  background: rgba(255,253,248,.95); color: var(--ink); border: 1.5px solid var(--line);
  border-radius: 99px; padding: 1px 7px; pointer-events: none;
}
.scene-spot { border-radius: 50%; border: 3px dashed var(--accent); background: rgba(255,253,248,.55); cursor: pointer; padding: 0; touch-action: manipulation; }
.scene-spot:active { background: rgba(227,236,229,.9); }
.scene-spot.ok { border: 4px solid var(--good); background: #fff; }
.scene-spot.ok img { width: 80%; height: 80%; }
.scene-spot.wrong { border: 4px solid var(--bad); background: rgba(247,227,222,.85); }
.ask-obj { text-align: center; margin-bottom: 10px; gap: 8px; }

/* ---- 순서 따라하기 ---- */
.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 420px; margin: 0 auto; width: 100%; }
.tiles .t { aspect-ratio: 1; border-radius: 18px; border: 0; background: var(--tile); cursor: pointer; transition: background .08s; touch-action: manipulation; }
.tiles .t.lit { background: var(--tile-lit); box-shadow: 0 0 0 4px #f3d49b inset; }
.tiles .t.tap { background: var(--accent); }
.tiles.locked .t { cursor: default; }
.seq-status { text-align: center; font-weight: 800; font-size: 1.2rem; min-height: 2em; margin: 6px 0 10px; }

/* ---- 기억 카드 복습 ---- */
.flash { background: var(--surface); border: 2px solid var(--line); border-radius: 20px; padding: 26px 18px; text-align: center; margin-bottom: 16px; }
.flash .q { font-size: 1.4rem; font-weight: 800; }
.flash .a { font-size: 1.6rem; font-weight: 800; color: var(--accent); margin-top: 14px; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
