html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #E9E8E4;
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
a { color: #1F4E8C; text-decoration: none; }
a:hover { color: #163865; }
button { font-family: inherit; }
::-webkit-scrollbar { width: 0; height: 0; }

@keyframes riseIn {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes veilIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.page {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  background: #E9E8E4;
  font-family: 'IBM Plex Sans KR', sans-serif;
}

.card {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100vh;
  height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #FBFAF8;
  box-shadow: 0 0 0 1px rgba(18,17,15,0.06), 0 24px 60px rgba(18,17,15,0.10);
}

/* Header */
.header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #EEEBE4;
}
.text-btn {
  border: none;
  background: transparent;
  /* 손가락 터치 영역 확보(높이 31px → 39px). 헤더 세로 여백을 줄여 총 높이는 유지. */
  padding: 10px 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: #7C786F;
  transition: color 180ms ease;
}
.text-btn:hover { color: #12110F; }
.date-label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.16em;
  color: #A9A59B;
}

/* Keywords row */
.keywords-row {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
  /* 위쪽 4px은 헤더 구분선에 붙어 보였다. 칩이 숨 쉴 여백을 준다. */
  padding: 14px 24px 2px 24px;
}
.keyword-chip {
  font-size: 11.5px;
  color: #7C786F;
  background: #F1EFEA;
  border-radius: 6px;
  padding: 4px 10px;
}

/* Sentence area */
.sentence-wrap {
  display: flex;
  align-items: center;
  /* 문장이 배정된 높이보다 길어지면 center는 위아래 양쪽으로 넘쳐서
     키워드 칩과 겹치고 윗부분은 스크롤로도 닿을 수 없게 된다.
     safe center는 넘칠 때만 flex-start처럼 동작해 이를 막는다. */
  align-items: safe center;
  justify-content: center;
  min-height: 0;
  padding: 20px 30px 12px 30px;
  overflow-y: auto;
  overscroll-behavior: contain;
  transition: flex-grow 620ms cubic-bezier(0.22,0.61,0.36,1), padding 620ms cubic-bezier(0.22,0.61,0.36,1);
  flex-basis: 0;
  flex-shrink: 1;
}
.sentence {
  margin: 0;
  width: 100%;
  text-align: center;
  font-family: 'Noto Serif KR', serif;
  font-weight: 300;
  font-size: clamp(19px, 5.6vw, 26px);
  line-height: 1.85;
  letter-spacing: -0.025em;
  color: #12110F;
  word-break: keep-all;
  text-wrap: pretty;
  transition: font-size 620ms ease, line-height 620ms ease;
}
/* 패널을 펼치면 문장 영역이 좁아지므로 글자도 함께 줄인다. */
.sentence-compact {
  font-size: clamp(16.5px, 4.6vw, 21px);
  line-height: 1.7;
}
.seg-word {
  cursor: pointer;
  border-radius: 4px;
  padding: 1px 2px;
  margin: 0 -1px;
  transition: background 260ms ease, box-shadow 260ms ease;
}
.seg-h { box-shadow: inset 0 -0.09em 0 rgba(31,78,140,0.32); }
.seg-h-on { color: #1F4E8C; background: rgba(31,78,140,0.11); box-shadow: inset 0 -0.09em 0 #1F4E8C; }
.seg-p { box-shadow: inset 0 -0.09em 0 rgba(180,85,46,0.34); }
.seg-p-on { color: #B4552E; background: rgba(180,85,46,0.12); box-shadow: inset 0 -0.09em 0 #B4552E; }

/* 세로가 짧은 기기에서는 행간을 더 좁혀 문장이 잘리지 않게 한다. */
@media (max-height: 740px) {
  .sentence { line-height: 1.7; }
  .sentence-compact { line-height: 1.6; }
  .sentence-wrap { padding: 14px 24px 10px 24px; }
}

/* Toggle bar */
.toggle-bar-wrap {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  padding: 4px 0 20px 0;
}
/* 패널이 닫혀 있을 때는 토글 바가 화면 맨 아래라 홈 인디케이터에 겹친다.
   펼친 상태에서는 아래에 패널이 오므로 이 여백을 주지 않는다. */
.toggle-bar-wrap-floor { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
.toggle-bar {
  display: inline-flex;
  gap: 2px;
  background: #F1EFEA;
  border-radius: 12px;
  padding: 3px;
}
.toggle-btn {
  cursor: pointer;
  border: none;
  background: transparent;
  color: #7C786F;
  border-radius: 9px;
  padding: 9px 22px;
  font-size: 13.5px;
  font-weight: 400;
  letter-spacing: -0.01em;
  transition: color 180ms ease;
}
.toggle-btn:hover { color: #12110F; }
.toggle-btn.active {
  cursor: default;
  background: #FFFFFF;
  color: #12110F;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(18,17,15,0.10), 0 0 0 1px rgba(18,17,15,0.04);
}

/* Collapsible panels */
.panel {
  min-height: 0;
  overflow: hidden;
  flex-basis: 0;
  flex-shrink: 1;
  transition: flex-grow 620ms cubic-bezier(0.22,0.61,0.36,1);
}
.panel-scroll {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Words panel */
.words-scroll { padding: 18px 22px calc(40px + env(safe-area-inset-bottom)) 22px; }
.words-heading {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  color: #A9A59B;
  padding-bottom: 12px;
}
.words-list { display: flex; flex-direction: column; gap: 12px; }
.word-card {
  scroll-margin-top: 12px;
  cursor: pointer;
  border-radius: 14px;
  padding: 18px 18px 19px 18px;
  background: #FFFFFF;
  transition: background 300ms ease, box-shadow 300ms ease;
}
.word-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.word-term {
  font-family: 'Noto Serif KR', serif;
  font-weight: 400;
  font-size: 20px;
  color: #12110F;
  letter-spacing: -0.02em;
}
.word-hanja {
  font-family: 'Noto Serif KR', serif;
  font-weight: 300;
  font-size: 15px;
  color: #8E8A80;
}
.word-kind {
  margin-left: auto;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: 3px 8px;
  border-radius: 6px;
}
.word-reading {
  padding-top: 6px;
  font-size: 12px;
  font-weight: 400;
  color: #9A968D;
  letter-spacing: -0.01em;
}
.word-meaning {
  padding-top: 12px;
  font-size: 14.5px;
  font-weight: 400;
  line-height: 1.75;
  color: #33312C;
  letter-spacing: -0.015em;
  word-break: keep-all;
}
.word-origin {
  margin-top: 14px;
  padding-top: 13px;
  border-top: 1px solid #EFECE5;
  font-size: 13px;
  font-weight: 300;
  line-height: 1.75;
  color: #6B675F;
  letter-spacing: -0.01em;
  word-break: keep-all;
}
.word-label {
  color: #A9A59B;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.06em;
  padding-right: 8px;
}
.word-example {
  margin-top: 10px;
  font-family: 'Noto Serif KR', serif;
  font-weight: 300;
  font-size: 13.5px;
  line-height: 1.8;
  color: #6B675F;
  letter-spacing: -0.015em;
  word-break: keep-all;
}
.word-example .word-label { font-family: 'IBM Plex Sans KR', sans-serif; }
.word-actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
}
.save-btn {
  cursor: pointer;
  border: 1px solid #E6E3DC;
  background: #FFFFFF;
  color: #7C786F;
  border-radius: 8px;
  padding: 7px 13px;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: -0.01em;
  transition: border-color 180ms ease, color 180ms ease;
}
.save-btn:hover { border-color: #C9C4B9; color: #12110F; }
.save-btn.saved {
  border: 1px solid #12110F;
  background: #12110F;
  color: #FBFAF8;
}

/* Gloss panel */
.gloss-scroll { padding: 2px 30px calc(36px + env(safe-area-inset-bottom)) 30px; }
.gloss-divider {
  width: 28px;
  height: 1px;
  margin: 0 auto 26px auto;
  background: #DDD9D0;
}
.gloss-plain {
  font-family: 'Noto Serif KR', serif;
  font-weight: 300;
  font-size: 19px;
  line-height: 1.95;
  letter-spacing: -0.025em;
  color: #33312C;
  text-align: center;
  word-break: keep-all;
  text-wrap: pretty;
}
.gloss-note {
  padding-top: 26px;
  font-size: 13.5px;
  font-weight: 300;
  line-height: 1.85;
  color: #7C786F;
  letter-spacing: -0.015em;
  text-align: center;
  word-break: keep-all;
  text-wrap: pretty;
}
.gloss-counts {
  padding-top: 26px;
  display: flex;
  gap: 8px;
  justify-content: center;
  font-size: 11.5px;
  font-weight: 400;
  color: #7C786F;
}
.gloss-count-chip {
  background: #F1EFEA;
  border-radius: 6px;
  padding: 4px 10px;
}

/* Archive modal */
.archive-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: rgba(18,17,15,0.35);
  backdrop-filter: blur(2px);
  animation: veilIn 220ms ease both;
  display: flex;
  align-items: flex-end;
}
.archive-sheet {
  width: 100%;
  max-height: 76%;
  /* 시트 전체가 스크롤되면 탭과 '닫기'가 목록과 함께 위로 밀려 사라진다.
     헤더는 고정하고 목록만 스크롤시킨다. */
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #FFFFFF;
  border-radius: 20px 20px 0 0;
  padding: 20px 18px 0 18px;
  animation: riseIn 300ms cubic-bezier(0.22,0.61,0.36,1) both;
  box-shadow: 0 -8px 40px rgba(18,17,15,0.18);
}
.archive-handle, .archive-head { flex: 0 0 auto; }
.archive-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: #E6E3DC;
  margin: 0 auto 16px auto;
}
.archive-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 16px;
}
.archive-tabs {
  display: inline-flex;
  gap: 2px;
  background: #F1EFEA;
  border-radius: 10px;
  padding: 3px;
}
.archive-tab {
  border: none;
  background: transparent;
  color: #7C786F;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 400;
  cursor: pointer;
}
.archive-tab.active {
  cursor: default;
  background: #FFFFFF;
  color: #12110F;
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(18,17,15,0.10);
}
.archive-close {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  color: #7C786F;
  padding: 9px 4px;
  margin: -9px -4px;
}
.archive-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}
.archive-day {
  cursor: pointer;
  border-radius: 14px;
  padding: 15px 16px;
}
.archive-day-date {
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.12em;
  color: #A9A59B;
  padding-bottom: 8px;
}
.archive-day-preview {
  font-family: 'Noto Serif KR', serif;
  font-weight: 300;
  font-size: 15px;
  line-height: 1.7;
  letter-spacing: -0.02em;
  color: #33312C;
  word-break: keep-all;
}

.saved-empty {
  padding: 46px 10px 50px 10px;
  text-align: center;
}
.saved-empty-title {
  font-family: 'Noto Serif KR', serif;
  font-weight: 300;
  font-size: 16px;
  letter-spacing: -0.02em;
  color: #33312C;
}
.saved-empty-sub {
  padding-top: 9px;
  font-size: 12.5px;
  font-weight: 300;
  color: #9A968D;
  letter-spacing: -0.01em;
}
.saved-item {
  cursor: pointer;
  border-radius: 14px;
  background: #F7F6F3;
  padding: 15px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.saved-body { flex: 1 1 auto; min-width: 0; }
.saved-head {
  display: flex;
  align-items: baseline;
  gap: 7px;
  flex-wrap: wrap;
}
.saved-term {
  font-family: 'Noto Serif KR', serif;
  font-weight: 400;
  font-size: 17px;
  letter-spacing: -0.02em;
  color: #12110F;
}
.saved-hanja {
  font-family: 'Noto Serif KR', serif;
  font-weight: 300;
  font-size: 13.5px;
  color: #9A968D;
}
.saved-kind {
  font-size: 10px;
  font-weight: 500;
  padding: 2px 7px;
  border-radius: 5px;
}
.saved-meaning {
  padding-top: 7px;
  font-size: 13px;
  font-weight: 300;
  line-height: 1.65;
  letter-spacing: -0.015em;
  color: #6B675F;
  word-break: keep-all;
}
.saved-muted { color: #A9A59B; font-style: normal; }
.saved-date {
  padding-top: 8px;
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  color: #B6B2A8;
}
.saved-remove {
  flex: 0 0 auto;
  cursor: pointer;
  border: none;
  background: transparent;
  color: #B6B2A8;
  font-size: 12px;
  padding: 8px 0 8px 10px;
  margin: -6px 0;
}
.saved-remove:hover { color: #12110F; }

/* Share sheet */
.share-sheet { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
.share-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  cursor: pointer;
  border: none;
  border-radius: 14px;
  background: #F7F6F3;
  padding: 16px 18px;
  margin-bottom: 8px;
  text-align: left;
  transition: background 180ms ease;
}
.share-item:hover { background: #F1EFEA; }
.share-item-title {
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.015em;
  color: #12110F;
}
.share-item-sub {
  font-size: 12.5px;
  font-weight: 300;
  letter-spacing: -0.01em;
  color: #9A968D;
}
.share-cancel {
  width: 100%;
  cursor: pointer;
  border: none;
  background: transparent;
  color: #7C786F;
  font-size: 13.5px;
  padding: 14px 0 4px 0;
}
.share-cancel:hover { color: #12110F; }

/* Toast */
.toast {
  position: absolute;
  left: 50%;
  bottom: calc(30px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  background: #12110F;
  color: #FBFAF8;
  font-size: 12.5px;
  letter-spacing: -0.01em;
  padding: 10px 18px;
  border-radius: 10px;
  animation: riseIn 240ms ease both;
}
