/* ===== 색과 크기 변수 =====
   차분하고 포근한 색만 사용 (빨간색 없음).
   다크 모드는 아래 @media 안에서 이 변수 값만 바꾼다. */
:root {
  --bg: #f6f3ee;          /* 배경: 따뜻한 미색 */
  --surface: #ffffff;     /* 입력창 등 바탕 */
  --text: #3d3a36;        /* 기본 글씨 */
  --text-soft: #7a746c;   /* 보조 글씨 */
  --accent: #6b8f8a;      /* 주요 버튼: 차분한 청록 */
  --accent-soft: #e3ece9; /* 연한 청록 바탕 */
  --accent-text: #ffffff;
  --border: #ddd6cc;

  /* 상자 그림 색 */
  --box-body: #d9b98c;
  --box-lid: #c9a574;
  --box-slot: #6f5a40;
  --box-tape: #b8915c;    /* 상자 테이프 (몸통보다 조금 짙은 갈색) */
  --note-paper: #fffaf0;  /* 쪽지 */
  --note-line: #c9bfae;
  --chart-muted: #b7c9c5; /* 그래프의 강조하지 않는 막대 (가장 많은 막대만 --accent) */

  --tabbar-h: 64px;
  /* 아이폰 아래쪽 홈 바 높이 (다른 기기는 0) */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ===== 다크 모드: 기기 설정이 어두운 화면이면 자동으로 =====
   눈이 편하도록 새까만 색 대신 따뜻한 짙은 갈색 계열 */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1c1a;
    --surface: #2a2825;
    --text: #ece6de;
    --text-soft: #a8a097;
    --accent: #8db5ae;
    --accent-soft: #2e3a38;
    --accent-text: #15201e;  /* 밝은 청록 버튼 위에는 어두운 글씨 */
    --border: #3f3a35;

    --box-body: #b39670;
    --box-lid: #a2845e;
    --box-slot: #3a2e21;
    --box-tape: #8d6f4a;
    --note-paper: #efe7da;
    --note-line: #b3a690;
    --chart-muted: #4f605d;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;  /* 휴대폰에서 누를 때 생기는 파란 네모 없애기 */
}

/* hidden 속성이 붙은 요소는 display 설정과 상관없이 항상 숨긴다 */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  font-size: 17px;
  line-height: 1.5;
}

/* 화면 가운데에 좁게 (모바일 우선) */
.app {
  max-width: 480px;
  margin: 0 auto;
  /* 아래쪽: 하단 탭 + "힘들 땐 109" 링크 자리만큼 비워둔다 */
  padding: 24px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 56px);
}

/* ===== 화면 전환: is-active 붙은 화면만 보인다 ===== */
.screen {
  display: none;
  position: relative;  /* 설정 버튼을 우측 상단에 놓기 위해 */
}
.screen.is-active {
  display: block;
}

.title {
  font-size: 1.5rem;
  margin: 8px 0 4px;
  text-align: center;
}

.subtitle,
.placeholder {
  color: var(--text-soft);
  text-align: center;
  margin: 0 0 16px;
}

.placeholder {
  margin-top: 48px;
}

/* ===== 버튼 공통 ===== */
.btn-primary,
.btn-secondary {
  min-height: 52px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 12px;
  cursor: pointer;
}

.btn-primary {
  color: var(--accent-text);
  background: var(--accent);
  border: none;
}

/* 데이터 지우기처럼 조심해야 하는 버튼: 빨간색 대신 테두리만 */
.btn-secondary {
  color: var(--text-soft);
  background: transparent;
  border: 1px solid var(--border);
}

.btn-primary:active,
.btn-secondary:active {
  opacity: 0.85;
}

.btn-block {
  display: block;
  width: 100%;
}

/* 상자 화면 우측 상단 설정 버튼 (톱니바퀴) */
.settings-btn {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  background: none;
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.back-btn {
  min-height: 48px;
  padding: 0 8px;
  font-size: 1rem;
  color: var(--text-soft);
  background: none;
  border: none;
  cursor: pointer;
}

/* ===== 상자 그림 ===== */
.box-art {
  display: flex;
  justify-content: center;
  margin: 24px 0 8px;
}
.box-body { fill: var(--box-body); }
.box-lid  { fill: var(--box-lid); }
.box-slot { fill: var(--box-slot); }
.box-tape { fill: var(--box-tape); }   /* 상자 가운데 테이프 */

/* 뚜껑: 상자를 누르면 왼쪽 아래 모서리를 축으로 살짝 들린다 */
.box-lid-group {
  transform-box: fill-box;
  transform-origin: left bottom;
  transition: transform 0.3s ease;
}
.box-button.is-open .box-lid-group {
  transform: translateY(-8px) rotate(-7deg);
}

/* 온보딩 사용법 그림 */
.onboard-howto-art svg {
  width: 170px;
  height: auto;
}

/* ===== 핵심 장면: 쪽지가 상자 안으로 쏙 들어가는 애니메이션 =====
   JS가 #box-art에 is-dropping을 붙이면 한 번 재생된다 (약 0.9초) */
.note-paper {
  fill: var(--note-paper);
  stroke: var(--note-line);
  stroke-width: 1;
}
.note-line {
  stroke: var(--note-line);
  stroke-width: 1.5;
  stroke-linecap: round;
}

/* 평소에는 쪽지가 안 보인다 */
.note {
  opacity: 0;
  transform-box: fill-box;       /* 쪽지 자기 자신을 기준으로 돌리기 */
  transform-origin: center;
}
.box-shape {
  transform-box: fill-box;
  transform-origin: center bottom;
}

.box-art.is-dropping .note {
  animation: note-drop 0.9s ease-in-out forwards;
}
/* 쪽지가 다 들어간 순간 상자가 살짝 "꿀꺽" */
.box-art.is-dropping .box-shape {
  animation: box-gulp 0.3s ease-out 0.75s;
}

@keyframes note-drop {
  0%   { opacity: 0; transform: translateY(-14px) rotate(-10deg); }  /* 위에서 살며시 나타나서 */
  25%  { opacity: 1; transform: translateY(0) rotate(-6deg); }
  45%  { opacity: 1; transform: translateY(4px) rotate(0deg); }       /* 상자 위에서 반듯하게 */
  100% { opacity: 1; transform: translateY(84px) rotate(0deg); }      /* 뚜껑 뒤로 쏙 들어간다 */
}

@keyframes box-gulp {
  0%   { transform: scale(1, 1); }
  40%  { transform: scale(1.04, 0.96); }
  100% { transform: scale(1, 1); }
}

.box-count {
  text-align: center;
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 4px;
}

/* 걱정 시간까지 남은 시간 */
.countdown {
  text-align: center;
  color: var(--text-soft);
  margin: 0 0 16px;
}

/* 걱정 시간이 되면 나오는 안내 카드 */
/* 글자와 버튼을 한 줄에 나란히 놓아 납작하게 (작은 휴대폰에서도 입력창이 밀리지 않게) */
.ready-card {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--accent-soft);
  border-radius: 16px;
  padding: 12px 12px 12px 16px;
  margin: 0 0 16px;
  text-align: left;
}
.ready-card .btn-primary {
  flex-shrink: 0;
  width: auto;
  min-height: 44px;
  padding: 0 16px;
}
.ready-card p {
  flex: 1;
  margin: 0;
  font-size: 0.95rem;
  word-break: keep-all;
  font-weight: 600;
}

/* ===== 입력창 + 버튼 ===== */
.worry-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.worry-form input,
.time-input,
.text-input {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  font-size: 1rem;  /* 16px 이상이면 아이폰에서 자동 확대가 안 된다 */
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.worry-form input:focus,
.time-input:focus,
.text-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ===== 음성 입력: 입력창 오른쪽 마이크 버튼 (PLAN.md 11번) ===== */
.worry-input-row {
  display: flex;
  gap: 8px;
}
.worry-input-row input {
  flex: 1;
  min-width: 0;   /* 좁은 화면에서 입력창이 마이크 버튼을 밀어내지 않게 */
}
.voice-btn {
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
}
.voice-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* 듣는 중: 청록색 버튼 + 은은하게 퍼지는 테두리 */
.voice-btn.is-listening {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
  animation: voice-pulse 1.6s ease-out infinite;
}
@keyframes voice-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(107, 143, 138, 0.5); }
  100% { box-shadow: 0 0 0 12px rgba(107, 143, 138, 0); }
}
/* 처음 한 번 보이는 안내 (소리가 브라우저 회사 서버로 갈 수 있음) */
.voice-notice {
  padding: 12px 14px;
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: keep-all;
  background: var(--accent-soft);
  border-radius: 12px;
}
.voice-notice p {
  margin: 0 0 10px;
}
.voice-notice-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.voice-notice-actions button {
  min-height: 44px;
  font-size: 0.9rem;
}
/* 듣는 중·잘 안 됐을 때 한 줄 안내 */
.voice-status {
  margin: -2px 0 0;
  font-size: 0.85rem;
  color: var(--text-soft);
  word-break: keep-all;
}

/* ===== 예상 가능성 고르기 (9단계) ===== */
.likelihood-label {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0 0 6px;
}
.likelihood-label small {
  font-weight: 400;
  color: var(--text-soft);
  margin-left: 4px;
}
/* 5개를 한 줄에 */
.likelihood-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}
.likelihood-btn {
  min-height: 48px;
  padding: 4px 2px;
  font-size: 0.8rem;
  line-height: 1.25;
  font-family: inherit;
  word-break: keep-all;   /* "거의 안 / 일어날 듯"처럼 단어 단위로 줄바꿈 */
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
}
.likelihood-btn[aria-pressed="true"] {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
.likelihood-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ===== 안내 문구: 화면 맨 위에 잠깐 떠올랐다 사라짐 =====
   화면 위쪽에 고정해서, 작은 휴대폰에서도 버튼이나 아래 띠에 가려지지 않는다 */
.toast {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 12px);
  left: 50%;
  transform: translate(-50%, -8px);
  z-index: 10;
  width: max-content;
  max-width: calc(100% - 32px);
  margin: 0;
  padding: 10px 18px;
  text-align: center;
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  opacity: 0;
  pointer-events: none;  /* 떠 있는 동안에도 아래 버튼을 누를 수 있게 */
  transition: opacity 0.3s, transform 0.3s;
}
.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ===== 걱정 시간 화면 ===== */

/* 잠김 / 비어 있음 / 열기 전 / 요약 */
.time-state {
  text-align: center;
  padding-top: 32px;
}
.state-icon {
  font-size: 2.5rem;
  margin: 0;
}
.state-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 8px 0;
}
.state-text {
  color: var(--text-soft);
  margin: 0 0 28px;
}
.summary-counts {
  font-size: 1.05rem;
  margin: 16px 0;
  line-height: 1.8;
}

/* 진행 상황 + 남은 시간 */
.session-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--text-soft);
  margin: 16px 0 12px;
}
.session-timer {
  font-variant-numeric: tabular-nums;  /* 숫자 폭을 같게 해서 흔들리지 않게 */
  font-weight: 600;
  color: var(--accent);
}

/* 걱정 카드 */
.worry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 20px;
}
.card-date {
  color: var(--text-soft);
  font-size: 0.85rem;
  margin: 0 0 8px;
}
.card-text {
  font-size: 1.15rem;
  margin: 0;
  word-break: keep-all;      /* 한국어 단어 중간에서 줄이 안 바뀌게 */
  overflow-wrap: anywhere;
}

/* ===== 마무리 1분 (10단계) ===== */
.closing-choice {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  text-align: left;
}
.closing-title {
  font-weight: 600;
  text-align: center;
  margin: 0 0 12px;
}

/* 호흡: 가운데 원 */
.breath-stage {
  position: relative;
  height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 8px 0;
}
.breath-circle {
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: var(--accent-soft);
  border: 2px solid var(--accent);
  transform: scale(0.55);
}
/* 10초에 한 번: 4초 동안 커지고(들이쉬기) 6초 동안 작아진다(내쉬기). 6번 = 1분 */
.breath-circle.is-breathing {
  animation: breathe 10s ease-in-out 6;
}
@keyframes breathe {
  0%   { transform: scale(0.55); }
  40%  { transform: scale(1); }
  100% { transform: scale(0.55); }
}
.breath-count {
  position: absolute;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.breath-phase {
  text-align: center;
  font-size: 1.2rem;
  font-weight: 600;
  margin: 0 0 4px;
}

/* 다 마친 화면: 문구와 버튼 사이 띄우기 */
#closing-done-view .btn-primary {
  margin-top: 24px;
}

/* 감각 찾기: 큰 숫자 */
.senses-number {
  font-size: 4rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--accent);
  margin: 16px 0 0;
}

/* 실제로 일어났는지 확인 (9단계) */
.check-title {
  text-align: center;
  margin-top: 16px;
}
.check-progress {
  text-align: center;
  color: var(--text-soft);
  margin: 0 0 12px;
}
.check-likelihood {
  margin: 10px 0 0;
  font-size: 0.85rem;
  color: var(--accent);
}
.check-likelihood:empty {
  display: none;
}

/* 주제 고르기 (8단계) */
.topic-picker {
  margin-bottom: 16px;
}
.topic-label {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 0 0 8px;
}
.topic-label small {
  font-weight: 400;
  color: var(--text-soft);
  margin-left: 4px;
}
/* 3개씩 두 줄로 반듯하게 */
.topic-chips {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.topic-chip {
  min-height: 44px;
  padding: 0 8px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
/* 고른 주제 */
.topic-chip[aria-pressed="true"] {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}
.topic-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 세 가지 선택 버튼 */
.choice-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.choice-btn {
  min-height: 60px;
  padding: 12px 16px;
  text-align: left;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
}
.choice-btn small {
  display: block;
  font-weight: 400;
  font-size: 0.85rem;
  color: var(--text-soft);
}
.choice-btn:active {
  background: var(--accent-soft);
}

/* 할 일 입력 / 다시 넣기 질문 */
.card-sub {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.card-sub .field-label {
  margin-top: 0;
}

/* ===== 기록 화면 ===== */

/* 위쪽 작은 탭: 이번 주 / 패턴 / 지난 기록 */
.subtabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  margin: 12px 0 4px;
  background: var(--accent-soft);
  border-radius: 14px;
}
.subtab {
  flex: 1;
  min-height: 44px;
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-soft);
  background: none;
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
.subtab[aria-selected="true"] {
  color: var(--text);
  background: var(--surface);
  font-weight: 700;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.subtab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* "이번 주" 맨 위 한 줄: 지금까지 맡긴 걱정 중 ○%가 걱정 시간 전에 사라졌어요 */
.stat-line {
  margin: 16px 0 0;
  font-weight: 600;
  text-align: center;
  word-break: keep-all;
}
.stat-line strong {
  color: var(--accent);
  font-size: 1.3rem;
}

/* 지난 기록 "더 보기" */
.session-more {
  margin-top: 10px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
}
.stat-label {
  color: var(--text-soft);
  font-size: 0.9rem;
  margin: 0;
}
.stat-number {
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0;
}

/* ===== 상자 화면 배경 하늘 (13단계) =====
   하늘색, 땅 색, 글씨·박스 색, 해·달 위치는 JS(renderSky)가 시간에 맞춰 계산해서
   body에 CSS 변수로 넣는다. 상자 화면에서만 쓰이고, 라이트·다크 모드와 상관없이 시간을 따른다 */

/* 하늘: 화면 전체 뒤에 깔린다. 하늘색은 지평선(--horizon)까지 그라데이션 */
.home-sky {
  display: none;
  position: fixed;    /* 상자 화면은 한 화면에 고정이라 하늘도 화면에 붙인다 */
  inset: 0;
  z-index: 0;
  overflow: hidden;   /* 지평선 아래로 내려간 해·달은 잘려서 안 보인다 */
  background: linear-gradient(to bottom, var(--sky-top, #6aa9e0) 0px, var(--sky-bottom, #c4e2f6) var(--horizon, 60vh));
}
body.is-home .home-sky {
  display: block;
}
/* 상자 화면은 한 화면에 고정: 손가락으로 끌어도 페이지가 위아래·옆으로 움직이지 않게
   (html에도 is-home을 붙인다. 아이폰 사파리는 body만 막으면 튕김이 남는다.
    한 손가락 끌기는 app.js의 touchmove에서도 막는다. 두 손가락 확대는 막지 않는다) */
html.is-home,
body.is-home {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}
/* 하단 탭과 109 띠는 앱 내용(하늘·땅)보다 항상 위에 */
.tabbar,
.help-link {
  z-index: 5;
}
/* 앱 내용은 하늘 위에 */
.app {
  position: relative;
  z-index: 1;
}
/* 상자 화면의 앱 내용은 화면에 붙여 둔다 (스크롤할 내용이 아예 없게).
   키보드를 닫은 뒤 페이지가 올라간 채 남는 일도 없어진다 */
body.is-home .app {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  padding-top: 12px;
  padding-bottom: 0;   /* 아래 여백은 땅이 대신 채운다 */
}

/* 상자 화면은 딱 화면 높이: 위는 하늘, 아래 4분의 1은 땅 */
#screen-box.is-active {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 460px;
}
/* 하늘 위쪽 글씨: 부제, 개수, 남은 시간 */
.home-top {
  text-align: center;
  padding-top: 6px;
}
#screen-box .subtitle {
  margin: 4px 44px 14px;   /* 오른쪽 위 설정 버튼과 겹치지 않게 양옆을 비운다 */
  word-break: keep-all;    /* 줄이 바뀌어도 단어 중간에서 끊기지 않게 */
}
/* 하늘 위의 글씨·설정 버튼: 하늘 밝기에 맞춘 글씨 색 + 은은한 테두리 그림자 */
#screen-box .subtitle,
#screen-box .box-count,
#screen-box .countdown {
  color: var(--sky-ink, var(--text));
  text-shadow: var(--sky-shadow, none);
  transition: color 1.2s;
}
#screen-box .settings-btn {
  color: var(--sky-ink, var(--text-soft));
  transition: color 1.2s;
}
/* 남는 하늘: 상자를 언덕까지 아래로 밀어 준다 */
.home-spacer {
  flex: 1;
  min-height: 8px;
}

/* 상자 버튼: 누르면 걱정 넣는 카드가 올라온다.
   언덕 꼭대기(땅 위 26px)에 상자 바닥이 5px쯤 묻히도록 땅에서 12px 띄운다
   (그림 아래쪽 9px은 빈 공간이라 실제 상자 바닥은 땅 위 21px) */
.box-button {
  position: relative;
  z-index: 2;            /* 언덕보다 앞에 */
  display: block;
  width: max-content;
  margin: 0 auto 12px;
  padding: 0;
  background: none;
  border: none;
  border-radius: 16px;
  cursor: pointer;
  /* 걱정 카드가 열려 있고 카드 위 공간이 좁으면(휴대폰 키보드) 상자를 작게 (JS가 --box-scale을 넣음).
     바닥을 기준으로 줄여서 언덕 위에 놓인 채로 작아진다 */
  transform: scale(var(--box-scale, 1));
  transform-origin: 50% 100%;
  transition: transform 0.3s ease;
}
.box-button svg {
  display: block;
  width: 180px;
  height: auto;
}
.box-button:focus-visible {
  outline: 3px solid var(--sky-ink, var(--accent));
  outline-offset: 4px;
}
/* 첫 걱정을 넣기 전: 상자가 살짝 들썩인다 */
.box-button.is-hinting svg {
  animation: box-bob 2.4s ease-in-out infinite;
}
@keyframes box-bob {
  0%, 60%, 100% { transform: translateY(0); }
  70%           { transform: translateY(-7px); }
  80%           { transform: translateY(0); }
  88%           { transform: translateY(-3px); }
}

/* 땅: 화면 아래쪽 4분의 1. 화면 양옆 끝까지 넓히고, 안의 내용은 원래 폭 그대로 */
.home-ground {
  position: relative;
  flex: 0 0 25vh;
  flex-basis: 25dvh;
  margin: 0 calc(50% - 50vw);
  padding: 22px calc(50vw - 50%) 0;
  background: var(--ground, #b9c6a6);
  transition: background-color 1.2s;
  overflow-x: clip;   /* 화면 밖으로 넓게 그린 언덕 양 끝은 잘라서 가로로 끌리지 않게 (위쪽 언덕 꼭대기는 그대로 보인다) */
}
/* "상자를 눌러 걱정을 넣어요" (첫 걱정 전까지만) */
.box-hint {
  margin: 0;
  text-align: center;
  font-weight: 600;
  color: var(--text);
}

/* ===== 걱정 넣는 카드: 화면 아래에서 올라온다 ===== */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 19;
  background: rgba(20, 24, 30, 0.18);
  opacity: 0;
  transition: opacity 0.3s;
}
.sheet-backdrop.is-open {
  opacity: 1;
}
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: var(--kb, 0px);   /* 휴대폰 키보드가 올라오면 그 위에 붙는다 (JS가 높이를 넣음) */
  z-index: 20;
  max-width: 480px;
  margin: 0 auto;
  padding: 4px 16px calc(16px + var(--safe-bottom));
  color: var(--text);
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
  transform: translateY(110%);
  transition: transform 0.3s ease;
  /* 실제로 보이는 높이(--vvh, JS가 넣음)보다 커지면 카드 안에서 스크롤 (가로 화면 + 키보드 같은 아주 좁은 경우) */
  max-height: calc(var(--vvh, 100vh) - 8px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet.is-open {
  transform: translateY(0);
}
/* 키보드가 떠 있으면 아이폰 홈 바 여백이 필요 없다 (그만큼 카드가 낮아진다) */
.sheet.has-kb {
  padding-bottom: 12px;
}
/* 키보드가 떠 있으면 카드를 조금 납작하게 (카드 위 상자 자리를 조금이라도 더 남긴다. 누르는 곳은 44px 이상 유지) */
.sheet.has-kb .sheet-head {
  min-height: 44px;
}
.sheet.has-kb .likelihood-btn {
  min-height: 44px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
}
.sheet-title {
  margin: 0;
  font-size: 1rem;
}
.sheet-close {
  width: 44px;
  height: 44px;
  margin-right: -10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-soft);
  background: none;
  border: none;
  border-radius: 12px;
  cursor: pointer;
}
.sheet-close:focus-visible {
  outline: 2px solid var(--accent);
}
/* 카드가 열려 있는 동안 상자 화면을 살짝 올려서 상자가 카드 위로 보이게 (JS가 --lift를 넣음) */
#screen-box {
  transform: translateY(calc(-1 * var(--lift, 0px)));
  transition: transform 0.3s ease;
}
/* 상자가 놓인 언덕 꼭대기: 땅 위로 둥글게 솟은 부분 */
.home-ground::before {
  content: "";
  position: absolute;
  left: -10%;
  right: -10%;
  top: -26px;
  height: 52px;
  border-radius: 50%;
  background: inherit;
}
/* 뒤쪽의 먼 언덕 (조금 흐린 색) */
.home-ground::after {
  content: "";
  position: absolute;
  left: 35%;
  right: -30%;
  top: -46px;
  height: 90px;
  border-radius: 50%;
  background: var(--ground-far, #a9b8a0);
  z-index: -1;
}
.home-ground > * {
  position: relative;  /* 언덕 꼭대기 모양보다 글씨·입력창이 위에 오게 */
}

/* 장식용 별 (밤에만 보인다. 밝기는 JS가 --star-alpha로 조절). 지평선 위에만 */
.sky-stars {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: var(--horizon, 60vh);
  opacity: var(--star-alpha, 0);
}
.sky-star {
  position: absolute;
  border-radius: 50%;
  background: #fffbe8;
  animation: twinkle 4s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
}
@keyframes twinkle {
  0%, 100% { opacity: 0.9; }
  50%      { opacity: 0.35; }
}

/* 해와 달: 가운데 점을 기준으로 위치를 잡는다 (left는 %, top은 px로 JS가 넣음) */
.sky-body {
  position: absolute;
  border-radius: 50%;
  transform: translate(-50%, -50%);
}
.sky-sun {
  width: 34px;
  height: 34px;
  background: var(--sun-color, #ffd76a);
  box-shadow: 0 0 18px 6px var(--sun-glow, rgba(255, 215, 106, 0.55));
}
.sky-moon {
  width: 26px;
  height: 26px;
  background: #f3efe0;
  box-shadow: 0 0 14px 3px rgba(243, 239, 224, 0.35);
}


/* ===== 걱정 패턴 보기 (12단계) =====
   가장 많은 막대 하나만 청록(--accent)으로 강조하고 나머지는 흐리게.
   막대는 얇게(최대 24px), 끝만 4px 둥글게, 바닥선은 가는 실선. 값 글자는 막대 색이 아닌 글자 색 */
.pattern-summary {
  margin: 0 0 10px;
  font-weight: 600;
  line-height: 1.6;
  word-break: keep-all;
}
.pattern-summary p {
  margin: 0;
}
.chart-card {
  margin-bottom: 10px;
}
.chart-title {
  margin: 0 0 8px;
  font-size: 0.9rem;
  font-weight: 600;
}
.chart-title small {
  font-weight: 400;
  color: var(--text-soft);
  margin-left: 4px;
}

/* 세로 막대 (요일별, 시간대별) */
.col-chart {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
}
.col-item {
  display: flex;
  flex-direction: column;
  align-items: center;
}
/* 막대가 서는 자리: 높이 고정, 아래에 바닥선 */
.col-plot {
  width: 100%;
  height: 96px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.col-bar {
  width: 22px;
  min-height: 2px;            /* 0개여도 바닥에 얇게 보이도록 */
  background: var(--chart-muted);
  border-radius: 4px 4px 0 0; /* 끝만 둥글게, 바닥은 반듯하게 */
}
.col-item.is-max .col-bar {
  background: var(--accent);
}
/* 가장 많은 막대 위에만 숫자 */
.col-value {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 2px;
}
.col-label {
  margin-top: 6px;
  font-size: 0.8rem;
  color: var(--text-soft);
}
.col-item.is-max .col-label {
  color: var(--text);
  font-weight: 700;
}

/* 가로 막대 (주제별 비율) */
.row-chart {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.row-item {
  display: grid;
  grid-template-columns: 3em 1fr 3em;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}
.row-label {
  color: var(--text-soft);
}
.row-track {
  border-left: 1px solid var(--border); /* 바닥선 */
}
.row-bar {
  height: 16px;
  min-width: 2px;
  background: var(--chart-muted);
  border-radius: 0 4px 4px 0;
}
.row-item.is-max .row-bar {
  background: var(--accent);
}
.row-item.is-max .row-label {
  color: var(--text);
  font-weight: 700;
}
.row-value {
  text-align: right;
  font-weight: 700;
  color: var(--text);
}

/* 숫자로 보기 (표) */
.pattern-table {
  margin-top: 4px;
}
.pattern-table summary {
  min-height: 44px;
  display: flex;
  align-items: center;
  color: var(--text-soft);
  font-size: 0.9rem;
  text-decoration: underline;
  cursor: pointer;
}
.pattern-table table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 12px;
  font-size: 0.85rem;
}
.pattern-table caption {
  text-align: left;
  font-weight: 600;
  padding: 4px 0;
}
.pattern-table th,
.pattern-table td {
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.pattern-table td {
  text-align: right;
  font-variant-numeric: tabular-nums;  /* 표의 숫자는 세로로 줄 맞춤 */
}

/* ===== 주간 리포트 카드 (14단계) ===== */
.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.week-nav-label {
  font-weight: 700;
}
/* 카드를 옆으로 나란히 놓고, 넘기면 한 장씩 딱 멈춘다 */
.week-cards {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;          /* 가로 스크롤 막대 숨기기 */
  border-radius: 16px;
}
.week-cards::-webkit-scrollbar {
  display: none;
}
.week-cards:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.week-card {
  flex: 0 0 100%;
  scroll-snap-align: center;
  background: var(--accent-soft);
  border-radius: 16px;
  padding: 16px;
}
.week-range {
  margin: 0 0 12px;
  font-size: 0.9rem;
  color: var(--text-soft);
  text-align: center;
}
.week-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.week-tile {
  background: var(--surface);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
}
.week-num {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
  word-break: keep-all;
}
.week-num.is-text {
  font-size: 1.15rem;   /* 주제 이름은 숫자보다 조금 작게 */
  line-height: 1.6;
}
.week-lbl {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-soft);
}
.week-predict {
  margin: 12px 0 0;
  font-size: 0.9rem;
  text-align: center;
  word-break: keep-all;
}
.week-save {
  margin-top: 10px;
}

/* ===== 걱정 시간 지킨 날 달력 (11단계) ===== */
.calendar {
  padding: 12px;
}
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.cal-title {
  margin: 0;
  font-weight: 700;
}
.cal-nav {
  width: 44px;
  height: 44px;
  font-size: 1.5rem;
  line-height: 1;
  font-family: inherit;
  color: var(--text);
  background: none;
  border: none;
  border-radius: 12px;
  cursor: pointer;
}
.cal-nav:disabled {
  color: var(--border);
  cursor: default;
}
.cal-nav:focus-visible {
  outline: 2px solid var(--accent);
}
.cal-weekdays,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
}
.cal-weekdays span {
  font-size: 0.8rem;
  color: var(--text-soft);
  padding-bottom: 6px;
}
.cal-day {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  font-size: 0.9rem;
  color: var(--text-soft);
}
/* 도장: 걱정 시간을 가진 날 */
.cal-day.is-stamped span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
}
/* 오늘: 숫자 아래 작은 점 */
.cal-day.is-today {
  color: var(--text);
  font-weight: 700;
}
.cal-day.is-today::after {
  content: "";
  position: absolute;
  bottom: 1px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}
.cal-summary {
  margin: 8px 0 0;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-soft);
}

/* 예상 vs 현실: 두 숫자를 나란히 */
.predict-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.predict-grid .stat-label {
  word-break: keep-all;
}
.stat-number small {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-soft);
}
.predict-note {
  color: var(--text-soft);
  font-size: 0.85rem;
  margin: 8px 0 0;
}

.section-title {
  font-size: 1.05rem;
  margin: 28px 0 10px;
}

.empty-text {
  color: var(--text-soft);
  margin: 0;
}

/* 할 일 목록 */
.todo-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.todo-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 52px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
}
.todo-item input {
  width: 22px;
  height: 22px;
  margin: 2px 0 0;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.todo-action {
  display: block;
  overflow-wrap: anywhere;
}
.todo-worry {
  display: block;
  font-size: 0.85rem;
  color: var(--text-soft);
  overflow-wrap: anywhere;
}
/* 다 한 일은 흐리게 + 줄 긋기 */
.todo-item.is-done .todo-action {
  text-decoration: line-through;
  color: var(--text-soft);
}

/* 지난 걱정 시간 목록 */
.session-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.session-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.session-item summary {
  min-height: 52px;
  padding: 12px 16px;
  cursor: pointer;
  list-style: none;      /* 기본 ▶ 표시 숨기기 */
}
.session-item summary::-webkit-details-marker {
  display: none;
}
.session-date {
  display: block;
  font-weight: 600;
}
.session-counts {
  display: block;
  font-size: 0.9rem;
  color: var(--text-soft);
}
.session-worries {
  list-style: none;
  margin: 0;
  padding: 0 16px 12px;
}
.session-worries li {
  padding: 10px 0;
  border-top: 1px solid var(--border);
  overflow-wrap: anywhere;
}
.worry-status {
  display: block;
  font-size: 0.85rem;
  color: var(--accent);
}

/* ===== 온보딩 ===== */
.onboard-step {
  padding-top: 24px;
}

.onboard-text {
  text-align: center;
  color: var(--text-soft);
  margin: 12px 0 32px;
}

/* ===== 설정·온보딩 입력 항목 ===== */
.field-label {
  display: block;
  font-weight: 600;
  margin: 20px 0 8px;
}

/* 15분 / 20분 / 30분 고르는 버튼 묶음 */
.segmented {
  display: flex;
  gap: 8px;
  margin-bottom: 28px;
}
.segmented label {
  flex: 1;
}
.segmented input {
  /* 동그라미는 숨기고 글자 버튼만 보이게 */
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
}
.segmented input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.segmented input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
/* 5개짜리(하늘 시간 바꿔보기)는 글씨를 조금 작게, 간격도 좁게 */
.segmented-small {
  gap: 6px;
  margin-bottom: 8px;
}
.segmented-small span {
  min-height: 48px;
  padding: 0 2px;
  font-size: 0.85rem;
  text-align: center;
  word-break: keep-all;
}
.field-hint {
  margin: 0 0 28px;
  font-size: 0.85rem;
  color: var(--text-soft);
}

/* 언제든 열기 켜기/끄기 */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 52px;
  margin-bottom: 28px;
  cursor: pointer;
}
.switch-row small {
  display: block;
  color: var(--text-soft);
  font-size: 0.85rem;
}
.switch-row input {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 32px 0 24px;
}

/* ===== 하단 탭 ===== */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);  /* 아이폰 홈 바와 겹치지 않게 */
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

/* 온보딩 중에는 하단 탭을 숨긴다 */
body.hide-tabbar .tabbar {
  display: none;
}

.tab {
  flex: 1;
  font-size: 0.95rem;
  color: var(--text-soft);
  background: none;
  border: none;
  cursor: pointer;
}

.tab.is-active {
  color: var(--accent);
  font-weight: 700;
}

/* ===== 안전 기능 (5단계) ===== */

/* 모든 화면 아래 작은 "힘들 땐 109" 링크: 하단 탭 바로 위에 붙은 가로 띠
   (배경을 칠해서 화면을 내려도 글자가 이 밑으로 가려지고 겹치지 않는다) */
.help-link {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 6px 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-soft);
  background: var(--bg);
  text-decoration: underline;
}
/* 하단 탭이 없는 온보딩에서는 맨 아래로 */
body.hide-tabbar .help-link {
  bottom: 0;
  padding-bottom: calc(var(--safe-bottom) + 8px);
}

/* 위기 안내 창: 빨간색 경고 대신 차분하게 */
.crisis-dialog {
  width: calc(100% - 32px);
  max-width: 420px;
  padding: 24px 20px 20px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);  /* 어두운 화면에서도 창 테두리가 보이게 */
  border-radius: 20px;
}
.crisis-dialog::backdrop {
  background: rgba(40, 36, 32, 0.55);
}
.crisis-title {
  font-size: 1.2rem;
  line-height: 1.45;
  margin: 0 0 8px;
  text-align: center;
}
.crisis-text {
  color: var(--text-soft);
  text-align: center;
  font-size: 0.95rem;
  margin: 0 0 20px;
  word-break: keep-all;
}
.crisis-list {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.crisis-call,
.crisis-emergency {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 10px 16px;
  color: var(--text);
  text-decoration: none;
  background: var(--accent-soft);
  border-radius: 12px;
}
.crisis-name {
  font-size: 0.95rem;
  word-break: keep-all;   /* 단어 중간에서 줄이 바뀌지 않게 */
}
.crisis-call:focus-visible,
.crisis-number:focus-visible,
.crisis-dialog .btn-secondary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.crisis-name small {
  color: var(--text-soft);
  font-size: 0.8rem;
}
.crisis-number {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}
/* 112 / 119는 따로따로 누르므로 누를 자리를 넉넉히 */
.crisis-emergency a {
  display: inline-block;
  padding: 8px 6px;
}

/* 애매한 표현일 때만 보이는 작은 글자 버튼 */
.text-btn {
  display: block;
  width: 100%;
  min-height: 44px;
  margin-top: 8px;
  font-size: 0.85rem;
  font-family: inherit;
  color: var(--text-soft);
  background: none;
  border: none;
  text-decoration: underline;
  cursor: pointer;
}
.text-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* 화면에는 안 보이지만 화면 낭독기는 읽는 글자 */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* 애니메이션 줄이기 설정을 켠 사용자에게는 효과를 끈다 */
@media (prefers-reduced-motion: reduce) {
  .toast {
    transition: none;
  }
  /* 하늘의 별은 반짝이지 않는다 (13단계). 해·달도 JS가 처음 한 번만 그리고 다시 옮기지 않는다 */
  .sky-star {
    animation: none;
    opacity: 0.8;
  }
  /* 호흡 원은 움직이지 않는다. 대신 원 안의 숫자 카운트로 안내한다 (10단계) */
  .breath-circle.is-breathing {
    animation: none;
    transform: scale(0.8);
  }
  /* 쪽지 애니메이션도 재생하지 않는다 (넣었다는 건 안내 문구와 개수로 알 수 있다) */
  .box-art.is-dropping .note,
  .box-art.is-dropping .box-shape {
    animation: none;
  }
  /* 상자 들썩임, 뚜껑 열림, 카드가 올라오는 움직임도 없앤다 (바로 나타나고 바로 사라진다) */
  .box-button.is-hinting svg {
    animation: none;
  }
  /* 마이크 버튼은 퍼지는 테두리 없이 색만 바뀐다 */
  .voice-btn.is-listening {
    animation: none;
  }
  .box-lid-group,
  .box-button,
  .sheet,
  .sheet-backdrop,
  #screen-box {
    transition: none;
  }
}
