:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #151923;
  --muted: #697180;
  --line: #dfe4ea;
  --blue: #1769e0;
  --green: #087f62;
  --orange: #9a431d;
  --orange-bg: #fff3e8;
  --dark: #202532;
}

* { box-sizing: border-box; }

html,
body { width: 100%; max-width: 100%; overflow-x: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
select,
input { font: inherit; }

.wrap {
  width: min(1100px, calc(100% - 12px));
  margin: 0 auto;
  padding: 0 0 20px;
}

.top {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 49px;
  padding: 7px 5px 7px 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
  backdrop-filter: blur(12px) saturate(160%);
}

.unit-title { min-width: 0; margin-right: auto; }
.unit-title strong { display: block; font-size: 19px; line-height: 1.1; }
.unit-title span {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.count,
.back {
  flex: none;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #414958;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  white-space: nowrap;
}

.count { padding: 6px 7px; background: #f7f9fb; }
.back { padding: 7px 8px; text-decoration: none; }
.back:active { background: #eef2f6; }

.visibility-toggle {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: #333b49;
  line-height: 1;
  cursor: pointer;
}

.visibility-toggle span {
  display: block;
  line-height: 1;
}

.visibility-toggle[aria-pressed="true"] {
  border-color: #cbd3dd;
  background: #eef2f6;
  color: #697180;
}

.visibility-toggle[aria-pressed="true"]::after,
.toggle-all.has-hidden::after {
  position: absolute;
  width: 17px;
  height: 2px;
  border-radius: 2px;
  background: currentColor;
  content: "";
  transform: rotate(-42deg);
}

.visibility-toggle:focus-visible {
  outline: 3px solid rgba(23, 105, 224, .2);
  outline-offset: 2px;
}

.toggle-all {
  flex: none;
  width: 31px;
  height: 31px;
  min-height: 31px;
  border-radius: 6px;
  font-size: 14px;
}

.bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  margin: 7px 0;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(16, 24, 40, .04);
}

.study-modes {
  display: grid;
  grid-template-columns: .72fr 1fr 1fr;
  min-height: 36px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f1f4f7;
}

.study-mode {
  min-width: 0;
  padding: 0 5px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #566070;
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}

.study-mode[aria-pressed="true"] {
  background: #fff;
  color: var(--blue);
  box-shadow: 0 1px 4px rgba(16, 24, 40, .12);
}

.study-mode:focus-visible {
  outline: 2px solid rgba(23, 105, 224, .35);
  outline-offset: -2px;
}

.commands { display: grid; grid-template-columns: 1fr .7fr; gap: 7px; }
.commands button {
  min-width: 0;
  min-height: 36px;
  padding: 0 8px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  font-size: 13px;
  font-weight: 750;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
}
.play { background: var(--blue); }
.stop { background: var(--dark); }

select {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 0 9px;
  color: #253042;
  font-size: 13px;
}

.rate-label {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 7px;
  min-height: 28px;
  color: var(--muted);
  font-size: 12px;
}

input[type="range"] { width: 100%; accent-color: #2098df; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.card {
  position: relative;
  min-width: 0;
  min-height: 92px;
  padding: 9px 8px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 2px 7px rgba(16, 24, 40, .035);
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(23, 105, 224, .08);
}

.jp {
  min-width: 0;
  min-height: 27px;
  padding-right: 32px;
  font-family: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif;
  font-size: 22px;
  font-weight: 800;
  line-height: 1.12;
  overflow-wrap: anywhere;
}
.jp.long { font-size: 18px; line-height: 1.18; }
.jp.xlong { font-size: 15px; line-height: 1.25; }

.speak {
  position: absolute;
  top: 7px;
  right: 7px;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  min-height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(16, 24, 40, .06);
  cursor: pointer;
}

.read {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 3px 5px;
  min-width: 0;
  margin-top: 4px;
  line-height: 1.2;
}
.hira {
  min-width: 0;
  color: var(--blue);
  font-size: 12.5px;
  font-weight: 750;
  overflow-wrap: anywhere;
}
.romaji {
  min-width: 0;
  max-width: 100%;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--orange-bg);
  color: var(--orange);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.zh {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 3px 5px;
  min-width: 0;
  margin-top: 5px;
  padding-right: 28px;
  color: #414958;
  font-size: 12px;
  line-height: 1.25;
}
.meaning { min-width: 0; overflow-wrap: anywhere; }
.type {
  flex: none;
  padding: 1px 4px;
  border-radius: 4px;
  background: #f0f2f5;
  color: #687180;
  font-size: 10.5px;
  font-weight: 700;
}

.card-visibility {
  position: absolute;
  right: 7px;
  bottom: 7px;
  width: 25px;
  height: 25px;
  min-height: 25px;
  border-radius: 50%;
  font-size: 11px;
  box-shadow: 0 2px 6px rgba(16, 24, 40, .05);
}

.card.content-hidden {
  padding: 0;
  background: #f9fafb;
}

.card.content-hidden .jp {
  min-height: 0;
  padding: 0;
}

.card .term-text[hidden],
.card .read[hidden],
.card .zh[hidden] {
  display: none;
}

body.mode-word .card:not(.study-revealed) .read,
body.mode-word .card:not(.study-revealed) .zh,
body.mode-meaning .card:not(.study-revealed) .term-text,
body.mode-meaning .card:not(.study-revealed) .read,
body.mode-meaning .card:not(.study-revealed) .type {
  visibility: hidden;
  pointer-events: none;
  user-select: none;
}

body.mode-word .card:not(.study-revealed):not(.content-hidden),
body.mode-meaning .card:not(.study-revealed):not(.content-hidden) {
  cursor: pointer;
}

body:not(.mode-word):not(.mode-meaning) .card {
  cursor: pointer;
}

body:not(.mode-word):not(.mode-meaning) .card:active,
body.mode-word .card:not(.study-revealed):not(.content-hidden):active,
body.mode-meaning .card:not(.study-revealed):not(.content-hidden):active {
  background: #f5f9ff;
}

.card.study-revealed {
  border-color: #b9cff1;
  box-shadow: 0 3px 10px rgba(23, 105, 224, .1);
}

@media (max-width: 560px) {
  .count { display: none; }
}

@media (max-width: 350px) {
  .wrap { width: calc(100% - 8px); }
  .count { display: none; }
  .card { padding-left: 7px; padding-right: 7px; }
  .jp { font-size: 20px; }
  .jp.long { font-size: 17px; }
  .jp.xlong { font-size: 14px; }
}

@media (min-width: 720px) {
  .wrap { padding: 12px 12px 28px; }
  .top { position: relative; padding-left: 10px; border: 1px solid var(--line); border-radius: 8px; }
  .bar { grid-template-columns: 1fr 1fr; align-items: center; }
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .card { min-height: 98px; padding: 10px; }
  .jp { font-size: 24px; }
  .jp.long { font-size: 19px; }
  .jp.xlong { font-size: 16px; }
  .hira { font-size: 13px; }
  .romaji { font-size: 11.5px; }
  .zh { font-size: 12.5px; }
}

@media (min-width: 1020px) {
  .bar { grid-template-columns: minmax(220px, .9fr) 230px minmax(230px, 1fr) minmax(240px, 1fr); }
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
