* { box-sizing: border-box; }
html { background: var(--bg); overflow-x: hidden; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--jp-font); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
.wrap { max-width: 1200px; margin: 0 auto; padding-bottom: 80px; }
.head { display: flex; min-width: 0; align-items: center; gap: 14px; padding: 22px 20px 12px; }
.home { flex: none; color: var(--accent); font-family: var(--disp); font-size: 44px; font-weight: 700; letter-spacing: .16em; line-height: 1; text-transform: uppercase; white-space: nowrap; }
.home small { margin-left: .4em; color: inherit; font: inherit; }
.back, .sbtn { display: grid; width: 38px; height: 38px; flex: none; place-items: center; border: 0; background: transparent; }
.back { margin-left: -8px; border-radius: 50%; }
.back svg, .sbtn svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; stroke-width: 2.2; }
.grow { flex: 1 1 auto; }
.ttl { min-width: 0; flex: 1 1 auto; }
.home ~ .ttl { align-self: stretch; display: flex; flex-direction: column; justify-content: center; margin-left: 4px; padding-left: 18px; border-left: 1px solid var(--line); }
.ttl .nm { overflow: hidden; font-size: 20px; font-weight: 700; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.ttl .sub { margin-top: 4px; color: var(--muted); font-size: 12px; letter-spacing: .04em; }
.find { padding: 4px 20px 8px; }
.find[hidden], [hidden] { display: none !important; }
.find input, .req input { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); padding: 0 16px; }
.find input:focus, .req input:focus { outline: none; border-color: var(--accent); }
.req { padding: 0 20px 12px; }
.reqrow { display: flex; gap: 8px; }
.reqrow button, .library-btn { flex: none; border: 0; border-radius: 10px; background: var(--accent); color: var(--on-accent); padding: 0 18px; font-weight: 700; }
.reqrow button:disabled { opacity: .55; cursor: default; }
.reqmsg { min-height: 1.5em; margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.gen { display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; padding: 14px 20px 4px; scrollbar-width: none; }
.gen::-webkit-scrollbar, .rail::-webkit-scrollbar { display: none; }
.gen button, .gen a { position: relative; flex: none; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--muted); padding: 9px 14px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.gen button::before { position: absolute; inset: -4px 0; content: ''; }
.gen button.on { border-color: var(--ink); background: var(--ink); color: var(--bg); }
.mode { display: flex; align-items: center; gap: 26px; margin: 14px 20px 0; border-bottom: 1px solid var(--line); }
.mode button { position: relative; border: 0; background: transparent; padding: 8px 2px 10px; color: var(--muted); font-family: var(--disp); font-size: 15px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; }
.mode button[aria-selected="true"] { color: var(--accent); }
.mode button[aria-selected="true"]::after { position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; border-radius: 1px; background: var(--accent); content: ''; }
.sort { display: inline-flex; align-items: center; margin-left: auto; }
.sort button { position: relative; border: 0; background: transparent; padding: 4px 10px; color: var(--muted); font-family: var(--disp); font-size: 14px; letter-spacing: .05em; }
.sort button + button::before { position: absolute; top: 50%; left: 0; width: 1px; height: 14px; transform: translateY(-50%); background: var(--line); content: ''; }
.sort button[aria-checked="true"] { color: var(--ink); font-weight: 700; }
#mode[data-mode="ch"] .sort { display: none; }
.sec { display: flex; align-items: baseline; gap: 12px; padding: 22px 20px 10px; }
.sec h2 { margin: 0; font-family: var(--disp); font-size: 22px; letter-spacing: .08em; text-transform: uppercase; }
.sec .n { color: var(--muted); font-family: var(--disp); font-size: 13px; letter-spacing: .04em; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 22px 14px; padding: 4px 20px; }
.grid:empty::after { grid-column: 1 / -1; padding: 30px 0; color: var(--muted); content: attr(data-empty); text-align: center; }
.grid[aria-busy="true"]:empty::after { content: none; }
.card { display: block; min-width: 0; }
.th { position: relative; display: block; overflow: hidden; aspect-ratio: 16 / 9; border-radius: 10px; background: var(--surface); }
.th > img { display: block; width: 100%; height: 100%; object-fit: cover; }
.th .dur { position: absolute; right: 8px; bottom: 8px; border-radius: 4px; background: rgba(0, 0, 0, .78); color: #fff; padding: 2px 6px; font-family: var(--disp); font-size: 11px; }
.th .seenN { position: absolute; left: 8px; top: 8px; border-radius: 4px; background: rgba(0, 0, 0, .78); color: var(--accent); padding: 2px 6px; font-family: var(--disp); font-size: 11px; }
.th .prog { position: absolute; right: 0; bottom: 0; left: 0; height: 3px; background: rgba(255, 255, 255, .18); }
.th .prog i { display: block; width: var(--p, 0%); height: 100%; background: var(--accent); }
.th .nmov { position: absolute; right: 0; bottom: 0; left: 0; padding: 25px 12px 10px; background: linear-gradient(to top, rgba(0,0,0,.82), transparent); color: #fff; font-weight: 700; }
.card .cnt { display: flex; align-items: center; gap: 9px; margin-top: 8px; color: var(--ink); font-family: var(--disp); font-size: 12px; }
.vcard .row { display: -webkit-box; overflow: hidden; margin-top: 10px; color: var(--ink); font-size: 14px; font-weight: 700; line-height: 1.4; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.vcard .row .nm { display: inline; }
.card .on { border-radius: 5px; background: var(--accent-soft); color: var(--accent); padding: 3px 7px; font-size: 11px; }
.vcard .chn { display: block; overflow: hidden; margin-top: 6px; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.meta { display: inline-flex; overflow: hidden; border-radius: 5px; font-family: var(--disp); font-size: 11px; font-weight: 700; }
.meta > span { padding: 3px 7px; }
.pct { background: var(--pc, #3a7d44); color: #fff; }
.vcard .row .meta { display: inline-flex; align-items: center; margin-right: 6px; vertical-align: 1px; }
.hero { position: relative; display: block; overflow: hidden; aspect-ratio: 16 / 9; margin: 6px 20px 8px; border-radius: 18px; background: var(--surface); }
body[data-page="listening"] .hero { display: none; }
.hero .bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.hero .sh { position: absolute; inset: 0; background: linear-gradient(to top, rgba(0,0,0,.9), transparent 65%); }
.hero .txt { position: absolute; right: 0; bottom: 0; left: 0; padding: 22px; }
.hero .k { color: var(--accent); font-family: var(--disp); font-size: 13px; letter-spacing: .2em; }
.hero .t { display: block; margin-top: 8px; font-size: 28px; font-weight: 700; line-height: 1.2; }
.hero .go { display: inline-block; margin-top: 13px; border-radius: 999px; background: #fff; color: #000; padding: 10px 20px; font-weight: 700; }
.shelf { position: relative; }
.rail { display: flex; gap: 12px; overflow-x: auto; overflow-y: hidden; padding: 2px 20px 6px; scroll-snap-type: x mandatory; scroll-padding: 0 20px; scrollbar-width: none; }
.rail .card { flex: 0 0 min(260px, 72vw); scroll-snap-align: start; }
.rail .vcard { flex-basis: 300px; }
.arr { position: absolute; top: 46px; bottom: 6px; width: 56px; border: 0; color: var(--ink); font-size: 34px; display: none; align-items: center; justify-content: center; z-index: 2; }
.arr.l { left: 0; background: linear-gradient(to right, var(--bg) 30%, transparent); }
.arr.r { right: 0; background: linear-gradient(to left, var(--bg) 30%, transparent); }
.arr[hidden] { display: none !important; }
@media (hover: hover) and (pointer: fine) { .shelf:hover .arr { display: flex; } }
.more { padding: 24px; color: var(--muted); text-align: center; }
.sync { min-height: 1.5em; padding: 0 20px 8px; color: var(--muted); font-size: 13px; }
.sbtn[aria-busy="true"] svg { animation: eia-spin 1s linear infinite; }
@keyframes eia-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .sbtn[aria-busy="true"] svg { animation: none; opacity: .5; } }
.sync > span:not(:empty) ~ span:not(:empty) { margin-left: .6em; }
.history-list { display: grid; gap: 12px; padding: 4px 20px; }
.hrow { display: grid; grid-template-columns: minmax(150px, 28%) 1fr; gap: 14px; border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: var(--surface); }
.hrow .nm { display: block; font-size: 15px; font-weight: 700; }
.hrow .ch, .hrow .last, .hrow .memo { display: block; margin-top: 5px; color: var(--muted); font-size: 13px; }
.runs { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 9px; }
.run { display: inline-flex; gap: 4px; border-radius: 5px; padding: 3px 6px; background: var(--accent-soft); color: var(--accent); font-size: 11px; }
.library-shell { padding: 8px 20px 70px; }
.library-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.library-header h1 { margin: 0; font-size: 22px; }
.library-subtitle, .sort-label { color: var(--muted); font-size: 13px; }
.library-actions { display: flex; gap: 8px; }
.library-btn { min-height: 38px; }
.sort-row { display: flex; gap: 8px; margin: 18px 0; }
.unknown-words-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.unknown-word-card { display: block; overflow: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); cursor: pointer; }
.word-visual { position: relative; display: grid; min-height: 110px; place-items: center; background: #222126; }
.word-visual-illust { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.word-initial { position: relative; color: var(--accent); font-family: var(--disp); font-size: 56px; font-weight: 700; }
.term-badge { position: absolute; top: 8px; left: 8px; z-index: 1; border-radius: 4px; background: var(--accent-soft); color: var(--accent); padding: 3px 6px; font-size: 11px; }
.unknown-word-body { padding: 12px; }
.unknown-word-title { margin: 0; font-size: 18px; }
.unknown-word-canonical, .unknown-word-date, .unknown-word-ipa { margin-top: 5px; color: var(--muted); font-size: 12px; }
.unknown-word-core, .unknown-word-note { margin-top: 8px; font-size: 13px; }
.unknown-word-detail-header { display: flex; align-items: center; gap: 10px; margin: 18px 0; }
.unknown-word-encounter-list { display: grid; gap: 10px; }
.unknown-word-encounter-card { display: grid; grid-template-columns: 38% 1fr; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 10px; background: var(--surface); }
.unknown-word-encounter-thumb { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; }
.unknown-word-encounter-body { min-width: 0; }
.unknown-word-platform-badge, .unknown-word-encounter-time, .unknown-word-encounter-date { margin-right: 6px; color: var(--muted); font-size: 12px; }
.unknown-word-history-title { margin-top: 6px; font-weight: 700; }
.unknown-word-encounter-sentence { margin-top: 6px; color: var(--muted); font-family: system-ui, "Helvetica Neue", Arial, sans-serif; font-size: 13px; }
.empty-state { padding: 24px 0; color: var(--muted); }
@media (max-width: 600px) {
  .wrap { padding-bottom: calc(80px + env(safe-area-inset-bottom)); }
  .head { gap: 10px; padding: 24px 22px 10px; }
  .home { font-size: 46px; letter-spacing: .2em; }
  .home small { display: none; }
  .back, .sbtn { width: 44px; height: 44px; }
  .find, .req, .sync { padding-right: 22px; padding-left: 22px; }
  body, .wrap { overflow-x: clip; }
  .gen { position: sticky; top: 0; z-index: 6; background: var(--bg); padding: 8px 22px 2px; }
  .mode { position: sticky; top: var(--genh, 48px); z-index: 6; gap: 16px; margin: 12px 0 0; padding: 0 22px; background: var(--bg); }
  .mode .sort { flex: none; margin: 0 0 0 auto; }
  .mode .sort button { padding: 12px 8px; font-size: 13px; }
  .mode .sort button:last-child { padding-right: 0; }
  .rail { gap: 10px; padding: 2px 22px 6px; scroll-padding: 0 22px; }
  .rail .card { flex-basis: 62vw; }
  .rail .vcard { flex-basis: 78vw; }
  .shelf { scroll-margin-top: 104px; }
  .sec { padding-right: 22px; padding-left: 22px; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 10px; padding-right: 22px; padding-left: 22px; }
  .vcard .row { font-size: 15px; }
  .hero { margin-right: 22px; margin-left: 22px; border-radius: 14px; }
  .hero .t { font-size: 21px; }
  body[data-page="listening"] .hero { display: block; overflow: visible; aspect-ratio: auto; margin: 8px 22px 6px; border-radius: 0; background: transparent; }
  body[data-page="listening"] .hero .th { position: relative; display: block; overflow: hidden; aspect-ratio: 16 / 9; border-radius: 14px; background: var(--surface); }
  body[data-page="listening"] .hero .th .bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
  body[data-page="listening"] .hero .body { display: block; padding: 10px 0 6px; }
  body[data-page="listening"] .hero .body .t { display: -webkit-box; overflow: hidden; color: var(--ink); font-size: 15px; font-weight: 700; line-height: 1.35; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
  body[data-page="listening"] .hero .body .s { display: block; margin-top: 3px; color: var(--muted); font-size: 13px; }
  body[data-page="listening"] #hist { display: none; }
  .hrow { grid-template-columns: 40% 1fr; }
  .history-list, .library-shell { padding-right: 22px; padding-left: 22px; }
  .unknown-words-grid { grid-template-columns: 1fr; }
}



body[data-page="genre"] #gridCh { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
body[data-page="genre"] #gridVd { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
body[data-page="genre"] .mode { margin-top: 0; }
body[data-page="genre"] .mode .sort { margin-bottom: 6px; }
body[data-page="genre"] #sortSlot { margin-left: auto; }
body[data-page="genre"] #gridCh, body[data-page="genre"] #gridVd { margin-top: 22px; }

body[data-page="channel"] #grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
body[data-page="channel"] #chLogo { display: block; width: 44px; height: 44px; flex: none; overflow: hidden; border-radius: 50%; background: var(--surface); }
body[data-page="channel"] #chLogo:empty { display: none; }
body[data-page="channel"] #chLogo img { display: block; width: 100%; height: 100%; object-fit: cover; }

body[data-page="unknown-words"] .unknown-words-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
body[data-page="unknown-words"] .unknown-word-card { display: flex; flex-direction: column; border-radius: 14px; box-shadow: inset 0 0 0 1px var(--line); }
body[data-page="unknown-words"] .word-visual { min-height: 0; aspect-ratio: 4 / 3; background: #101013; overflow: hidden; }
body[data-page="unknown-words"] .word-initial { font-size: 64px; line-height: 1; }
body[data-page="unknown-words"] .term-badge { left: 10px; top: 10px; height: 20px; padding: 0 7px; display: inline-flex; align-items: center; background: rgba(0, 0, 0, .72); color: #fff; font-family: var(--disp); font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
body[data-page="unknown-words"] .term-badge.phrase { background: var(--accent); color: var(--on-accent); }
body[data-page="unknown-words"] .unknown-word-body { display: flex; flex-direction: column; gap: 4px; padding: 12px 14px 14px; }
body[data-page="unknown-words"] .unknown-word-detail-header { margin: 4px 0 14px; }
body[data-page="unknown-words"] .unknown-word-encounter-card { grid-template-columns: 200px 1fr; gap: 16px; padding: 12px; border-radius: 14px; box-shadow: inset 0 0 0 1px var(--line); align-items: start; }
body[data-page="unknown-words"] .unknown-word-encounter-card + .unknown-word-encounter-card { margin-top: 10px; }
body[data-page="unknown-words"] .unknown-word-encounter-thumb { border-radius: 10px; background: #101013; }
body[data-page="unknown-words"] .unknown-word-encounter-thumb--netflix { display: grid; place-items: center; font-family: var(--disp); font-size: 34px; font-weight: 700; color: #e50914; }
body[data-page="unknown-words"] .unknown-word-encounter-body { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
body[data-page="unknown-words"] .unknown-word-history-title, body[data-page="unknown-words"] .unknown-word-encounter-sentence { flex: 0 0 100%; }

body[data-page="history"] .history-list { display: flex; flex-direction: column; gap: 10px; padding: 4px 20px; }
body[data-page="history"] .hrow { grid-template-columns: 120px minmax(0, 1fr); gap: 12px; align-items: center; border: 0; border-radius: 12px; padding: 8px; box-shadow: inset 0 0 0 1px var(--line); }
body[data-page="history"] .hrow .th { width: 120px; height: 68px; aspect-ratio: auto; border-radius: 8px; object-fit: cover; }
body[data-page="history"] .hrow .th.nf { display: grid; place-items: center; background: #101013; color: #e50914; font-family: var(--disp); font-size: 30px; font-weight: 700; }
body[data-page="history"] .hrow .body { min-width: 0; }
body[data-page="history"] .hrow .nm { overflow: hidden; font-size: 15px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
body[data-page="history"] .hrow .l2 { display: flex; align-items: center; gap: 6px; min-width: 0; margin-top: 6px; overflow: hidden; }
body[data-page="history"] .runs { flex: 0 1 auto; flex-direction: row-reverse; flex-wrap: wrap; justify-content: flex-end; gap: 4px; min-width: min-content; max-width: 55%; height: 18px; margin-top: 0; overflow: hidden; }
body[data-page="history"] .run { flex: none; align-items: center; height: 18px; padding: 0 6px; border-radius: 5px; color: #fff; font-family: var(--disp); font-size: 11px; font-weight: 700; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
body[data-page="history"] .hrow .ch { flex: 0 1 auto; min-width: 0; margin-top: 0; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
body[data-page="history"] .hrow .dt { flex: none; color: var(--muted); font-size: 12px; white-space: nowrap; }
body[data-page="history"] .hrow .ch + .dt::before { content: '·'; margin-right: 6px; }
body[data-page="history"] .run.none, body[data-page="history"] .run.comp-zero { background: transparent; box-shadow: inset 0 0 0 1px var(--line); color: var(--muted); }
body[data-page="history"] .run.comp-0 { background: rgb(220, 38, 38); }
body[data-page="history"] .run.comp-1 { background: rgb(236, 72, 153); }
body[data-page="history"] .run.comp-2 { background: rgb(168, 85, 247); }
body[data-page="history"] .run.comp-3 { background: rgb(99, 102, 241); }
body[data-page="history"] .run.comp-4 { background: rgb(20, 184, 166); }
body[data-page="history"] .run.comp-5 { background: rgb(34, 197, 94); }
body[data-page="history"] .run.comp-6 { background: rgb(163, 210, 51); }
body[data-page="history"] .run.comp-7 { background: rgb(234, 179, 8); }
body[data-page="history"] .run.comp-8 { background: rgb(245, 139, 10); }
body[data-page="history"] .run.comp-9 { background: rgb(255, 140, 0); }

@media (max-width: 600px) {
  body[data-page="genre"] .mode { position: static; top: auto; z-index: auto; flex-wrap: wrap; gap: 8px; margin: 0 22px; padding: 0; background: transparent; }
  body[data-page="genre"] .mode .sort { margin: 0; }
  body[data-page="genre"] .mode .sort button { padding: 10px 4px; }
  body[data-page="genre"] .mode .sort button:last-child { padding-right: 0; }
  body[data-page="genre"] #gridCh { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  body[data-page="genre"] #gridVd { grid-template-columns: 1fr; }

  body[data-page="channel"] .head { position: sticky; top: 0; z-index: 6; background: var(--bg); }
  body[data-page="channel"] .find { position: sticky; top: var(--headh, 72px); z-index: 6; background: var(--bg); }
  body[data-page="channel"] #chLogo { width: 32px; height: 32px; }
  body[data-page="channel"] #grid { grid-template-columns: 1fr; gap: 12px; }
  body[data-page="channel"] #grid .card { display: grid; grid-template-columns: 42% 1fr; gap: 10px; align-items: start; }
  body[data-page="channel"] #grid .card .th { grid-column: 1; grid-row: 1 / 3; }
  body[data-page="channel"] #grid .card .row { grid-column: 2; grid-row: 1; margin-top: 0; -webkit-line-clamp: 3; }
  body[data-page="channel"] #grid .card .chn { grid-column: 2; grid-row: 2; }

  body[data-page="unknown-words"] .unknown-words-grid { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  body[data-page="unknown-words"] .word-visual { aspect-ratio: 16 / 9; }
  body[data-page="unknown-words"] .word-initial { font-size: 48px; }
  body[data-page="unknown-words"] .unknown-word-encounter-card { grid-template-columns: 38% 1fr; gap: 10px; padding: 10px; }

  body[data-page="history"] .history-list { padding: 4px 22px; }
  body[data-page="history"] .hrow { gap: 10px; }
}
