/* frontend/css/theme.css — 은하 웹 테마 토큰 (라이트/다크)
   정본 설계: ~/Desktop/control/DARK-MODE-PLAN.md
   - 라이트 값 = 종전 웹 리터럴 그대로(외관 변화 0). 다크 값 = iOS 앱 Theme.swift·TextReading 팔레트 복제(네이티브 동형).
   - 테마 선택자는 html[data-theme="dark"] 단일 기준. data-theme는 js/theme.js가 첫 페인트 전에 스탬프
     (auto = prefers-color-scheme 해석, 앱 셸(html.app-shell)은 항상 auto). CSS에서 prefers-color-scheme 직접 사용 금지.
   - 이 파일은 index.html·korzina.html 양쪽에서 가장 먼저 로드된다. */

html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

:root {
  /* ---- 기본 표면 ---- */
  --bg: #f0fff0;
  --card: #ffffff;
  --panel: #ffffff;
  --panel2: #e6f7e6;
  --text: #1f1f1f;
  --muted: #6b7280;
  --tertiary: rgba(60,60,67,0.3);
  --green: #228b22;
  --green-rgb: 34,139,34;            /* rgba(var(--green-rgb), α) 용 */
  --green-deep: #1f6f1f;             /* 헤더 텍스트·강조 */
  --green-hover: #1c711c;            /* 버튼 hover */
  --mint: #90ee90;
  --border: #90ee90;
  --separator: rgba(60,60,67,0.29);
  --line: #e5e7eb;                   /* 회색 헤어라인 */
  --shadow: 0 8px 24px rgba(0,0,0,0.07);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --overlay: rgba(0,0,0,0.5);        /* 모달 배경 */
  --on-accent: #ffffff;              /* 그린/블루 버튼 위 글자 — 양 테마 고정 */
  --input-bg: #ffffff;
  --hover-bg: rgba(34,139,34,0.06);
  --primaryBlue: #1f3a8a;
  --primaryBlueSoft: #e8edfb;

  /* ---- 읽기·분석 ---- */
  --ruby: #b03a2e;                   /* 후리가나 */
  --ruby-hl: #7c2418;
  --gloss: #4a7a4a;                  /* 직역 글로스 */
  --gloss-active: #0f5e0f;           /* 현재 문장/활성 글로스 */
  --gloss-active-deep: #0a4a0a;
  --nat: #5a5a5a;                    /* 자연역 */
  --context-text: #9a9a9a;           /* 앞뒤 문맥 문장 */
  --sentence-cur-bg: rgba(34,139,34,0.14);
  --word-hl: rgba(34,139,34,0.24);   /* 단어 하이라이트 박스 */
  --capsule: rgba(34,139,34,0.13);   /* 빈칸/캡슐 */
  --sh-purple: #7c3aed;              /* super-heavy ruby */
  --sh-purple-soft: rgba(147,112,219,0.10);
  --sh-purple-mid: rgba(147,112,219,0.25);

  /* ---- 복습 등급 (again/hard/good/easy) ---- */
  --grade-again-bg: #fee2e2; --grade-again-fg: #dc2626;
  --grade-hard-bg:  #fef3c7; --grade-hard-fg:  #d97706;
  --grade-good-bg:  #d1fae5; --grade-good-fg:  #059669;
  --grade-easy-bg:  #dbeafe; --grade-easy-fg:  #2563eb;

  /* ---- JLPT 칩 (라이트: 배경=색, 글자=흰) ---- */
  --jlpt-n5: #7cb342; --jlpt-n4: #26a69a; --jlpt-n3: #f9a825;
  --jlpt-n2: #ef6c00; --jlpt-n1: #c62828; --jlpt-etc: #90a4ae;
  --jlpt-n5-bg: var(--jlpt-n5); --jlpt-n4-bg: var(--jlpt-n4); --jlpt-n3-bg: var(--jlpt-n3);
  --jlpt-n2-bg: var(--jlpt-n2); --jlpt-n1-bg: var(--jlpt-n1); --jlpt-etc-bg: var(--jlpt-etc);
  --jlpt-fg: #ffffff;

  /* ---- 상태 ---- */
  --success: #10b981;
  --danger: #dc2626;
  --danger-soft: #ff6b6b;
  --info: #3b82f6;
  --toast-bg: rgba(0,0,0,0.82);
  --toast-fg: #ffffff;

  /* ---- PDF 뷰어 (페이지 자체는 흰 종이 고정 — DARK-MODE-PLAN §1) ---- */
  --pdf-stack-bg: #e5e5ea;
  --pdf-page-bg: #ffffff;

  /* ---- 기타 표면 ---- */
  --row-expanded-bg: #f5f5f5;        /* korzina.js 확장 행 (index에서 로드) */

  /* ---- 파생 토큰 (index 스윕 P2) ---- */
  --card-rgb: 255,255,255;                 /* 반투명 카드 rgba(var(--card-rgb),α) */
  --reader-bg: #fafaf6;                    /* 리더 모드 body */
  --reader-body-text: #1a1a1a;             /* 리더 줄글 본문 */
  --drop-overlay-bg: rgba(240,250,240,0.92);
  --tint-bg: #fbfffb;                      /* pill/miniBtn/toggleWrap/modeSelect/sliderBox */
  --tint-row-bg: #fafdfa;                  /* subUnitRow */
  --tint-row-hover: #eef7ee;
  --tint-box-bg: #f6faf6;                  /* 문장 번역 박스 */
  --tint-lib-bg: #f6fbf6;                  /* 이야기 서재·편지 */
  --tint-lib-hover: #ecf7ec;
  --line-green: #d0e7d0;                   /* 연녹 테두리 */
  --line-green-2: #d9e6d9;
  --line-green-hover: #b8dcb8;
  --table-line: rgba(144,238,144,0.9);     /* 어휘표 셀 테두리 */
  --line-faint: rgba(0,0,0,0.06);          /* 검정 헤어라인 */
  --line-faint-4: rgba(0,0,0,0.04);
  --line-faint-8: rgba(0,0,0,0.08);
  --gray-soft: #f3f4f6;                    /* 회색 버튼/스켈레톤 배경 */
  --gray-hover: #f9fafb;
  --gray-line: #d1d5db;
  --muted-2: #9ca3af;
  --sep-text: #c4c4c4;                     /* 직역 구분자 */
  --dot-idle: #ccc;                        /* 상태 점 기본 */
  --switch-off: #cfd5cf;                   /* 리더 스위치 off 트랙 */
  --disabled-bg: #aaa;                     /* button:disabled */
  --text-strong: #0f0f0f;                  /* 리더 현재 문장·어휘 */
  --text-strong-b: #111;                   /* 팝오버 단어 */
  --text-strong-c: #111827;                /* 서재 제목 */
  --text-head: #1f2937;                    /* 드롭다운 이름·모달 제목·기록 제목 */
  --text-body-2: #2a2a2a;                  /* 어휘 뜻 */
  --text-body-3: #2f2f2f;                  /* 비활성 문장 */
  --text-body-4: #374151;                  /* 드롭다운 항목·베타 안내문 */
  --text-soft: #4a4a4a;
  --text-soft-2: #555;
  --text-soft-3: #6a6a6a;
  --nat-inline: #1f2f1f;                   /* super-heavy 인라인 자연역 */
  --gloss-hl-fg: #1a5a1a;                  /* alignSpan 강조 글자 */
  --gloss-active-sub: #073d07;             /* rv-sub 강조 글자 */
  --green-deep-2: #1a6e1a;                 /* 서재·편지 글자/hover */
  --green-grad-end: #2d8a2d;               /* 로그인 버튼 그라데이션 끝 */
  --ruby-2: #c0392b;                       /* 팝오버 읽기 */
  --hl-row: rgba(120,220,120,0.28);        /* 교차 하이라이트 행 */
  --ruby-row-bg: linear-gradient(90deg, rgba(147, 112, 219, 0.10) 0%, rgba(255,255,255,0) 100%);
  --ruby-row-hl-bg: linear-gradient(90deg, rgba(147, 112, 219, 0.18) 0%, rgba(120, 220, 120, 0.20) 100%);
  --ruby-hl-bg: linear-gradient(90deg, rgba(147, 112, 219, 0.25) 0%, rgba(120, 220, 120, 0.30) 100%);
  --sh-purple-tag: rgba(147, 112, 219, 0.15);
  --overlay-45: rgba(0,0,0,0.45);          /* 베타 경고·서재 모달 배경 */
  --overlay-35: rgba(0,0,0,0.35);          /* 기록 드로어 배경 */
  --danger-bright: #ef4444;                /* 토스트 오류·사용량 danger·삭제 hover */
  --danger-deep: #b91c1c;                  /* 편지 오류 안내 */
  --danger-soft-bg: #fef2f2;
  --badge-warn-bg: #fff3cd; --badge-warn-fg: #856404;   /* 리더 버튼 배지 */
  --jlpt-off-fg: #9aa3ab; --jlpt-off-line: #e2e6ea;
  --tier-free-bg: #f0f0f0; --tier-free-fg: #666; --tier-free-line: #ddd;
  --tier-anon-bg: #f8f8f8; --tier-anon-fg: #aaa; --tier-anon-line: #eee;
  --nudge-bg: linear-gradient(135deg, #f0fdf4, #dcfce7);
  --nudge-fg: #166534;

  /* ---- 파생 토큰 (korzina 스윕 P3) ---- */
    --accent-orange: #d97706;          /* 통계 강조·due-hot */
    --accent-blue: #2563eb;
    --accent-emerald: #059669;
    --row-line: rgba(0,0,0,0.04);      /* 표 행 헤어라인 */
    --faint: #ccc;                     /* 삭제 ×·빈 값 대시 */
    --hint: #bbb;                      /* 복습 키 힌트 */
    --danger-bg: #fee2e2;              /* 위험 버튼 연한 배경 */
    --danger-hover: #b91c1c;
    --warn-bg: #fef3c7;                /* 일괄 삭제 바·복습 태그 */
    --warn-fg: #92400e;
    --toast-error-bg: #ef4444;
    --ghost-bg: #f3f4f6;               /* 모달 ghost 버튼 */
    --chip-border: #cbd5e1;            /* 하루 신규 숫자 칩 테두리 */
    --pop-read: #c0392b;               /* 예문 팝오버 읽기 */
}

html[data-theme="dark"] {
  --bg: #121712;                     /* iOS FlowingReader.bg — honeydew의 다크 짝 */
  --card: #1c1c1e;                   /* iOS Theme.card / rowBg(white .11) */
  --panel: #1c1c1e;
  --panel2: rgba(97,199,107,0.16);   /* headerBg */
  --text: #ebebeb;                   /* body(white .92) */
  --muted: rgba(235,235,245,0.6);    /* Theme.secondary */
  --tertiary: rgba(235,235,245,0.3);
  --green: #61c76b;                  /* Theme.brand 다크 */
  --green-rgb: 97,199,107;
  --green-deep: #9ee09e;             /* headerText */
  --green-hover: #7ad383;
  --mint: rgba(97,199,107,0.35);
  --border: rgba(97,199,107,0.35);   /* gridLine/cardBorder */
  --separator: rgba(84,84,88,0.6);
  --line: rgba(84,84,88,0.6);
  --shadow: 0 8px 24px rgba(0,0,0,0.45);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.4);
  --overlay: rgba(0,0,0,0.65);
  --input-bg: #1c1c1e;
  --hover-bg: rgba(97,199,107,0.1);
  --primaryBlue: #0a84ff;            /* systemBlue 다크 — 웹에선 CTA 버튼 배경·링크로 쓰여 흰 글자 대비 확보 */
  --primaryBlueSoft: rgba(10,132,255,0.16);

  --ruby: #ff453a;                   /* systemRed 다크 */
  --ruby-hl: #ff8a80;
  --gloss: #8fcc8f;
  --gloss-active: #9ee09e;           /* curText */
  --gloss-active-deep: #9ee09e;
  --nat: #9e9e9e;                    /* natText(white .62) */
  --context-text: #8c8c8c;           /* context(white .55) */
  --sentence-cur-bg: rgba(97,199,107,0.18);
  --word-hl: rgba(97,199,107,0.28);
  --capsule: rgba(97,199,107,0.18);  /* brandSoft */
  --sh-purple: #bf5af2;              /* systemPurple 다크 */
  --sh-purple-soft: rgba(191,90,242,0.18);
  --sh-purple-mid: rgba(191,90,242,0.3);

  /* iOS tinted 공식: 글자=원색, 배경=원색 15% */
  --grade-again-bg: rgba(255,69,58,0.15);  --grade-again-fg: #ff453a;
  --grade-hard-bg:  rgba(255,159,10,0.15); --grade-hard-fg:  #ff9f0a;
  --grade-good-bg:  rgba(97,199,107,0.15); --grade-good-fg:  #61c76b;
  --grade-easy-bg:  rgba(10,132,255,0.15); --grade-easy-fg:  #0a84ff;

  /* JLPT 칩 다크: 시스템색, 배경=색 14%, 글자=색 */
  --jlpt-n5: #30d158; --jlpt-n4: #40cbe0; --jlpt-n3: #0a84ff;
  --jlpt-n2: #ff9f0a; --jlpt-n1: #ff453a; --jlpt-etc: #8e8e93;
  --jlpt-n5-bg: rgba(48,209,88,0.14);  --jlpt-n4-bg: rgba(64,203,224,0.14); --jlpt-n3-bg: rgba(10,132,255,0.14);
  --jlpt-n2-bg: rgba(255,159,10,0.14); --jlpt-n1-bg: rgba(255,69,58,0.14);  --jlpt-etc-bg: rgba(142,142,147,0.14);
  --jlpt-fg: currentColor;           /* 칩 글자 = 레벨색 (각 칩 규칙에서 color: var(--jlpt-nX)) */

  --success: #30d158;
  --danger: #ff453a;
  --danger-soft: #ff6961;
  --info: #0a84ff;

  --pdf-stack-bg: #2c2c2e;           /* iOS PDFView systemGray5 다크 */
  /* --pdf-page-bg 는 흰 종이 고정 */

  --row-expanded-bg: #2c2c2e;

  /* ---- 파생 토큰 (index 스윕 P2) ---- */
  --card-rgb: 28,28,30;
  --reader-bg: #121712;
  --reader-body-text: #ebebeb;
  --drop-overlay-bg: rgba(18,23,18,0.92);
  --tint-bg: rgba(97,199,107,0.06);
  --tint-row-bg: rgba(97,199,107,0.05);
  --tint-row-hover: rgba(97,199,107,0.16);
  --tint-box-bg: rgba(97,199,107,0.10);
  --tint-lib-bg: rgba(97,199,107,0.10);
  --tint-lib-hover: rgba(97,199,107,0.18);
  --line-green: rgba(97,199,107,0.3);
  --line-green-2: rgba(97,199,107,0.3);
  --line-green-hover: rgba(97,199,107,0.6);
  --table-line: rgba(97,199,107,0.3);
  --line-faint: rgba(255,255,255,0.08);
  --line-faint-4: rgba(255,255,255,0.06);
  --line-faint-8: rgba(255,255,255,0.1);
  --gray-soft: #2c2c2e;
  --gray-hover: rgba(255,255,255,0.06);
  --gray-line: rgba(84,84,88,0.8);
  --muted-2: rgba(235,235,245,0.45);
  --sep-text: rgba(235,235,245,0.3);
  --dot-idle: #48484a;
  --switch-off: #39393d;
  --disabled-bg: #3a3a3c;
  --text-strong: #f2f2f2;
  --text-strong-b: #f2f2f2;
  --text-strong-c: #f2f2f2;
  --text-head: #ebebeb;
  --text-body-2: #dcdcdc;
  --text-body-3: #dcdcdc;
  --text-body-4: #d6d6d6;
  --text-soft: #c8c8c8;
  --text-soft-2: #b0b0b0;
  --text-soft-3: #b0b0b0;
  --nat-inline: #dcdcdc;
  --gloss-hl-fg: #9ee09e;
  --gloss-active-sub: #9ee09e;
  --green-deep-2: #9ee09e;
  --green-grad-end: #6fd279;
  --ruby-2: #ff453a;
  --hl-row: rgba(97,199,107,0.3);
  --ruby-row-bg: linear-gradient(90deg, rgba(191,90,242,0.18) 0%, rgba(28,28,30,0) 100%);
  --ruby-row-hl-bg: linear-gradient(90deg, rgba(191,90,242,0.25) 0%, rgba(97,199,107,0.25) 100%);
  --ruby-hl-bg: linear-gradient(90deg, rgba(191,90,242,0.3) 0%, rgba(97,199,107,0.3) 100%);
  --sh-purple-tag: rgba(191,90,242,0.22);
  --overlay-45: rgba(0,0,0,0.65);
  --overlay-35: rgba(0,0,0,0.55);
  --danger-bright: #ff453a;
  --danger-deep: #ff6961;
  --danger-soft-bg: rgba(255,69,58,0.15);
  --badge-warn-bg: rgba(255,214,10,0.18); --badge-warn-fg: #ffd60a;
  --jlpt-off-fg: rgba(235,235,245,0.4); --jlpt-off-line: rgba(84,84,88,0.6);
  --tier-free-bg: #2c2c2e; --tier-free-fg: rgba(235,235,245,0.6); --tier-free-line: rgba(84,84,88,0.6);
  --tier-anon-bg: #1c1c1e; --tier-anon-fg: rgba(235,235,245,0.3); --tier-anon-line: rgba(84,84,88,0.4);
  --nudge-bg: linear-gradient(135deg, rgba(97,199,107,0.18), rgba(97,199,107,0.10));
  --nudge-fg: #9ee09e;

  /* ---- 파생 토큰 (korzina 스윕 P3) ---- */
    --accent-orange: #ff9f0a;
    --accent-blue: #0a84ff;
    --accent-emerald: #30d158;
    --row-line: rgba(255,255,255,0.06);
    --faint: rgba(235,235,245,0.3);
    --hint: rgba(235,235,245,0.3);
    --danger-bg: rgba(255,69,58,0.15);
    --danger-hover: #ff6961;
    --warn-bg: rgba(255,159,10,0.15);
    --warn-fg: #ff9f0a;
    --toast-error-bg: #ff453a;
    --ghost-bg: #2c2c2e;
    --chip-border: rgba(84,84,88,0.6);
    --pop-read: #ff453a;
}

/* 한자 획순 SVG(AnimCJK: 검은 획·#ccc 채움·투명 배경)는 <object> 별도 문서라 페이지 CSS가 닿지 않음 →
   다크에서 반전 필터로 iOS KanjiStrokeHTML.wrap과 동일 결과(흰 획·진회색 채움). 구조 무변경. */
html[data-theme="dark"] .kc-stroke-obj { filter: invert(0.89); }  /* 0.89: object 흰 캔버스→#1c1c1c(카드색), 검은 획→#e3e3e3, #ccc 채움→#444 */

/* ---- 테마 토글 버튼 (헤더/korzina 상단) — 리더 버튼과 같은 pill, 아이콘은 data-theme-pref로 전환 ---- */
.header-theme-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
  background: rgba(var(--green-rgb), 0.08);
  color: var(--green);
  border: 1px solid rgba(var(--green-rgb), 0.2);
  border-radius: 999px;
  cursor: pointer; transition: all 0.15s; margin-right: 8px;
}
.header-theme-btn:hover { background: rgba(var(--green-rgb), 0.14); border-color: rgba(var(--green-rgb), 0.35); }
.header-theme-btn svg { display: none; }
html[data-theme-pref="auto"]  .header-theme-btn .ic-auto,
html[data-theme-pref="dark"]  .header-theme-btn .ic-dark,
html[data-theme-pref="light"] .header-theme-btn .ic-light { display: block; }
/* 앱 셸(iOS 웹뷰)은 시스템 추종만 — 토글 숨김 */
html.app-shell [data-theme-toggle] { display: none !important; }
