:root {
  --bg: #f5f4f0;
  --surface: #f8f7f3;
  --ink: #0d0d0d;
  --muted: #706e68;
  --line: rgba(13, 13, 13, 0.16);
  --soft-line: rgba(13, 13, 13, 0.08);
  --shadow: rgba(48, 38, 24, 0.16);
  --active: rgba(255, 255, 255, 0.72);
  font-family: "Helvetica Neue", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
}

body {
  letter-spacing: 0;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.34;
  background:
    radial-gradient(circle at 50% 12%, rgba(255, 255, 255, 0.78), transparent 28%),
    linear-gradient(135deg, rgba(13, 13, 13, 0.025), transparent 30%, rgba(255, 255, 255, 0.3) 66%, transparent);
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.deck-header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  background: rgba(245, 244, 240, 0.82);
  backdrop-filter: blur(18px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 46px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  color: inherit;
  display: inline-grid;
  gap: 2px;
  line-height: 0.92;
  font-weight: 650;
  text-decoration: none;
}

.brand__main {
  font-size: 18px;
}

.brand__sub {
  font-size: 11px;
}

.deck-nav {
  display: flex;
  align-items: center;
  gap: 34px;
  font-size: 13px;
  font-weight: 560;
}

.deck-nav a,
.nav-button {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 5px 0;
  text-decoration: none;
}

.github-button {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(13, 13, 13, 0.16);
  border-radius: 50%;
  color: var(--ink);
  background: rgba(248, 247, 243, 0.72);
  text-decoration: none;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}

.github-button:hover {
  border-color: rgba(13, 13, 13, 0.42);
  background: rgba(248, 247, 243, 0.95);
  transform: translateY(-1px);
}

.github-button svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.nav-current {
  position: relative;
  padding-bottom: 5px;
}

.nav-current::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  border-bottom: 1px solid currentColor;
}

.deck-main {
  position: relative;
  z-index: 1;
  width: min(1240px, calc(100vw - 64px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

.deck-topline {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 26px 0 20px;
}

.deck-topline h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 68px);
  line-height: 0.9;
  font-weight: 760;
}

.deck-topline p {
  margin: 13px 0 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 560;
}

.deck-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.deck-stats span,
.settings-strip label {
  border: 1px solid rgba(13, 13, 13, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.46);
}

.deck-stats span {
  padding: 8px 11px;
  border-radius: 999px;
}

.study-panel {
  position: sticky;
  top: 76px;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(210px, 1fr) auto minmax(420px, 1.8fr);
  align-items: center;
  gap: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 247, 243, 0.9);
  box-shadow: 0 18px 45px rgba(48, 38, 24, 0.12);
  backdrop-filter: blur(18px);
}

.now-playing {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.now-playing img {
  flex: 0 0 auto;
  width: 54px;
  height: 40px;
  object-fit: cover;
  border: 1px solid rgba(13, 13, 13, 0.08);
  border-radius: 6px;
  background: #efe9da;
  box-shadow: 0 8px 16px rgba(48, 38, 24, 0.08);
}

.now-playing span {
  display: block;
  font-size: 26px;
  line-height: 1;
  font-weight: 760;
}

.now-playing small {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  font-weight: 560;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.deck-controls {
  display: flex;
  align-items: center;
  gap: 9px;
}

.round-control,
.row-play {
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
  box-shadow: 0 9px 18px rgba(48, 38, 24, 0.1);
}

.round-control {
  position: relative;
  width: 38px;
  height: 38px;
  font-size: 16px;
}

.primary-control {
  width: 44px;
  height: 44px;
  font-size: 18px;
  color: #fff;
  border-color: rgba(13, 13, 13, 0.84);
  background: #171717;
}

.round-control.is-active,
.row-play.is-active {
  color: var(--ink);
  border-color: rgba(13, 13, 13, 0.58);
  background: #fff;
  box-shadow: 0 12px 24px rgba(48, 38, 24, 0.16);
}

.primary-control.is-active {
  color: #fff;
  border-color: rgba(13, 13, 13, 0.84);
  background: #171717;
}

.settings-strip {
  display: grid;
  grid-template-columns: minmax(78px, 0.5fr) minmax(96px, 0.6fr) minmax(128px, 0.75fr) minmax(170px, 1fr);
  gap: 9px;
}

.settings-strip label {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  min-width: 0;
  gap: 8px;
  height: 38px;
  padding: 0 9px;
}

.settings-strip span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.settings-strip .setting-title {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 5px;
}

.settings-strip .setting-help {
  position: relative;
  flex: 0 0 auto;
  width: 13px;
  height: 13px;
  border: 1px solid rgba(13, 13, 13, 0.25);
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.62);
  font-size: 9px;
  line-height: 1;
  font-weight: 740;
  cursor: help;
  text-transform: none;
}

.round-control[data-tooltip]::after,
.setting-help::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 10px);
  left: 50%;
  z-index: 90;
  width: max-content;
  max-width: min(230px, calc(100vw - 40px));
  padding: 8px 9px;
  border: 1px solid rgba(13, 13, 13, 0.14);
  border-radius: 7px;
  background: rgba(248, 247, 243, 0.98);
  color: var(--ink);
  box-shadow: 0 14px 32px rgba(48, 38, 24, 0.16);
  font-size: 11px;
  line-height: 1.32;
  font-weight: 560;
  opacity: 0;
  pointer-events: none;
  text-align: left;
  text-transform: none;
  transform: translate(-50%, 4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.category-control .setting-help::after {
  right: 0;
  left: auto;
  transform: translateY(4px);
}

.round-control[data-tooltip]:hover::after,
.round-control[data-tooltip]:focus-visible::after,
.setting-help:hover::after,
.setting-help:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.category-control .setting-help:hover::after,
.category-control .setting-help:focus-visible::after {
  transform: translateY(0);
}

.setting-help:hover,
.setting-help:focus-visible {
  color: var(--ink);
  border-color: rgba(13, 13, 13, 0.55);
}

.settings-strip input,
.settings-strip select {
  min-width: 0;
  width: 100%;
  height: 28px;
  border: 0;
  background: transparent;
  font-size: 12px;
  font-weight: 620;
}

.settings-strip select {
  appearance: none;
}

.table-shell {
  margin-top: 18px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(248, 247, 243, 0.82);
  box-shadow: 0 24px 70px rgba(48, 38, 24, 0.14);
}

.deck-table {
  width: 100%;
  min-width: 900px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
  line-height: 1.28;
}

.deck-table thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 12px 18px;
  background: rgba(248, 247, 243, 0.96);
  border-bottom: 1px solid rgba(13, 13, 13, 0.13);
  color: var(--muted);
  font-size: 10px;
  font-weight: 720;
  text-align: left;
  text-transform: uppercase;
  backdrop-filter: blur(14px);
}

.deck-table tbody td {
  padding: 10px 18px;
  border-bottom: 1px solid rgba(13, 13, 13, 0.07);
  vertical-align: middle;
}

.deck-table tbody tr {
  transition: background 160ms ease, box-shadow 160ms ease;
}

.deck-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.52);
}

.deck-table tbody tr.is-selected {
  background: rgba(255, 255, 255, 0.72);
  box-shadow: inset 3px 0 0 rgba(13, 13, 13, 0.68);
}

.deck-table tbody tr.is-playing {
  background: rgba(255, 255, 255, 0.9);
  box-shadow: inset 3px 0 0 #171717, 0 0 0 1px rgba(13, 13, 13, 0.06);
}

.deck-table tbody tr.is-filtered-out {
  display: none;
}

.image-cell {
  width: 104px;
}

.audio-cell {
  width: 74px;
}

.word-image {
  display: block;
  width: 72px;
  height: 54px;
  object-fit: cover;
  border: 1px solid rgba(13, 13, 13, 0.08);
  border-radius: 6px;
  background: #efe9da;
  box-shadow: 0 8px 16px rgba(48, 38, 24, 0.08);
}

.row-play {
  width: 32px;
  height: 32px;
  font-size: 13px;
}

.hanzi-cell {
  width: 132px;
  font-size: 24px;
  font-weight: 780;
}

.pinyin-cell {
  width: 180px;
  color: #66615b;
  font-weight: 620;
}

.english-cell {
  min-width: 210px;
}

.category-cell {
  width: 210px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.help-dialog {
  width: min(700px, calc(100vw - 40px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 26px;
  background: #f8f7f3;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(48, 38, 24, 0.22);
}

.help-dialog::backdrop {
  background: rgba(245, 244, 240, 0.62);
}

.help-dialog h2 {
  margin: 0 0 20px;
  font-size: 18px;
  line-height: 1;
}

.help-mascot {
  height: auto;
  margin: -4px 0 22px;
  overflow: hidden;
  border: 1px solid rgba(13, 13, 13, 0.1);
  border-radius: 8px;
  background: #eee5d6;
  box-shadow: 0 12px 30px rgba(48, 38, 24, 0.12);
}

.help-mascot img {
  display: block;
  width: 100%;
  height: auto;
}

.help-dialog ul {
  display: grid;
  gap: 10px;
  margin: 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.35;
}

.help-contact {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid rgba(13, 13, 13, 0.12);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.help-contact p {
  margin: 0;
}

.help-contact p + p {
  margin-top: 4px;
}

.help-contact__title {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

.help-contact a {
  display: inline-flex;
  margin-top: 8px;
  color: var(--ink);
  font-weight: 650;
  text-decoration: none;
  border-bottom: 1px solid currentColor;
}

.dialog-close {
  position: absolute;
  top: 12px;
  right: 14px;
  border: 0;
  background: transparent;
  font-size: 24px;
  line-height: 1;
}

.round-control:disabled,
.row-play:disabled {
  cursor: default;
  opacity: 0.42;
}

.deck-nav a:focus-visible,
.nav-button:focus-visible,
.github-button:focus-visible,
.brand:focus-visible,
.round-control:focus-visible,
.row-play:focus-visible,
.setting-help:focus-visible,
.settings-strip input:focus,
.settings-strip select:focus,
.dialog-close:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 4px;
}

@media (max-width: 980px) {
  .study-panel {
    grid-template-columns: 1fr auto;
  }

  .settings-strip {
    grid-column: 1 / -1;
  }
}

@media (max-width: 768px) {
  .deck-header {
    height: auto;
    min-height: 62px;
    padding: 14px 20px;
  }

  .header-left {
    gap: 24px;
  }

  .brand__main {
    font-size: 16px;
  }

  .brand__sub {
    font-size: 10px;
  }

  .deck-nav {
    gap: 20px;
  }

  .deck-main {
    width: calc(100vw - 28px);
    padding-top: 14px;
  }

  .deck-topline {
    align-items: flex-start;
    flex-direction: column;
    gap: 16px;
    padding-top: 18px;
  }

  .deck-topline h1 {
    font-size: 46px;
  }

  .deck-stats {
    justify-content: flex-start;
  }

  .study-panel {
    top: 62px;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: 10px;
  }

  .now-playing {
    gap: 10px;
  }

  .now-playing img {
    width: 46px;
    height: 34px;
  }

  .now-playing span {
    font-size: 22px;
  }

  .deck-controls {
    justify-content: flex-start;
  }

  .round-control {
    width: 34px;
    height: 34px;
  }

  .primary-control {
    width: 40px;
    height: 40px;
  }

  .settings-strip {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .settings-strip label {
    grid-template-columns: 1fr;
    align-content: center;
    gap: 2px;
    height: 48px;
    padding: 0 10px;
  }

  .settings-strip input,
  .settings-strip select {
    height: 22px;
  }

  .table-shell {
    margin-top: 14px;
  }

  .help-mascot {
    margin-bottom: 18px;
  }

  .deck-table {
    min-width: 760px;
  }

  .deck-table thead th,
  .deck-table tbody td {
    padding-left: 12px;
    padding-right: 12px;
  }
}

@media (max-width: 430px) {
  .deck-nav {
    gap: 15px;
  }

  .deck-topline h1 {
    font-size: 40px;
  }

  .settings-strip span {
    font-size: 9px;
  }

  .settings-strip .setting-help {
    width: 12px;
    height: 12px;
    font-size: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 80ms !important;
  }
}
