:root {
  --bg: #f5f5f7;
  --toolbar: rgba(250, 250, 252, 0.92);
  --surface: #ffffff;
  --surface-soft: #f6f7f8;
  --surface-hover: #eef4f8;
  --ink: #1d1d1f;
  --muted: #6e7775;
  --muted-2: #8a9491;
  --line: #d8dddc;
  --line-strong: #b7c0be;
  --accent: #007aff;
  --accent-dark: #0062cc;
  --accent-soft: rgba(0, 122, 255, 0.12);
  --green: #0f7f68;
  --amber: #b56d12;
  --amber-soft: rgba(255, 184, 77, 0.2);
  --danger: #c43b32;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.14);
  --shadow-soft: 0 8px 22px rgba(15, 23, 42, 0.08);
  --radius: 8px;
  --radius-small: 6px;
  color-scheme: light;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text",
    "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.45;
}

.app-shell {
  height: 100dvh;
  min-height: 680px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.topbar {
  min-height: 62px;
  display: grid;
  grid-template-columns: minmax(250px, 420px) minmax(520px, 1fr);
  align-items: center;
  gap: 18px;
  padding: 9px 16px;
  background: var(--toolbar);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.2;
  font-weight: 760;
}

.brand p {
  margin: 4px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(150px, 210px) minmax(280px, 1fr) minmax(190px, 300px) auto;
  gap: 10px;
  align-items: center;
}

.field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
}

.field span,
.eyebrow {
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  font-weight: 720;
  letter-spacing: 0;
  text-transform: uppercase;
}

select,
input[type="search"] {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
  font-size: 13px;
  outline: none;
  box-shadow: inset 0 1px 1px rgba(15, 23, 42, 0.04);
}

select:focus,
input[type="search"]:focus,
button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.16);
  outline: none;
}

.workspace {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 12px;
  padding: 12px;
}

.image-stage,
.word-panel {
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}

.image-stage {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.stage-mode-actions {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 8px;
  opacity: 0.72;
  transition: opacity 120ms ease;
}

.stage-mode-actions .icon-button {
  width: 38px;
  height: 38px;
  background: rgba(255, 255, 255, 0.86);
  border-color: rgba(183, 192, 190, 0.8);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(14px);
}

.image-stage:hover .stage-mode-actions,
.stage-mode-actions:focus-within {
  opacity: 1;
}

.listening-mode-button[aria-pressed="true"] {
  border-color: rgba(0, 122, 255, 0.42);
  background: rgba(0, 122, 255, 0.12);
  color: var(--accent);
}

.focus-icon-exit {
  display: none;
}

.stage-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.stage-head h2 {
  margin: 5px 0 0;
  font-size: 20px;
  line-height: 1.18;
  font-weight: 760;
}

.stage-actions {
  display: flex;
  align-items: center;
}

.stage-actions {
  gap: 8px;
}

.icon-button,
.secondary-button,
.speak-button,
.collection-button,
.favorite-button {
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: #fff;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease,
    box-shadow 120ms ease;
}

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
}

.secondary-button,
.speak-button {
  min-width: 104px;
  height: 38px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 720;
}

.icon-button:hover,
.secondary-button:hover,
.speak-button:hover,
.collection-button:hover,
.favorite-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-hover);
}

.icon-button svg,
.speak-button svg,
.collection-button svg,
.favorite-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.collection-button {
  min-width: 94px;
  height: 36px;
  padding: 0 10px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 720;
  white-space: nowrap;
}

.collection-button.has-favorites {
  border-color: rgba(181, 109, 18, 0.34);
  background: var(--amber-soft);
  color: var(--amber);
}

.collection-button.has-favorites svg,
.favorite-button.is-active svg {
  fill: currentColor;
  stroke: currentColor;
}

#favoriteCountBadge {
  min-width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--muted);
  padding: 0 6px;
  font-size: 11px;
  line-height: 1;
}

.collection-button.has-favorites #favoriteCountBadge {
  background: rgba(181, 109, 18, 0.14);
  color: var(--amber);
}

.favorite-button {
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--muted);
}

.favorite-button.is-active {
  border-color: rgba(181, 109, 18, 0.38);
  background: var(--amber-soft);
  color: var(--amber);
}

.image-frame {
  position: relative;
  margin: 12px;
  height: calc(100% - 24px);
  min-height: 420px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 0;
  border-radius: var(--radius);
  background: #fff;
  overscroll-behavior: none;
  touch-action: none;
}

.image-frame img {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  min-height: 0;
  display: block;
  margin: 0 auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  clip-path: inset(2px);
  will-change: transform, opacity;
}

.label-layer {
  position: absolute;
  z-index: 2;
  pointer-events: none;
  will-change: transform, opacity;
}

.image-frame.is-entering-next img,
.image-frame.is-entering-next .label-layer {
  animation: scene-enter-next 460ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

.image-frame.is-entering-prev img,
.image-frame.is-entering-prev .label-layer {
  animation: scene-enter-prev 460ms cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes scene-enter-next {
  from {
    opacity: 0.22;
    transform: translateY(30px) scale(0.992);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes scene-enter-prev {
  from {
    opacity: 0.22;
    transform: translateY(-30px) scale(0.992);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.label-zone,
.listening-zone {
  position: absolute;
  pointer-events: auto;
}

.listening-zone {
  display: none;
  min-width: 64px;
  min-height: 42px;
}

.label-hit {
  position: absolute;
  inset: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 0;
  cursor: pointer;
  pointer-events: auto;
}

.label-hit::after {
  content: "";
  position: absolute;
  inset: -5px;
  border: 1px solid transparent;
  border-radius: 6px;
  transition: background 120ms ease, border-color 120ms ease, box-shadow 120ms ease;
}

.label-zone:hover .label-hit::after,
.label-hit:focus-visible::after {
  border-color: rgba(0, 122, 255, 0.72);
  background: rgba(0, 122, 255, 0.1);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.12);
}

.label-zone.is-selected .label-hit::after {
  border-color: rgba(181, 109, 18, 0.9);
  background: var(--amber-soft);
  box-shadow: 0 0 0 3px rgba(181, 109, 18, 0.14);
}

.label-reveal-button {
  display: none;
}

.label-reveal-button {
  position: absolute;
  right: -11px;
  top: -11px;
  z-index: 4;
  width: 26px;
  height: 26px;
  place-items: center;
  padding: 0;
  border: 1px solid rgba(123, 133, 130, 0.32);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.14);
  backdrop-filter: blur(12px);
}

.label-reveal-button svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reveal-icon-hide {
  display: none;
}

body.is-listening-mode .label-zone {
  display: none;
}

body.is-listening-mode .listening-zone {
  display: block;
}

.listening-hit {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 0;
  border-radius: 7px;
  padding: 0;
  cursor: pointer;
  pointer-events: auto;
}

body.is-listening-mode .listening-hit {
  overflow: hidden;
  border: 1px solid rgba(123, 133, 130, 0.26);
  background: rgba(247, 249, 249, 0.96);
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.1);
  backdrop-filter: blur(10px) saturate(0.82);
}

body.is-listening-mode .listening-hit::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.76), rgba(232, 237, 236, 0.9)),
    repeating-linear-gradient(
      45deg,
      rgba(99, 112, 109, 0.12) 0,
      rgba(99, 112, 109, 0.12) 1px,
      transparent 1px,
      transparent 7px
    );
}

body.is-listening-mode .listening-zone:hover .listening-hit,
body.is-listening-mode .listening-hit:focus-visible {
  border-color: rgba(0, 122, 255, 0.48);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.13), 0 8px 20px rgba(15, 23, 42, 0.12);
}

body.is-listening-mode .listening-zone.is-revealed .listening-hit {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

body.is-listening-mode .listening-zone.is-revealed .listening-hit::before {
  opacity: 0;
}

body.is-listening-mode .label-reveal-button {
  display: grid;
}

body.is-listening-mode .label-reveal-button:hover,
body.is-listening-mode .label-reveal-button:focus-visible {
  border-color: rgba(0, 122, 255, 0.42);
  color: var(--accent);
}

body.is-listening-mode .listening-zone.is-revealed .reveal-icon-show {
  display: none;
}

body.is-listening-mode .listening-zone.is-revealed .reveal-icon-hide {
  display: block;
}

.word-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.word-detail-card {
  position: relative;
  min-height: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  overflow: auto;
}

.detail-favorite {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
}

.word-detail-card h3 {
  margin: 0;
  padding-right: 48px;
  color: var(--ink);
  font-size: clamp(28px, 3vw, 42px);
  line-height: 1.05;
  font-weight: 800;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.word-detail-card.is-empty h3 {
  padding-right: 0;
  color: var(--muted);
  font-size: 24px;
  line-height: 1.2;
}

.word-detail-card.is-empty .detail-favorite {
  display: none;
}

.phonetic {
  margin: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.3;
}

.detail-meaning {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.6;
}

.word-detail-card.is-empty .detail-meaning {
  color: var(--muted);
  font-size: 14px;
}

.detail-study {
  display: grid;
  gap: 12px;
}

.word-detail-card.is-empty .detail-study {
  display: none;
}

.detail-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  padding: 12px;
}

.detail-section h4 {
  margin: 0 0 9px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  font-weight: 760;
  letter-spacing: 0;
  text-transform: uppercase;
}

.detail-section p {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.7;
}

.book-definition {
  display: grid;
  gap: 12px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.68;
}

.book-definition p {
  margin: 0;
}

.book-definition-content ul {
  display: grid;
  gap: 5px;
  margin: 0;
  padding-left: 18px;
}

.book-definition-content li {
  padding-left: 2px;
}

.book-definition-note {
  color: var(--muted);
  font-size: 12px;
}

.root-list {
  display: grid;
  gap: 8px;
}

.root-item {
  display: grid;
  grid-template-columns: minmax(58px, auto) 1fr;
  align-items: baseline;
  gap: 8px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.root-item strong {
  width: fit-content;
  max-width: 120px;
  border: 1px solid rgba(0, 122, 255, 0.26);
  border-radius: var(--radius-small);
  background: #fff;
  color: var(--accent-dark);
  padding: 3px 6px;
  font-size: 12px;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.root-item span {
  color: var(--muted);
}

.detail-meta {
  display: grid;
  gap: 8px;
  margin-top: 4px;
}

.detail-meta span {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface-soft);
  color: var(--muted);
  padding: 6px 9px;
  font-size: 12px;
  line-height: 1.3;
}

.detail-meta span:empty {
  display: none;
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.word-detail-card.is-empty .detail-actions {
  display: none;
}

.speak-button {
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.speak-button:hover {
  color: #fff;
  background: #0b6a57;
  border-color: #0b6a57;
}

.empty-state {
  padding: 14px;
  color: var(--muted);
  font-size: 13px;
}

.collection-page {
  position: fixed;
  inset: 0;
  z-index: 24;
  display: grid;
  background: var(--bg);
}

.collection-page[hidden] {
  display: none;
}

.collection-shell {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: 18px;
  overflow: hidden;
}

.collection-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  padding: 16px;
}

.collection-header h2 {
  margin: 5px 0 4px;
  color: var(--ink);
  font-size: 24px;
  line-height: 1.1;
}

.collection-count {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.favorites-grid {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  align-content: start;
  gap: 12px;
  overflow: auto;
}

.favorite-card {
  position: relative;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.favorite-card-main {
  width: 100%;
  min-height: 172px;
  display: grid;
  gap: 8px;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 16px 52px 16px 16px;
  text-align: left;
}

.favorite-card-main:hover {
  background: var(--surface-hover);
}

.favorite-card-main strong {
  color: var(--ink);
  font-size: 28px;
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.favorite-card-main .phonetic {
  font-size: 14px;
}

.favorite-card-main p {
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
}

.favorite-card-main small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.favorite-scene-tag {
  width: fit-content;
  max-width: 100%;
  border: 1px solid rgba(0, 122, 255, 0.2);
  border-radius: var(--radius-small);
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 4px 7px;
  font-size: 11px;
  line-height: 1;
  font-weight: 720;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.favorite-remove {
  position: absolute;
  top: 12px;
  right: 12px;
}

.favorite-remove:hover {
  color: var(--danger);
}

.favorites-empty {
  display: grid;
  place-items: center;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 15px;
  box-shadow: var(--shadow-soft);
}

.favorites-empty[hidden] {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(12, 20, 18, 0.46);
}

.modal-backdrop[hidden] {
  display: none;
}

.word-modal {
  position: relative;
  width: min(760px, 100%);
  max-height: min(680px, calc(100vh - 48px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1;
}

.modal-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 28px 62px 22px 28px;
  border-bottom: 1px solid var(--line);
}

.modal-hero h3 {
  margin: 6px 0 8px;
  font-size: 42px;
  line-height: 1;
  letter-spacing: 0;
}

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

.definition-grid section {
  min-height: 132px;
  padding: 22px;
  background: #fff;
}

.definition-grid h4 {
  margin: 0 0 10px;
  color: var(--amber);
  font-size: 12px;
  line-height: 1;
  letter-spacing: 0;
  text-transform: uppercase;
}

.definition-grid p {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.65;
}

.modal-nav {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.is-speaking {
  animation: pulse 900ms ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(15, 127, 104, 0.22);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(15, 127, 104, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .icon-button,
  .secondary-button,
  .speak-button,
  .image-frame img,
  .label-layer,
  .label-hit::after,
  .is-speaking {
    animation: none;
    transition: none;
  }
}

@media (max-width: 1120px) {
  body {
    overflow: auto;
  }

  .app-shell {
    min-height: 100vh;
    height: auto;
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .toolbar {
    grid-template-columns: minmax(140px, 190px) minmax(240px, 1fr) minmax(170px, 240px) auto;
  }

  .workspace {
    grid-template-columns: minmax(0, 1fr) 320px;
  }

  .image-stage {
    min-height: 640px;
  }
}

@media (max-width: 860px) {
  .toolbar,
  .workspace {
    grid-template-columns: 1fr;
  }

  .image-stage {
    min-height: 560px;
  }

  .word-panel {
    min-height: 320px;
  }

  .word-detail-card h3 {
    font-size: 30px;
  }

  .modal-hero,
  .definition-grid {
    display: block;
  }

  .modal-hero {
    padding: 26px 58px 22px 22px;
  }

  .modal-hero h3 {
    font-size: 34px;
  }

  .collection-shell {
    padding: 12px;
  }

  .collection-header {
    align-items: stretch;
    flex-direction: column;
  }

  .favorites-grid {
    grid-template-columns: 1fr;
  }

  .definition-grid section + section {
    border-top: 1px solid var(--line);
  }
}

body.is-image-focus {
  overflow: hidden;
}

body.is-image-focus .app-shell {
  height: 100dvh;
  min-height: 0;
}

body.is-image-focus .topbar,
body.is-image-focus .word-panel {
  display: none;
}

body.is-image-focus .workspace {
  grid-template-columns: minmax(0, 1fr);
  gap: 0;
  padding: 0;
}

body.is-image-focus .image-stage {
  min-height: 0;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

body.is-image-focus .image-frame {
  height: 100dvh;
  min-height: 0;
  margin: 0;
  border-radius: 0;
}

body.is-image-focus .image-frame img {
  max-height: 100dvh;
}

body.is-image-focus .stage-mode-actions {
  top: calc(14px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
  opacity: 1;
}

body.is-image-focus .focus-icon-enter {
  display: none;
}

body.is-image-focus .focus-icon-exit {
  display: block;
}
