:root {
  color-scheme: light;
  --page: #f7f3ea;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #202124;
  --muted: #6b655b;
  --line: #ded6c7;
  --accent: #b43b2f;
  --accent-strong: #8e2e25;
  --green: #2d6d55;
  --blue: #355f8a;
  --shadow: 0 18px 60px rgba(43, 35, 24, 0.12);
  font-family: "Noto Sans SC", "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.66), rgba(255, 255, 255, 0) 280px),
    var(--page);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.skip-link {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 20;
  transform: translateY(-140%);
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
}

.skip-link:focus {
  transform: translateY(0);
}

.page {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 18px 0 116px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: 12px 0;
  background: rgba(247, 243, 234, 0.92);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand img {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  flex: 0 0 auto;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.2;
}

.brand strong {
  font-size: 17px;
}

.brand small {
  color: var(--muted);
  margin-top: 2px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button,
.chip,
.bookmark-button {
  border: 1px solid transparent;
  border-radius: 6px;
  min-height: 40px;
  padding: 0 14px;
  background: var(--surface-strong);
  color: var(--ink);
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.button:focus-visible,
.chip:focus-visible,
.bookmark-button:focus-visible,
.search-box input:focus-visible {
  outline: 3px solid rgba(53, 95, 138, 0.25);
  outline-offset: 2px;
}

.button:hover,
.chip:hover,
.bookmark-button:hover {
  transform: translateY(-1px);
}

.button-primary {
  background: var(--accent);
  color: #fff;
}

.button-primary:hover {
  background: var(--accent-strong);
}

.button-outline,
.chip {
  border-color: var(--line);
}

.main {
  display: grid;
  gap: 18px;
}

.study-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 420px);
  gap: 24px;
  align-items: end;
  padding: 34px 0 14px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(38px, 6vw, 72px);
  line-height: 1.02;
  letter-spacing: 0;
}

.summary {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 18px;
}

.stats-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
  box-shadow: var(--shadow);
}

.stats-panel div {
  min-width: 0;
  padding: 18px;
  background: var(--surface-strong);
}

.stats-panel span,
.meta,
.source-line,
.status-line {
  color: var(--muted);
}

.stats-panel span {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}

.stats-panel strong {
  font-size: 28px;
  line-height: 1;
}

.controls {
  position: sticky;
  top: 72px;
  z-index: 9;
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 12px 16px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  backdrop-filter: blur(14px);
  box-shadow: 0 12px 42px rgba(43, 35, 24, 0.08);
}

.search-box {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.search-box span {
  color: var(--muted);
  font-size: 14px;
}

.search-box input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
}

.filter-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chip.is-active {
  border-color: var(--blue);
  background: #edf4fb;
  color: #173f66;
}

.status-line {
  grid-column: 1 / -1;
  min-height: 20px;
  margin: 0;
  font-size: 14px;
}

.word-list {
  display: grid;
  gap: 12px;
}

.word-card {
  display: grid;
  grid-template-columns: 78px minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  scroll-margin-top: 158px;
}

.word-card.is-bookmarked {
  border-color: rgba(180, 59, 47, 0.55);
  box-shadow: inset 4px 0 0 var(--accent);
}

.rank {
  display: grid;
  place-items: center;
  width: 64px;
  height: 64px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--blue);
  font-weight: 800;
}

.word-main {
  min-width: 0;
}

.word-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.jp-word {
  font-family: "Yu Gothic", "Meiryo", "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 31px;
  line-height: 1.16;
  overflow-wrap: anywhere;
}

.kana {
  color: var(--green);
  font-size: 18px;
  overflow-wrap: anywhere;
}

.meaning {
  margin: 8px 0 10px;
  font-size: 18px;
  line-height: 1.55;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  font-size: 13px;
}

.example {
  margin-top: 14px;
}

.example summary {
  color: var(--blue);
  font-weight: 700;
  width: max-content;
  max-width: 100%;
}

.example-body {
  display: grid;
  gap: 8px;
  margin-top: 10px;
  padding: 14px;
  border-left: 3px solid var(--green);
  background: #f3faf6;
  border-radius: 0 6px 6px 0;
}

.example-body p {
  margin: 0;
  line-height: 1.55;
}

.example-jp {
  font-size: 18px;
}

.example-kana {
  color: #3d705c;
}

.example-zh {
  color: #46433e;
}

.bookmark-button {
  white-space: nowrap;
  border-color: var(--line);
}

.bookmark-button.is-saved {
  border-color: var(--accent);
  background: #fff2ef;
  color: var(--accent-strong);
}

.empty-state {
  padding: 44px 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
}

.source-line {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-top: 10px;
  font-size: 13px;
}

.source-line a {
  color: var(--blue);
  white-space: nowrap;
}

.float-jump {
  position: fixed;
  right: max(14px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 18;
  display: grid;
  gap: 8px;
  width: clamp(42px, 4.4vw, 52px);
}

.jump-button {
  display: grid;
  place-items: center;
  width: clamp(42px, 4.4vw, 52px);
  height: clamp(42px, 4.4vw, 52px);
  border: 1px solid rgba(53, 95, 138, 0.24);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.94);
  color: var(--blue);
  box-shadow: 0 10px 30px rgba(43, 35, 24, 0.16);
  backdrop-filter: blur(12px);
  transition: background-color 160ms ease, color 160ms ease, opacity 160ms ease, transform 160ms ease;
}

.jump-button span {
  font-size: clamp(22px, 2.8vw, 28px);
  line-height: 1;
  font-weight: 800;
}

.jump-button:hover {
  transform: translateY(-1px);
  background: #edf4fb;
}

.jump-button:focus-visible {
  outline: 3px solid rgba(53, 95, 138, 0.25);
  outline-offset: 2px;
}

.jump-button:disabled {
  cursor: default;
  opacity: 0.42;
  transform: none;
}

@media (max-width: 820px) {
  .page {
    width: min(100% - 24px, 1180px);
    padding-bottom: 104px;
  }

  .topbar,
  .study-head,
  .controls {
    position: static;
  }

  .topbar,
  .study-head,
  .controls,
  .source-line {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
  }

  .top-actions,
  .filter-row {
    justify-content: flex-start;
  }

  .study-head {
    padding-top: 22px;
  }

  h1 {
    font-size: 42px;
  }

  .stats-panel {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stats-panel div {
    padding: 14px 12px;
  }

  .stats-panel strong {
    font-size: 22px;
  }

  .word-card {
    grid-template-columns: 54px minmax(0, 1fr);
    gap: 12px;
    padding: 14px;
    scroll-margin-top: 18px;
  }

  .rank {
    width: 48px;
    height: 48px;
    font-size: 14px;
  }

  .bookmark-button {
    grid-column: 2;
    justify-self: start;
  }

  .jp-word {
    font-size: 27px;
  }

  .float-jump {
    right: max(10px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    gap: 7px;
    width: 44px;
  }

  .jump-button {
    width: 44px;
    height: 44px;
  }
}

@media (max-width: 520px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .brand {
    width: 100%;
  }

  .brand strong {
    font-size: 16px;
  }

  .top-actions,
  .filter-row {
    width: 100%;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .chip {
    flex: 1 1 auto;
  }

  .search-box {
    grid-template-columns: 1fr;
  }

  .stats-panel {
    grid-template-columns: 1fr;
  }
}
