/* ============================================================
   にほんご — Révision des cours de japonais
   Design mobile-first, élégant, inspiré du Japon
   ============================================================ */

:root {
  --primary: #cf4d46;
  --primary-2: #e2775f;
  --primary-soft: #f7ddd8;
  --sakura: #f2c8c2;
  --blue: #3a6fd8;
  --blue-soft: #e3ecfb;
  --gold: #d9a441;
  --green: #4c9a6a;
  --green-soft: #e0efe6;

  --bg: #f6f2ec;
  --bg-2: #efe9e0;
  --card: #fffdf9;
  --ink: #27272f;
  --ink-2: #55556b;
  --muted: #948d80;
  --line: #e7e0d5;
  --shadow: 0 1px 2px rgba(60, 50, 40, .05), 0 4px 14px rgba(60, 50, 40, .06);

  --hl-y: rgba(250, 214, 96, .42);
  --hl-p: rgba(238, 158, 158, .35);
  --hl-g: rgba(150, 205, 165, .35);
  --hl-b: rgba(140, 175, 235, .32);
  --hl-o: rgba(240, 178, 122, .35);
  --hl-v: rgba(185, 160, 230, .35);
  --hl-s: rgba(235, 170, 165, .35);
  --hl-r: rgba(185, 185, 185, .35);

  --radius: 16px;
  --radius-s: 10px;
  --font-body: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-jp: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic", "YuGothic", "Noto Sans JP", "Meiryo", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --primary: #e0655e;
    --primary-2: #e88973;
    --primary-soft: #4a2c28;
    --sakura: #6b4340;
    --blue: #7da2ee;
    --blue-soft: #26324d;
    --gold: #e2b35c;
    --green: #6db98a;
    --green-soft: #24402f;

    --bg: #17161b;
    --bg-2: #1f1e25;
    --card: #222129;
    --ink: #ece9e2;
    --ink-2: #b7b2a8;
    --muted: #8b8578;
    --line: #33313c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .35);

    --hl-y: rgba(214, 178, 60, .30);
    --hl-p: rgba(190, 90, 90, .30);
    --hl-g: rgba(90, 150, 110, .30);
    --hl-b: rgba(90, 120, 190, .30);
    --hl-o: rgba(190, 130, 70, .30);
    --hl-v: rgba(140, 110, 190, .30);
    --hl-s: rgba(190, 110, 105, .30);
    --hl-r: rgba(150, 150, 150, .30);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  min-height: 100dvh;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; }
a { color: var(--blue); }

/* ---------------- topbar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar .brand { display: flex; align-items: baseline; gap: 8px; flex: 1; min-width: 0; }
.topbar .brand h1 {
  margin: 0; font-size: 21px; font-weight: 800; letter-spacing: .02em;
  font-family: var(--font-jp);
}
.topbar .brand h1 .red { color: var(--primary); }
.topbar .brand small { color: var(--muted); font-size: 12.5px; font-weight: 500; white-space: nowrap; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 42px; height: 42px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card);
  color: var(--ink-2); font-size: 19px; flex: none;
  transition: transform .12s ease, background .15s ease;
}
.icon-btn:active { transform: scale(.92); }
.icon-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------------- main layout ---------------- */
main { max-width: 760px; margin: 0 auto; padding: 16px 16px 28px; }
.view-title {
  display: flex; align-items: center; gap: 10px; margin: 4px 0 14px;
}
.view-title h2 { margin: 0; font-size: 20px; font-weight: 750; }
.back-btn { margin-right: 2px; }

/* ---------------- hero / stats ---------------- */
.hero {
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; border-radius: 20px; padding: 20px 20px 18px;
  margin-bottom: 18px; position: relative; overflow: hidden;
  box-shadow: 0 8px 24px rgba(190, 60, 50, .25);
}
.hero::after {
  content: "あ"; position: absolute; right: -6px; top: -26px;
  font-size: 130px; font-family: var(--font-jp); opacity: .14; line-height: 1;
}
.hero .h-title { font-size: 15px; font-weight: 600; opacity: .92; margin-bottom: 2px; }
.hero .h-big { font-size: 26px; font-weight: 800; letter-spacing: .01em; }
.hero .h-sub { font-size: 13px; opacity: .85; margin-top: 2px; }
.hero .h-bar { height: 8px; border-radius: 99px; background: rgba(255,255,255,.28); margin-top: 12px; overflow: hidden; }
.hero .h-bar i { display: block; height: 100%; border-radius: 99px; background: #fff; transition: width .4s ease; }

.stats-row { display: flex; gap: 10px; margin-bottom: 18px; }
.stat {
  flex: 1; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; text-align: center;
  box-shadow: var(--shadow);
}
.stat b { display: block; font-size: 21px; font-weight: 800; color: var(--ink); }
.stat span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }

/* ---------------- week list ---------------- */
.week-list { display: flex; flex-direction: column; gap: 12px; }
.week-card {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); color: var(--ink);
  transition: transform .12s ease, border-color .15s ease;
  position: relative; overflow: hidden;
}
.week-card:active { transform: scale(.985); }
.week-card .wc-top { display: flex; align-items: center; gap: 12px; }
.wc-num {
  flex: none; width: 46px; height: 46px; border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; font-weight: 800; font-size: 15px; letter-spacing: .02em;
  box-shadow: 0 3px 10px rgba(190, 60, 50, .3);
}
.wc-infos { flex: 1; min-width: 0; display: block; }
.wc-date { display: block; font-weight: 700; font-size: 15.5px; }
.wc-jpdate { display: block; font-size: 12px; color: var(--muted); font-family: var(--font-jp); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.wc-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 99px;
  background: var(--bg-2); color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 4px;
}
.chip.v { background: var(--blue-soft); color: var(--blue); }
.chip.p { background: var(--primary-soft); color: var(--primary); }
.chip.i { background: var(--green-soft); color: var(--green); }
.wc-review {
  position: absolute; top: 12px; right: 12px;
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 1.5px solid var(--line); background: transparent; color: var(--muted);
}
.wc-review.on { background: var(--green); border-color: var(--green); color: #fff; }
.wc-review svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.wc-progress { display: block; height: 5px; border-radius: 99px; background: var(--bg-2); margin-top: 11px; overflow: hidden; }
.wc-progress i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--green), #6db98a); transition: width .3s ease; }

.section-note { font-size: 12.5px; color: var(--muted); text-align: center; padding: 18px 8px; }

/* ---------------- week view ---------------- */
.week-head {
  position: sticky; top: 63px; z-index: 30;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 10px 16px 12px; margin: 0 -16px 4px;
  border-bottom: 1px solid var(--line);
}
.week-head .wh-row { display: flex; align-items: center; gap: 8px; }
.week-head h2 { margin: 0; font-size: 18px; font-weight: 800; flex: 1; min-width: 0; }
.week-head .wh-date { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.week-head .wh-date .jp { font-family: var(--font-jp); }
.pill-btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--card); color: var(--ink-2);
  border-radius: 99px; padding: 7px 12px; font-size: 13px; font-weight: 650;
  transition: transform .12s ease;
}
.pill-btn:active { transform: scale(.94); }
.pill-btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.pill-btn.on { background: var(--green); border-color: var(--green); color: #fff; }
.pill-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

/* sections */
.sec {
  display: flex; align-items: center; gap: 9px;
  margin: 22px 0 10px; padding: 8px 4px;
  font-weight: 750; font-size: 14.5px; letter-spacing: .02em;
  color: var(--ink);
}
.sec .sec-ico {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.sec-vocab .sec-ico { background: var(--blue-soft); }
.sec-grammar .sec-ico { background: var(--primary-soft); }
.sec-notes .sec-ico, .sec-title .sec-ico { background: var(--bg-2); }
.sec-homework .sec-ico { background: var(--hl-o); }
.sec-journal .sec-ico { background: var(--hl-p); }
.sec:first-child { margin-top: 8px; }

/* vocab cards */
.vocab {
  position: relative;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 54px 13px 16px;
  margin-bottom: 10px; box-shadow: var(--shadow);
  cursor: pointer; transition: transform .12s ease;
}
.vocab:active { transform: scale(.99); }
.v-jp { font-family: var(--font-jp); font-size: 17px; font-weight: 600; line-height: 1.45; color: var(--ink); }
.v-fr { font-size: 14.5px; color: var(--blue); margin-top: 3px; }
.vocab.playing { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* text rows */
.trow {
  position: relative; display: flex; gap: 10px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 13px 14px;
  margin-bottom: 10px; box-shadow: var(--shadow);
}
.trow-text { flex: 1; min-width: 0; font-size: 15.5px; overflow-wrap: anywhere; }
.trow.playing { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.trow.has-speak { padding-right: 50px; }

/* segments */
.sg.b { font-weight: 700; }
.sg.i { font-style: italic; }
.sg.u { text-decoration: underline; text-underline-offset: 2px; }
.sg.c-blue { color: var(--blue); }
.sg.c-red { color: var(--primary); }
.sg.c-purple { color: #8a5bd0; }
.sg.c-steel { color: var(--blue); }
.sg.fr { color: var(--blue); font-style: italic; }
.sg.jp { font-family: var(--font-jp); }
.sg.bgy { background: var(--hl-y); border-radius: 3px; }
.sg.bgp { background: var(--hl-p); border-radius: 3px; }
.sg.bgg { background: var(--hl-g); border-radius: 3px; }
.sg.bgb { background: var(--hl-b); border-radius: 3px; }
.sg.bgo { background: var(--hl-o); border-radius: 3px; }
.sg.bgv { background: var(--hl-v); border-radius: 3px; }
.sg.bgs { background: var(--hl-s); border-radius: 3px; }
.sg.bggr { background: var(--hl-r); border-radius: 3px; }

/* kana mode */
.jp-kana { display: none; }
.kana-mode .jp-rom { display: none; }
.kana-mode .jp-kana { display: inline; }
.kana-mode .v-jp, .kana-mode .trow-text { font-family: var(--font-jp); }

/* masquer les traductions */
.hide-fr .v-fr { display: none; }
.hide-fr .sg.fr { display: none; }

/* speak button */
.speak-btn {
  position: absolute; top: 12px; right: 12px;
  width: 36px; height: 36px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--card);
  color: var(--primary); display: flex; align-items: center; justify-content: center;
  transition: transform .12s ease, background .2s ease, color .2s ease;
}
.speak-btn:active { transform: scale(.88); }
.speak-btn svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.speak-btn.playing { background: var(--primary); color: #fff; border-color: var(--primary); animation: pulse 1.1s ease infinite; }
.speak-btn.done { color: var(--green); border-color: color-mix(in srgb, var(--green) 45%, var(--line)); }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(207, 77, 70, .45); }
  50% { box-shadow: 0 0 0 9px rgba(207, 77, 70, 0); }
}

/* images */
.img-b { margin: 12px 0; border-radius: var(--radius); overflow: hidden; background: var(--bg-2); box-shadow: var(--shadow); }
.img-b img { display: block; width: 100%; height: auto; cursor: zoom-in; }
.img-b figcaption { font-size: 11.5px; color: var(--muted); padding: 6px 12px; }
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.img-grid .img-b { margin: 0; }
.seg-img { display: inline-block; vertical-align: middle; margin: 2px 4px; border-radius: 6px; max-height: 90px; cursor: zoom-in; }

/* flash highlight (depuis la recherche) */
.flash { animation: flashAnim 1.6s ease; }
@keyframes flashAnim {
  0%, 60% { box-shadow: 0 0 0 3px var(--gold); border-color: var(--gold); }
  100% { box-shadow: var(--shadow); }
}

/* ---------------- tabbar ---------------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  display: flex; justify-content: center; gap: 8px;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
}
.tabbar button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: transparent; border: none; color: var(--muted);
  font-size: 10.5px; font-weight: 650; letter-spacing: .03em;
  padding: 4px 20px; border-radius: 12px;
  transition: color .15s ease, background .15s ease;
}
.tabbar button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--primary); background: var(--primary-soft); }

/* ---------------- playbar ---------------- */
.playbar {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 44;
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 99px; padding: 9px 10px 9px 18px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .22);
  max-width: calc(100vw - 32px);
}
.playbar .pb-info { font-size: 13.5px; font-weight: 700; white-space: nowrap; }
.playbar .pb-info small { display: block; font-weight: 500; color: var(--muted); font-size: 11px; }
.playbar .pb-stop {
  width: 42px; height: 42px; border-radius: 50%; border: none; flex: none;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.playbar .pb-stop svg { width: 16px; height: 16px; fill: currentColor; }

/* ---------------- search ---------------- */
.search-box {
  position: sticky; top: 63px; z-index: 25;
  margin: -6px -16px 6px; padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.search-input {
  width: 100%; font-size: 16px; font-family: inherit;
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 99px; padding: 11px 16px 11px 42px; outline: none;
}
.search-input:focus { border-color: var(--primary); }
.search-ico { position: absolute; left: 28px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-ico svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.search-results .sr-week { margin: 18px 0 8px; font-weight: 800; font-size: 14px; color: var(--ink-2); display: flex; align-items: center; gap: 8px; }
.search-results .sr-week .wc-num { width: 30px; height: 30px; border-radius: 9px; font-size: 12px; }
.sr-item {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 11px 14px; margin-bottom: 9px;
  box-shadow: var(--shadow);
}
.sr-item .sr-jp { font-family: var(--font-jp); font-weight: 600; font-size: 15px; }
.sr-item .sr-fr { font-size: 13.5px; color: var(--blue); margin-top: 2px; }
mark { background: var(--hl-y); color: inherit; border-radius: 3px; padding: 0 1px; }
.empty-state { text-align: center; color: var(--muted); padding: 44px 16px; }
.empty-state .big { font-size: 40px; display: block; margin-bottom: 8px; }

/* ---------------- modal ---------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(20, 16, 12, .5);
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.modal {
  width: 100%; max-width: 560px; max-height: 86dvh; overflow: auto;
  background: var(--card); border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom));
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal .grab { width: 40px; height: 4px; border-radius: 99px; background: var(--line); margin: 6px auto 14px; }
.modal h3 { margin: 4px 0 16px; font-size: 18px; font-weight: 800; }
.set-row { margin-bottom: 18px; }
.set-row label { display: block; font-size: 13px; font-weight: 700; color: var(--ink-2); margin-bottom: 7px; }
.set-row .range-row { display: flex; align-items: center; gap: 12px; }
.set-row input[type=range] { flex: 1; accent-color: var(--primary); height: 34px; }
.set-row .range-val { width: 46px; text-align: center; font-weight: 750; font-variant-numeric: tabular-nums; }
.set-row select {
  width: 100%; font-size: 15px; font-family: inherit;
  padding: 11px 12px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--ink);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; border: none; border-radius: 13px; padding: 12px;
  font-size: 15px; font-weight: 700; color: #fff;
}
.btn.primary { background: var(--primary); }
.btn.ghost { background: var(--bg-2); color: var(--ink-2); }
.btn.danger { background: transparent; color: var(--primary); border: 1.5px solid var(--primary); }
.modal .btn + .btn { margin-top: 10px; }
.modal-note { font-size: 12px; color: var(--muted); margin-top: 14px; line-height: 1.5; }

/* ---------------- lightbox ---------------- */
.lightbox {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(12, 10, 8, .92);
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
}
.lightbox img { max-width: 100%; max-height: 92dvh; border-radius: 10px; }
.lightbox .lb-close {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); right: 14px;
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: rgba(255,255,255,.15); color: #fff; font-size: 19px;
}

/* ---------------- toast ---------------- */
#toast-root { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(86px + env(safe-area-inset-bottom)); z-index: 80; pointer-events: none; }
.toast {
  background: var(--ink); color: var(--bg);
  border-radius: 99px; padding: 10px 18px; font-size: 13.5px; font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,.3);
  animation: toastIn .25s ease;
}
@keyframes toastIn { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------- responsive ---------------- */
@media (min-width: 700px) {
  main { padding: 20px 24px 40px; }
  .week-head { margin: 0 -24px 4px; padding-left: 24px; padding-right: 24px; }
  .search-box { margin: -6px -24px 6px; padding-left: 24px; padding-right: 24px; }
  .search-ico { left: 36px; }
  .tabbar { display: none; }
  body { padding-bottom: 20px; }
  .playbar { bottom: 24px; }
  #toast-root { bottom: 24px; }
}

@media (max-width: 380px) {
  .topbar .brand small { display: none; }
  .wc-chips .chip.i { display: none; }
}
