/* 잔디 (habit) — 습관 잔디밭 / 디자인 시스템 */

:root {
  --bg: #f4f8f3;
  --surface: #ffffff;
  --surface-2: #eef3ec;
  --ink: #16241c;
  --muted: #5f7367;
  --line: #dde7da;
  --accent: #2ea043;
  --accent-strong: #216e39;
  --streak: #f59e0b;

  --i0: #e9efe6;
  --i1: #9be9a8;
  --i2: #40c463;
  --i3: #30a14e;
  --i4: #216e39;

  --r-cell: 3px;
  --r-chip: 8px;
  --r-card: 16px;
  --r-modal: 20px;

  --sh-card: 0 1px 2px rgba(20,40,30,.06), 0 4px 16px rgba(20,40,30,.05);
  --sh-modal: 0 12px 40px rgba(20,40,30,.22);

  --font-display: 'Baloo 2', 'Pretendard', system-ui, sans-serif;
  --font-body: 'Pretendard', system-ui, -apple-system, 'Segoe UI', sans-serif;

  --maxw: 880px;
}
/* ===== 3-way theme (Light/Dark/System) — base :root above = native LIGHT. Opposite (dark) WCAG-aware auto-generated (contrast-solving ink/accent vs worst-case surface). ===== */
:root[data-theme="dark"]{
  --bg: #171e15;
  --surface: #2c2c2c;
  --surface-2: #0d100c;
  --ink: #9cc3ad;
  --muted: #859a8e;
  --line: rgba(255,255,255,0.12);
  --accent: #2d9b41;
  --accent-strong: #000000;
  --streak: #bc7908;
  --i0: #6e915d;
  --i1: #229c37;
  --i2: #309b4c;
  --i3: #2e9b4b;
  --i4: #2e9b50;
}












* { box-sizing: border-box; }
[hidden] { display: none !important; } /* 명시적 display가 [hidden]을 무력화하지 않도록 */

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 480px at 100% -10%, #e7f3e6 0%, transparent 60%),
    radial-gradient(900px 420px at -10% 0%, #eaf4ea 0%, transparent 55%),
    var(--bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--accent); color: #fff; padding: 8px 12px; border-radius: 0 0 8px 0;
  z-index: 100;
}
.skip-link:focus { left: 0; }

main {
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 16px 64px;
}

/* ---------- 헤더 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  max-width: var(--maxw);
  margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  background: rgba(244,248,243,.82);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { font-size: 26px; line-height: 1; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 22px; letter-spacing: .2px; }
.brand-sub { font-size: 12px; color: var(--muted); font-weight: 600; }
.topbar-actions { display: flex; gap: 6px; }

.icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink);
  border-radius: var(--r-chip); padding: 8px 10px; cursor: pointer;
  font: inherit; font-weight: 600; font-size: 14px; min-height: 40px;
  transition: background .15s ease, border-color .15s ease, transform .1s ease;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn .icon-label { font-size: 13px; }
.icon-btn.close { padding: 6px 9px; }

/* ---------- 요약 ---------- */
.summary {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin: 18px 0;
}
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
  padding: 14px 12px; text-align: center; box-shadow: var(--sh-card);
}
.stat-num { font-family: var(--font-display); font-weight: 800; font-size: 30px; line-height: 1.05; }
.stat-num.streak { color: var(--streak); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; font-weight: 600; }

/* ---------- 패널 ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--sh-card);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.panel-title { font-family: var(--font-display); font-weight: 700; font-size: 18px; margin: 0; }
.hint { font-size: 12px; color: var(--muted); font-weight: 600; }

/* ---------- 버튼 ---------- */
.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: var(--r-chip); padding: 10px 16px; min-height: 44px;
  transition: background .15s ease, border-color .15s ease, transform .1s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn.sm { min-height: 38px; padding: 8px 12px; font-size: 14px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: #b42318; border-color: #f4c4bf; }
.btn.danger:hover { background: #fdecea; }

/* ---------- 오늘 체크 리스트 ---------- */
.today-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.today-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.today-row .emoji { font-size: 22px; width: 30px; text-align: center; }
.today-row .meta { flex: 1; min-width: 0; }
.today-row .name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.today-row .sub { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.streak-chip { color: var(--streak); font-weight: 700; }
.goal-chip { background: var(--surface-2); border-radius: 999px; padding: 1px 8px; font-weight: 600; }
.goal-chip.met { background: #def7e6; color: var(--accent-strong); }

.toggle {
  flex: none; width: 52px; height: 52px; border-radius: 14px; cursor: pointer;
  border: 2px solid var(--cell-line, var(--line)); background: var(--surface-2);
  display: grid; place-items: center; font-size: 22px; color: transparent;
  transition: transform .14s cubic-bezier(.2,.8,.2,1), background .18s ease, border-color .18s ease;
}
.toggle:hover { border-color: var(--cell-base, var(--accent)); }
.toggle.done {
  background: var(--cell-base, var(--accent)); border-color: var(--cell-base, var(--accent));
  color: #fff;
}
.toggle.pop { animation: pop .22s cubic-bezier(.2,.8,.2,1); }
@keyframes pop {
  0% { transform: scale(.8); }
  55% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

/* ---------- 빈 상태 ---------- */
.empty { text-align: center; padding: 28px 12px; }
.empty-emoji { font-size: 44px; }
.empty-title { font-weight: 800; font-size: 17px; margin: 8px 0 2px; }
.empty-sub { color: var(--muted); margin: 0 0 16px; }

/* ---------- 습관 카드 ---------- */
.habit-cards { display: grid; grid-template-columns: 1fr; gap: 14px; }
.habit-card { border: 1px solid var(--line); border-radius: 14px; padding: 14px; background: var(--surface); }
.habit-card .hc-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.habit-card .hc-emoji { font-size: 20px; }
.habit-card .hc-name { font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.habit-card .hc-edit {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; padding: 5px 9px; color: var(--muted);
}
.habit-card .hc-edit:hover { background: var(--surface-2); color: var(--ink); }
.hc-stats { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.stat-pill { background: var(--surface-2); border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700; }
.stat-pill b { font-family: var(--font-display); }
.stat-pill.fire { color: var(--streak); }

/* ---------- 히트맵 ---------- */
.heat-scroll { overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.heat {
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr);
  gap: 3px; width: max-content;
}
.heat .cell {
  width: 13px; height: 13px; border-radius: var(--r-cell);
  background: var(--i0); border: 1px solid rgba(0,0,0,.04);
}
.heat .cell.spacer { background: transparent; border: none; }
.overall-heat .heat .cell { width: 15px; height: 15px; }

.overall-caption { font-size: 13px; color: var(--muted); margin: 0 0 12px; }

/* 강도 클래스는 inline style(background)로 칠함; 범례만 고정 */
.legend { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); font-weight: 600; }
.legend .lg { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend .lg0 { background: var(--i0); }
.legend .lg1 { background: var(--i1); }
.legend .lg2 { background: var(--i2); }
.legend .lg3 { background: var(--i3); }
.legend .lg4 { background: var(--i4); }

/* ---------- 모달 ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(16,28,22,.42);
  display: grid; place-items: end center;
  padding: 0; animation: fade .2s ease;
}
@media (min-width: 560px) { .modal-backdrop { place-items: center; padding: 24px; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%; max-width: 460px; background: var(--surface);
  border-radius: var(--r-modal) var(--r-modal) 0 0; box-shadow: var(--sh-modal);
  max-height: 92vh; overflow: auto; animation: slideup .24s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 560px) { .modal { border-radius: var(--r-modal); } }
@keyframes slideup { from { transform: translateY(24px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }

.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.modal-head h3 { margin: 0; font-family: var(--font-display); font-weight: 700; font-size: 18px; }
.modal-body { padding: 18px; }

.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.input {
  width: 100%; font: inherit; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink);
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; background: var(--surface); }
.input.count { width: 64px; text-align: center; }

.emoji-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.emoji-grid button {
  font-size: 18px; aspect-ratio: 1; border: 1px solid var(--line); background: var(--surface);
  border-radius: 9px; cursor: pointer; display: grid; place-items: center;
}
.emoji-grid button:hover { background: var(--surface-2); }
.emoji-grid button[aria-checked="true"] { border-color: var(--accent); background: #def7e6; box-shadow: 0 0 0 2px rgba(46,160,67,.25); }

.color-row { display: flex; flex-wrap: wrap; gap: 8px; }
.color-row button {
  width: 30px; height: 30px; border-radius: 999px; cursor: pointer; border: 2px solid transparent;
}
.color-row button[aria-checked="true"] { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px currentColor; }

.goal-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; font-weight: 600; }
.seg input { accent-color: var(--accent); }
.goal-suffix { color: var(--muted); font-weight: 600; }

.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.modal-actions .spacer { flex: 1; }

.data-note, .data-body .data-note { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.data-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.data-actions .btn { flex: 1; min-width: 130px; }
.rule { border: none; border-top: 1px solid var(--line); margin: 16px 0; }

.help-list { margin: 0 0 14px; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
.help-list li { font-size: 14px; }
.help-foot { color: var(--muted); font-size: 13px; margin: 0; }

/* ---------- 공유 캔버스 ---------- */
.canvas-wrap { display: grid; place-items: center; background: var(--surface-2); border-radius: 12px; padding: 12px; margin-bottom: 14px; }
#shareCanvas { width: 100%; max-width: 360px; height: auto; border-radius: 10px; box-shadow: var(--sh-card); }

/* ---------- 토스트 ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(12px);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 999px;
  font-weight: 600; font-size: 14px; z-index: 80; box-shadow: var(--sh-modal);
  opacity: 0; transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- 푸터 ---------- */
.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 8px 0; }

/* ---------- 반응형 ---------- */
@media (min-width: 720px) {
  .habit-cards { grid-template-columns: 1fr 1fr; }
  .icon-btn .icon-label { display: inline; }
}
@media (max-width: 380px) {
  .stat-num { font-size: 26px; }
  .icon-btn .icon-label { display: none; }
  .heat .cell { width: 11px; height: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* i18n language switcher — 라이트 토큰으로 덮어쓴다 (기본값은 중립 반투명이라 안 보일 수 있음). */
.topbar .i18n-switch {
  --i18n-switch-bg: var(--surface);
  --i18n-switch-border: var(--line);
  --i18n-switch-fg: var(--ink);
  --i18n-switch-active-bg: #def7e6;
  --i18n-switch-active-fg: var(--accent-strong);
  --i18n-switch-menu-bg: var(--surface);
  --i18n-switch-menu-border: var(--line);
  --i18n-switch-shadow: var(--sh-modal);
}

/* dark-mode override for hardcoded body gradient (refinement) */
:root[data-theme="dark"] body{ background: var(--bg); }
:root[data-theme="dark"] .topbar{ background: rgba(20,16,24,.82); }
