/* 색상 토큰 · 공통 요소 */
:root {
  --bg: #e3e9ee;
  --surface: #f8fafb;
  --surface-2: #edf1f4;
  --line: #d0d9e0;
  --text: #1c2731;
  --muted: #5a6875;
  --faint: #5d6a76;   /* 배경(--bg) 위에서도 명도 대비 4.5:1 이상 */
  --accent: #bf541e;  /* 흰 글자와 대비 4.5:1 이상 */
  --accent-ink: #ffffff;
  --accent-soft: #f8e2d5;
  --accent-text: #a34616;
  --track: #d5dde4;
  --bad-bg: #fbe2df;  --bad: #b02a20;
  --mid-bg: #f9eecd;  --mid: #855800;
  --good-bg: #dbf0e1; --good: #1c703e;
  --shadow: 0 1px 2px rgba(28, 42, 56, .05), 0 6px 20px rgba(28, 42, 56, .06);
  --ko: "IBM Plex Sans KR", system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --fs: 1;   /* 글자 크기 배율 — 상단 가−/가+ 버튼이 바꾼다 */
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131a20;
    --surface: #1c252d;
    --surface-2: #232e37;
    --line: #313e4a;
    --text: #e4eaef;
    --muted: #9cabb8;
    --faint: #8a97a3;
    --accent: #ec7b40;
    --accent-ink: #1b0f07;
    --accent-soft: #3a2519;
    --accent-text: #f59c68;
    --track: #2c3843;
    --bad-bg: #3a1d1b;  --bad: #ff9c90;
    --mid-bg: #352a12;  --mid: #f0c75e;
    --good-bg: #16301f; --good: #80d69c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--ko);
  font-size: calc(16px * var(--fs));
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mono { font-family: var(--mono); }

.wrap {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
}

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; border: 0; border-radius: 14px; padding: 15px 16px;
  font-size: calc(17px * var(--fs)); font-weight: 600;
}
a.btn { text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary:active { filter: brightness(.94); }
.btn.primary:disabled { background: var(--track); color: var(--faint); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn .num { font-family: var(--mono); }

.sect { margin: 26px 0 10px; font-size: calc(13px * var(--fs)); font-weight: 600; color: var(--muted); letter-spacing: .02em; }
.note { margin-top: 10px; font-size: calc(12.5px * var(--fs)); color: var(--faint); }

/* 학습·가이드 화면 상단 */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.back { border: 0; background: none; padding: 6px 2px; font-size: calc(15px * var(--fs)); font-weight: 600; color: var(--muted); }

.kbd {
  display: none; font-family: var(--mono); font-size: calc(11px * var(--fs)); font-weight: 500;
  padding: 0 5px; border-radius: 4px; border: 1px solid currentColor;   /* 흐리게(opacity) 하면 버튼 위 명도 대비가 모자라다 */
}
@media (hover: hover) and (pointer: fine) { .kbd { display: inline-block; } }

.loading, .error { padding: 40px 0; text-align: center; color: var(--muted); }
.error .btn { margin-top: 16px; }

.btn.secondary { background: var(--surface); color: var(--accent-text); border: 1px solid var(--line); box-shadow: var(--shadow); }
.btn.secondary:active { background: var(--surface-2); }
.btn.secondary:disabled { color: var(--faint); box-shadow: none; }

/* 글자 크기 조절 (모든 화면 상단) */
.fontctl { display: inline-flex; flex: none; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); overflow: hidden; }
.fontctl button {
  border: 0; background: transparent; color: var(--muted); font-weight: 700; line-height: 1;
  width: 40px; height: 34px; display: grid; place-items: center;
}
.fontctl button + button { border-left: 1px solid var(--line); }
.fontctl .s { font-size: 13px; }
.fontctl .l { font-size: 18px; }
.fontctl button:disabled { opacity: .35; }
.fontctl button:active:not(:disabled) { background: var(--line); }
.topbar .right { display: flex; align-items: center; gap: 10px; }
.topbar .dict-name { flex: 1; min-width: 0; text-align: center; font-size: calc(14px * var(--fs)); font-weight: 700; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 새 버전 알림 */
.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  width: min(528px, calc(100% - 32px));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 12px 12px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); box-shadow: 0 8px 28px rgba(0, 0, 0, .25);
  font-size: calc(14.5px * var(--fs)); z-index: 10;
}
.toast button {
  flex: none; border: 0; border-radius: 10px; padding: 8px 14px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: calc(14px * var(--fs));
}
.toast .x { background: transparent; color: inherit; opacity: .7; padding: 8px; }

/* 화면에는 보이지 않고 화면 읽기 프로그램만 읽는 글 */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ── 넓은 화면 (PC·태블릿) ─────────────────────────────────────────
   휴대폰 배치는 그대로 두고, 화면이 넓으면 화면마다 알맞은 폭으로 넓힌다.
   카드 학습·퀴즈(study)는 한눈에 보기 좋은 폭을 유지한다. */
@media (min-width: 760px) {
  .wrap { padding-left: 28px; padding-right: 28px; }
  .wrap[data-view="study"], .wrap[data-view="scene"] { max-width: 680px; }
  .wrap[data-view="guide"], .wrap[data-view="doc"], .wrap[data-view="about"],
  .wrap[data-view="log"], .wrap[data-view="search"], .wrap[data-view="glossary"], .wrap[data-view="marks"], .wrap[data-view="links"], .wrap[data-view="transfer"] { max-width: 860px; }
  .wrap[data-view="home"], .wrap[data-view="list"], .wrap[data-view="word"],
  .wrap[data-view="docs"], .wrap[data-view="stats"], .wrap[data-view="hs"], .wrap.portal { max-width: 1280px; }
  .wrap[data-view="course"], .wrap[data-view="lessons"], .wrap[data-view="lesson"] { max-width: 860px; }
  .toast { width: min(640px, calc(100% - 32px)); }
}

/* 아랍어 (오른쪽에서 왼쪽으로 쓰는 글자) — lang="ar" 요소는 RTL 로 따로 떼어 놓고(bidi isolate), 모음 부호가 잘 보이는 글꼴과 줄 간격.
   글자 사이 간격은 0 (아랍 글자는 이어 쓰므로), 줄은 한국어 화면처럼 왼쪽 정렬 (글 안의 방향만 RTL; 크롬은 match-parent 를 start 로 계산해 오른쪽으로 붙는다).
   문법 정보(.parts)는 한국어 이름표·로마자가 섞여 있어 왼쪽에서 오른쪽 배치를 그대로 둔다. 로마자 줄은 lang="ar-Latn" 이라 해당 없음. */
:root { --ar: "Noto Naskh Arabic", "Noto Sans Arabic", "Geeza Pro", "Segoe UI", Tahoma, Arial, var(--ko); }
[lang="ar"] { font-family: var(--ar) !important; letter-spacing: 0 !important; direction: rtl; unicode-bidi: isolate; text-align: left; line-height: 1.75; }
.parts[lang="ar"] { direction: ltr; unicode-bidi: normal; }

/* 힌디어 (데바나가리) — 고정폭·한글 글꼴에는 글자가 없으므로 데바나가리 글꼴로. 글자 사이 간격 0 (자음 결합·윗줄이 끊기지 않게),
   모음 기호가 위아래로 붙어 줄 간격을 조금 넓힌다. 로마자 줄은 lang="hi-Latn" 이라 해당 없음. 힌디어 사전 index.html 이 Noto Sans Devanagari 를 불러온다. */
:root { --hi: "Noto Sans Devanagari", "Kohinoor Devanagari", "Devanagari Sangam MN", "Nirmala UI", Mangal, var(--ko); }
[lang="hi"] { font-family: var(--hi) !important; letter-spacing: 0 !important; line-height: 1.5; }
