:root {
  color-scheme: light;
  --bg: #ffffff;
  --card: #ffffff;
  --line: #e4e4e0;
  --ink: #17171a;
  --muted: #6b6b73;
  --accent: #ff4b4b;
  --accent-ink: #ffffff;
  --soft: #f5f5f3;
  --blue: #2a78d6;
  --red: #eb6834;
  --green: #1baf7a;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #0e1117;
    --card: #171a21;
    --line: #2b2f38;
    --ink: #f2f2f4;
    --muted: #9aa0ab;
    --soft: #1d212a;
    --blue: #3987e5;
    --red: #d95926;
    --green: #199e70;
  }
}

* { box-sizing: border-box; }
/* hidden 속성이 항상 이기도록 (.screen 의 display 가 덮어쓰지 않게) */
[hidden] { display: none !important; }
body {
  margin: 0;
  padding: env(safe-area-inset-top) 0 calc(env(safe-area-inset-bottom) + 24px);
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}
.screen { max-width: 760px; margin: 0 auto; padding: 12px 16px; }
.center { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 70vh; gap: 12px; }
h1 { font-size: clamp(1.3rem, 5vw, 1.9rem); margin: 8px 0; }
h2 { font-size: 1.15rem; margin: 18px 0 8px; }
h3 { font-size: 1rem; margin: 14px 0 6px; }
header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hint, .muted { color: var(--muted); font-size: 0.85rem; }
.error { color: var(--accent); font-size: 0.9rem; }

button {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; cursor: pointer; min-height: 44px;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.plain { background: none; border: none; color: var(--muted); }
button.danger { color: var(--accent); }
button.icon { min-height: 40px; padding: 6px 10px; font-size: 1.1rem; }
button:disabled { opacity: 0.45; cursor: default; }

input, textarea, select {
  font: inherit; color: var(--ink); background: var(--soft);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; width: 100%; min-height: 44px;
}
textarea { min-height: 72px; }
/* 체크박스·라디오는 폭 100% 규칙에서 빼고, 글자와 한 줄에 나오게 */
input[type="checkbox"], input[type="radio"] { width: auto; min-height: auto; margin-right: 8px; vertical-align: -2px; }
label:has(> input[type="checkbox"]) { display: flex; align-items: center; gap: 6px; color: var(--ink); }
label { display: block; margin: 8px 0; font-size: 0.9rem; color: var(--muted); }
label input, label textarea, label select { margin-top: 4px; color: var(--ink); }
form { width: 100%; display: flex; flex-direction: column; gap: 8px; }

/* 비밀번호 칸 안의 눈 단추 (보이기/가리기) */
.pw-field { position: relative; width: 100%; }
.pw-field input { padding-right: 48px; }
.pw-field .eye {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  min-height: 38px; width: 42px; padding: 0; border: none; background: none; color: var(--muted);
}
.pw-field .eye svg { width: 21px; height: 21px; }
.pw-field .eye:hover { color: var(--ink); }

nav#menu { display: flex; gap: 8px; margin: 10px 0 14px; }
nav#menu .tab { flex: 1; }
nav#menu .tab[aria-current="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.badge { background: rgba(255, 255, 255, 0.25); border-radius: 999px; padding: 0 8px; margin-left: 4px; font-size: 0.85rem; }

.card { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); padding: 14px; margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }
.counts { font-size: 0.9rem; }
.counts .new { color: var(--blue); }
.counts .learning { color: var(--red); }
.counts .review { color: var(--green); }

.word { font-size: clamp(1.8rem, 9vw, 2.6rem); font-weight: 700; text-align: center; margin: 18px 0 6px; }
.audio-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-bottom: 14px; }
.speak {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border-radius: 999px; min-height: 44px; font-size: 0.95rem;
}
.speak .flag { font-size: 1.05rem; }
.speak svg { width: 19px; height: 19px; color: var(--muted); }
.speak .who { color: var(--muted); }
.speak:hover svg, .speak:hover .who { color: var(--ink); }
.speak.playing { border-color: var(--accent); color: var(--accent); }
.speak.playing svg, .speak.playing .who { color: var(--accent); }
.sense { border-top: 1px solid var(--line); padding: 14px 0; }
.sense:first-of-type { border-top: none; }
/* 한국어 뜻은 크고 굵게, 그 아래 한 줄 띄우고 예문 */
.meaning { font-size: 1.08rem; font-weight: 700; line-height: 1.45; margin-bottom: 10px; }
.num {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; margin-right: 8px; padding: 0 6px;
  border-radius: 999px; background: var(--soft); color: var(--muted);
  font-size: 0.8rem; font-weight: 600; vertical-align: 2px;
}
.meaning .phrase { color: var(--blue); }
.sub { color: var(--ink); font-size: 0.95rem; margin: -4px 0 10px; }
.sentence { margin: 0 0 4px; }
.translation { color: var(--muted); font-size: 0.9rem; }
/* 뜻 칸 오른쪽 끝의 삭제 단추 */
.trash { flex: none; width: 46px; padding: 0; font-size: 1rem; }
.trash[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }
.sense.marked { opacity: 0.5; }
.sense.marked input, .sense.marked textarea { text-decoration: line-through; }

/* 숙어는 회색 상자로 묶어 뜻 목록과 구분 */
.phrase-group { background: var(--soft); border-radius: var(--radius); padding: 2px 14px 10px; margin-top: 16px; }
.phrase-group .pick { border-top-color: var(--line); }
.phrase-group h3 { margin-top: 14px; }
.rate { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 14px; }
.rate button { padding: 10px 4px; font-size: 0.9rem; }
.rate small { display: block; color: var(--muted); }

.pick { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--line); }
.pick input[type=checkbox] { width: 20px; min-height: 20px; margin-top: 4px; flex: none; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); }

#suggest { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); margin-top: 4px; overflow: hidden; }
#suggest div { padding: 10px 12px; color: var(--muted); cursor: pointer; }
#suggest div[aria-selected="true"] { background: var(--soft); color: var(--ink); }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { border-bottom: 1px solid var(--line); padding: 6px 4px; text-align: right; }
th:first-child, td:first-child { text-align: left; }

dialog { border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--ink); max-width: 420px; width: calc(100% - 32px); padding: 18px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }

#toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 16px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 0.9rem; z-index: 50;
}
.spinner { color: var(--muted); font-size: 0.9rem; padding: 8px 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.stat { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.stat .label { font-size: 0.8rem; color: var(--muted); }
.stat .value { font-size: 1.5rem; font-weight: 600; }
