:root {
  color-scheme: light dark;
  --desk: #f3eee7;
  --bar: #faf6ef;
  --paper: #fffcf6;
  --ink: #282324;
  --muted: #686062;
  --line: #e6ddd3;
  --line-strong: #d5c6bc;
  --accent: #74475e;
  --tint: #f4e9ed;
  --row-hover: #f9f0f2;
  --cover: #eee4df;
  --shadow: #50312b12;
  --red: #f16a64;
  --yellow: #efb644;
  --green: #55bb6b;
  --serif: "Hiragino Mincho ProN", "Yu Mincho", "Songti SC", "Noto Serif CJK JP", serif;
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --desk: #201c21;
    --bar: #262128;
    --paper: #2b252c;
    --ink: #f3e9e6;
    --muted: #c0afb6;
    --line: #423741;
    --line-strong: #5e4d59;
    --accent: #e3adc8;
    --tint: #412d3c;
    --row-hover: #392c37;
    --cover: #463945;
    --shadow: #0004;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--desk); color: var(--ink); }
button, select, input, textarea { font: inherit; color: inherit; }
button, select { cursor: pointer; }
button:disabled { cursor: default; opacity: .45; }
button:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.skip { position: absolute; top: 8px; left: 8px; transform: translateY(-150%); z-index: 3; color: var(--accent); background: var(--paper); padding: 8px; }
.skip:focus { transform: none; }

.topbar { border-bottom: 1px solid var(--line); background: var(--bar); }
.masthead, .layout { width: min(100% - 64px, 1240px); margin-inline: auto; }
.masthead { min-height: 76px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand img { flex: none; }
.brand strong { display: block; font-size: 1.06rem; letter-spacing: .06em; }
.brand small { color: var(--muted); font-size: .72rem; letter-spacing: .09em; }

.action {
  min-height: 44px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--paper);
  padding: 7px 13px;
  font-size: .83rem;
  font-weight: 650;
}
.action:not(:disabled):hover { background: var(--tint); }
.action.add, .action.primary { color: var(--accent); background: var(--tint); border-color: transparent; }
.add span { margin-inline-end: 3px; font-size: 1rem; }
.action.primary:hover, .action.add:hover { border-color: var(--accent); }

.layout { display: grid; grid-template-columns: 206px minmax(0, 1fr); gap: 34px; padding-block: 38px 56px; align-items: start; }
aside { position: sticky; top: 30px; min-width: 0; max-height: calc(100vh - 60px); overflow: auto; padding: 2px 4px 12px; }
.eyebrow { font-size: .73rem; font-weight: 700; letter-spacing: .11em; color: var(--accent); }
.contents-title { border-bottom: 1px solid var(--line-strong); padding: 6px 4px 14px; }
.contents-title span { color: var(--muted); font-weight: 400; margin-inline-start: 7px; }
.lesson-name { color: var(--muted); font-size: .81rem; margin: 20px 6px 8px; overflow-wrap: anywhere; }
.nav-item { display: flex; justify-content: space-between; align-items: center; gap: 6px; text-align: start; width: 100%; padding: 8px 10px; min-height: 44px; background: none; border: 0; border-inline-start: 3px solid transparent; border-radius: 6px; font-size: .92rem; }
.nav-item span:first-child { overflow-wrap: anywhere; }
.nav-item:hover { background: var(--row-hover); }
.nav-item[aria-current] { background: var(--tint); border-inline-start-color: var(--accent); color: var(--accent); font-weight: 700; }
.nav-count { font-size: .72rem; color: var(--muted); white-space: nowrap; }
.progress-card { margin-top: 28px; padding: 15px 13px; border: 1px solid var(--line-strong); border-radius: 9px; }
.progress-card p { margin: 7px 0; font-size: .82rem; color: var(--muted); }
progress { display: block; width: 100%; height: 7px; accent-color: var(--accent); }
.mobile-nav { display: none; }

.sheet {
  position: relative;
  isolation: isolate;
  border: 1px solid var(--line-strong);
  border-radius: 13px 13px 8px 8px;
  background: var(--paper);
  box-shadow: 0 3px 0 -1px var(--paper), 0 4px 0 -1px var(--line-strong), 0 7px 0 -2px var(--paper), 0 8px 0 -2px var(--line-strong), 0 17px 40px var(--shadow);
}
.sheet-header {
  position: relative;
  overflow: hidden;
  border-radius: inherit;
  padding: 32px clamp(22px, 5vw, 56px) 30px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(108deg, var(--tint), var(--paper) 76%);
}
.book-label { display: flex; align-items: center; gap: 10px; position: relative; z-index: 1; color: var(--accent); font-weight: 680; letter-spacing: .12em; font-size: .76rem; }
.label-rule { width: 24px; height: 1px; background: currentColor; opacity: .6; }
h1 { position: relative; z-index: 1; font-family: var(--serif); font-size: clamp(2rem, 5vw, 3.55rem); line-height: 1.14; letter-spacing: .045em; margin: 14px 0 10px; overflow-wrap: anywhere; }
.section-meta { position: relative; z-index: 1; margin: 0; color: var(--muted); font-size: .85rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.stamp { position: absolute; right: 5%; top: 50%; transform: translateY(-50%) rotate(9deg); display: grid; place-items: center; width: 112px; height: 112px; border-radius: 25px; border: 3px double currentColor; color: var(--accent); opacity: .12; font: 700 4.25rem var(--serif); pointer-events: none; }

.study-bar { display: flex; align-items: center; justify-content: space-between; gap: 9px 14px; flex-wrap: wrap; margin: 18px 24px 10px; }
.study-bar p { margin: 0; color: var(--muted); font-size: .82rem; }
.controls { display: flex; flex-wrap: wrap; gap: 7px; }
.legend { display: flex; flex-wrap: wrap; gap: 7px 15px; color: var(--muted); margin: 0 24px 14px; font-size: .74rem; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .dot { width: 9px; height: 9px; }
.words { width: calc(100% - 48px); margin-inline: 24px; table-layout: fixed; border-collapse: collapse; }
.number-col { width: 46px; }
.term-col { width: 43%; }
.mark-col { width: 52px; }
thead { color: var(--accent); background: var(--tint); }
th { font-weight: 700; font-size: .76rem; text-align: left; padding: 9px 8px; }
th:first-child, th:last-child { text-align: center; }
td { padding: 4px 0; border-bottom: 1px solid var(--line); }
.row-number { color: var(--muted); font-size: .74rem; text-align: center; font-variant-numeric: tabular-nums; }
.cover { position: relative; display: flex; align-items: center; width: 100%; min-height: 48px; padding: 6px 8px; border: 0; border-radius: 5px; background: transparent; text-align: start; overflow-wrap: anywhere; line-height: 1.45; }
.cover:hover { background: var(--row-hover); }
.answer { display: block; width: 100%; }
.cover-hint { display: none; }
.cover.covered { background: var(--cover); }
.cover.covered:hover { background: var(--tint); }
.covered .answer { visibility: hidden; }
.covered .cover-hint { display: grid; place-items: center; position: absolute; inset: 0; font-size: .73rem; color: var(--muted); letter-spacing: .06em; }
.term-line, .notes { display: flex; align-items: baseline; gap: 4px 8px; flex-wrap: wrap; }
.term { font: 700 1.17rem/1.35 var(--serif); min-width: 0; }
.accent, .notes, .part { color: var(--muted); font-size: .74rem; }
.accent { color: var(--accent); }
.notes:empty { display: none; }
.part { color: var(--accent); }
.meaning { font-size: .91rem; }

.mark { text-align: center; }
.mark-button { display: inline-grid; place-items: center; width: 44px; height: 44px; max-width: 100%; background: none; border: 0; border-radius: 50%; padding: 0; }
.mark-button:hover { background: var(--tint); }
.mark-button[aria-disabled="true"] { cursor: wait; opacity: .55; }
.dot { display: block; width: 17px; height: 17px; border: 1px solid var(--line-strong); border-radius: 50%; }
.dot[data-status="0"] { border-color: var(--muted); }
.dot:not([data-status="0"]) { border-color: #0002; box-shadow: inset 0 1px 1px #fff6; }
.dot[data-status="1"] { background: var(--red); }
.dot[data-status="2"] { background: var(--yellow); }
.dot[data-status="3"] { background: var(--green); }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 20px 24px; }
.pagination span { color: var(--muted); font-size: .81rem; }

.live:not(:empty) { position: fixed; z-index: 2; bottom: max(20px, env(safe-area-inset-bottom)); right: 20px; max-width: calc(100% - 40px); padding: 10px 14px; border: 1px solid var(--line-strong); background: var(--paper); box-shadow: 0 4px 18px var(--shadow); border-radius: 9px; color: var(--accent); }
dialog { width: min(calc(100% - 26px), 530px); max-height: calc(100dvh - 28px); border: 1px solid var(--line-strong); border-radius: 14px; background: var(--paper); color: var(--ink); padding: 20px; }
dialog::backdrop { background: #24182086; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.dialog-head h2 { margin: 0; font: 700 1.55rem var(--serif); }
.close { min-width: 44px; font-size: 1.1rem; }
form label { display: grid; gap: 5px; margin-block: 10px; font-size: .83rem; font-weight: 700; }
input, textarea, select { width: 100%; min-height: 44px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--bar); padding: 8px 10px; }
input, textarea { font-size: 1rem; font-weight: 400; }
textarea { resize: vertical; tab-size: 4; }
#import-help { color: var(--muted); font-size: .8rem; line-height: 1.55; }
.error { color: var(--accent); font-size: .83rem; font-weight: 700; }
.error:empty { display: none; }

@media (max-width: 820px) {
  .masthead, .layout { width: calc(100% - 36px); }
  .layout { display: block; padding-block: 16px 36px; }
  aside { position: static; max-height: none; overflow: visible; padding: 0 0 14px; }
  .contents-title, #contents, .progress-card { display: none; }
  .mobile-nav { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 12px; color: var(--muted); font-size: .82rem; }
  .mobile-nav select { color: var(--ink); font-size: 1rem; }
}

@media (max-width: 480px) {
  .masthead, .layout { width: calc(100% - 24px); }
  .masthead { min-height: 64px; }
  .sheet-header { padding: 23px 16px; }
  .stamp { width: 77px; height: 77px; border-radius: 16px; font-size: 2.85rem; }
  .study-bar { margin: 12px 10px 10px; }
  .legend { margin: 0 10px 11px; gap: 6px 10px; }
  .words { margin-inline: 5px; width: calc(100% - 10px); }
  .number-col { width: 29px; }
  .mark-col { width: 44px; }
  .term-col { width: 43%; }
  .cover, th { padding-inline: 5px; }
  .term { font-size: 1.02rem; }
  .meaning { font-size: .84rem; }
  .pagination { padding: 16px 10px; }
}

.audio-col { width: 46px; }
.words th:nth-child(2) { text-align: center; }
.voice-credit { text-align: center; margin: 0 12px 24px; color: var(--muted); font-size: .75rem; }

@media (max-width: 480px) {
  .audio-col { width: 44px; }
  .term-col { width: 37%; }
}

.audio-button { color: var(--muted); }
.audio-button:hover, .audio-button.is-playing { color: var(--accent); }
.audio-button svg { width: 20px; height: 20px; fill: currentColor; }
.audio-button.is-playing path { animation: audio-wave 900ms steps(1, end) infinite; }
.audio-button.is-playing path:nth-child(2) { animation-name: audio-wave-middle; }
.audio-button.is-playing path:nth-child(3) { animation-name: audio-wave-outer; }

@keyframes audio-wave {
  0%, 100% { opacity: 1; }
}
@keyframes audio-wave-middle {
  0% { opacity: 0; }
  33% { opacity: 1; }
}
@keyframes audio-wave-outer {
  0% { opacity: 0; }
  66% { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .audio-button.is-playing path { animation: none; }
}

.autoplay-controls { display: inline-flex; align-items: center; gap: 6px; }
.icon-action { display: inline-grid; place-items: center; width: 44px; padding: 0; }
.icon-action svg { width: 22px; height: 22px; fill: currentColor; }
.icon-action.is-active { color: var(--accent); background: var(--tint); }
.icon-action .pause-shape, .icon-action.is-active .play-shape { display: none; }
.icon-action.is-active .pause-shape { display: inline; }

.words tr.is-reading { background: var(--tint); }
.words tr.is-reading .row-number {
  box-shadow: inset 3px 0 var(--accent);
  color: var(--accent);
  font-weight: 700;
}

.study-bar .controls { flex: 1 1 auto; justify-content: flex-end; }
.study-bar .autoplay-controls { margin-inline-start: auto; }
#autoplay-form output { color: var(--accent); font-variant-numeric: tabular-nums; }
#autoplay-form input[type="range"] { width: 100%; accent-color: var(--accent); padding: 0; }

#autoplay-form .autoplay-controls { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }

#mark-filter { position: relative; margin: 0; }
#mark-filter summary { cursor: pointer; list-style: none; white-space: nowrap; }
#mark-filter summary::-webkit-details-marker { display: none; }
#mark-filter.is-filtered summary { text-decoration: underline; }
.mark-options {
  position: absolute; z-index: 3; inset-inline-end: 0; min-width: 132px;
  padding: 8px; text-align: start; color: var(--ink); background: var(--paper);
  border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 4px 14px var(--shadow);
}
.mark-options label { display: flex; align-items: center; gap: 6px; min-height: 34px; white-space: nowrap; }
.mark-options input { width: auto; min-height: 0; accent-color: var(--accent); }
.mark-options .dot { width: 10px; height: 10px; }
.jump-number { border: 0; background: transparent; color: inherit; width: 100%; min-height: 44px; padding: 0; user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
#filter-empty { text-align: center; color: var(--muted); padding: 12px; }

.words .row-number, .jump-number {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.words tr.is-holding {
  background: linear-gradient(var(--tint), var(--tint)) left center / 0% 100% no-repeat;
  animation: word-hold 1s linear forwards;
}
@keyframes word-hold {
  to { background-size: 100% 100%; }
}
@media (prefers-reduced-motion: reduce) {
  .words tr.is-holding { animation-timing-function: steps(1, end); }
}

.mastery-button { touch-action: manipulation; }

.account-area { display: flex; align-items: center; gap: 10px; }
.account-area a.action { text-decoration: none; }
.account-menu { position: relative; }
.account-menu summary { cursor: pointer; list-style: none; }
.account-menu summary::-webkit-details-marker { display: none; }
.account-popover { position: absolute; right: 0; top: calc(100% + 10px); z-index: 20; width: min(280px, 85vw); padding: 18px; border-radius: 16px; background: var(--paper); color: var(--ink); border: 1px solid var(--line); box-shadow: 0 10px 35px #0002; display: grid; gap: 12px; }
.account-popover > span { font-size: 13px; overflow-wrap: anywhere; }
.account-popover > small { opacity: .65; }
.account-popover > a { color: inherit; font-size: 13px; }
.account-area [hidden] { display: none; }
