.scanner-shell,
.scanner-shell button,
.scanner-shell input {
  font-family: "Space Grotesk", "PingFang SC", "Microsoft YaHei", sans-serif;
}

.scanner-shell {
  position: relative;
  padding-top: clamp(0.9rem, 2vw, 1.4rem);
}

.scanner-heading h1 {
  margin: 0 0 1.2rem;
  color: var(--brand);
  font-size: clamp(2rem, 5vw, 3.1rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.scanner-workspace {
  display: grid;
  grid-template-columns: minmax(300px, 0.8fr) minmax(0, 1.2fr);
  gap: clamp(1rem, 2.5vw, 1.5rem);
  align-items: stretch;
}

.camera-panel,
.scanner-result-panel {
  box-sizing: border-box;
  display: grid;
  gap: 1rem;
  min-width: 0;
  padding: clamp(1rem, 2.5vw, 1.3rem);
  border: 1px solid var(--border);
  border-radius: 0.7rem;
  background: #fbfcff;
  box-shadow: 0 16px 34px rgba(21, 42, 102, 0.08);
}

.camera-panel {
  align-content: start;
}

.scanner-result-panel {
  position: relative;
  gap: 0;
  grid-template-rows: auto auto minmax(0, 1fr);
  align-content: stretch;
  min-height: 0;
  overflow: hidden;
}

.scanner-panel__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.8rem;
}

.scanner-result-panel .scanner-panel__header {
  align-items: start;
}

.scanner-panel__header h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1.1rem, 2vw, 1.35rem);
  line-height: 1.2;
  letter-spacing: 0;
}

.scanner-status {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
  text-align: right;
}

.scanner-status.is-error {
  color: var(--danger);
  font-weight: 700;
}

.scanner-result-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 0.55rem;
  min-width: 0;
  margin-left: auto;
}

.read-aloud-toggle {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 2.05rem;
  height: 2.05rem;
  padding: 0;
  border: 1px solid #1d4ed8;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  line-height: 1;
}

.read-aloud-toggle[hidden] {
  display: none;
}

.read-aloud-icon {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.read-aloud-icon--pause {
  display: none;
}

.read-aloud-toggle.is-playing:hover .read-aloud-icon--speaker,
.read-aloud-toggle.is-paused .read-aloud-icon--speaker {
  display: none;
}

.read-aloud-toggle.is-playing:hover .read-aloud-icon--pause,
.read-aloud-toggle.is-paused .read-aloud-icon--pause {
  display: block;
}

.read-aloud-toggle.is-paused:hover .read-aloud-icon--speaker {
  display: block;
}

.read-aloud-toggle.is-paused:hover .read-aloud-icon--pause {
  display: none;
}

.read-aloud-toggle:hover {
  border-color: #1e40af;
  background: #1d4ed8;
  color: #fff;
}

.read-aloud-toggle.is-playing,
.read-aloud-toggle.is-paused {
  border-color: #15803d;
  background: #16a34a;
}

.read-aloud-toggle.is-paused {
  animation: read-aloud-paused-bounce 1.35s ease-in-out infinite;
}

.read-aloud-toggle:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

@keyframes read-aloud-paused-bounce {
  0%,
  100% {
    transform: translateY(0);
  }

  45% {
    transform: translateY(-0.18rem);
  }

  70% {
    transform: translateY(0.05rem);
  }
}

@media (prefers-reduced-motion: reduce) {
  .read-aloud-toggle.is-paused {
    animation: none;
  }
}

.pinyin-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 6.8rem;
  min-height: 2rem;
  padding: 0.35rem 0.7rem;
  border-color: #9fb2d9;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-dark);
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.2;
  white-space: nowrap;
}

.pinyin-toggle[hidden] {
  display: none;
}

.pinyin-toggle:hover {
  border-color: var(--brand);
  background: #e4ecfb;
}

.camera-field {
  box-sizing: border-box;
  position: relative;
  display: grid;
  place-items: center;
  align-self: start;
  justify-self: stretch;
  overflow: hidden;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  aspect-ratio: 4 / 5;
  min-height: 320px;
  padding: 0;
  border: 2px dashed #9fb2d9;
  border-radius: 0.7rem;
  background: linear-gradient(135deg, #eef3fb 0%, #fff7ed 100%);
  color: var(--brand-dark);
}

.camera-field:hover {
  border-color: var(--accent);
}

.camera-field.is-previewing {
  border-style: solid;
  background: #000;
}

.camera-preview,
.photo-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #000;
  object-fit: contain;
}

.camera-countdown {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.34);
  color: #fff;
  font-size: clamp(5rem, 14vw, 8rem);
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 10px 30px rgba(15, 23, 42, 0.45);
}

.camera-countdown[hidden] {
  display: none;
}

.camera-countdown.is-flashing {
  animation: camera-countdown-flash 0.82s ease-out;
}

@keyframes camera-countdown-flash {
  0% {
    opacity: 0;
    transform: scale(0.72);
  }

  22% {
    opacity: 1;
    transform: scale(1.08);
  }

  100% {
    opacity: 0.85;
    transform: scale(1);
  }
}

.camera-placeholder {
  display: grid;
  gap: 0.5rem;
  place-items: center;
  padding: 1.25rem;
  color: var(--brand-dark);
  font-weight: 700;
  text-align: center;
}

.camera-placeholder__icon {
  display: grid;
  place-items: center;
  width: 3rem;
  height: 3rem;
  border: 2px solid currentColor;
  border-radius: 50%;
}

.camera-placeholder__svg {
  width: 1.75rem;
  height: 1.75rem;
}

.scanner-actions {
  display: grid;
  gap: 0.7rem;
  justify-items: center;
}

.scanner-actions__row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  justify-content: center;
  align-items: center;
  min-width: 0;
  width: 100%;
}

.scanner-action {
  box-sizing: border-box;
  flex: 0 1 8.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 8.25rem;
  max-width: 100%;
  height: 2.7rem;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  color: #fff;
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
  white-space: normal;
}

.scanner-action--primary {
  border-color: var(--brand);
  background: var(--brand);
}

.scanner-action--countdown {
  padding: 0.35rem 0.55rem;
  font-size: 0.82rem;
  line-height: 1.1;
}

.scanner-action--secondary {
  border-color: var(--accent-dark);
  background: var(--accent);
}

.scanner-action--generate {
  border-color: #b7c2d6;
  background: #d7dee9;
  color: #64748b;
  cursor: not-allowed;
}

.scanner-action--generate:not(:disabled) {
  border-color: var(--success);
  background: var(--success);
  color: #fff;
  cursor: pointer;
}

.scanner-action--primary:disabled {
  cursor: not-allowed;
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
  opacity: 1;
}

.scanner-action:disabled:hover {
  box-shadow: none;
  transform: none;
}

.file-fallback {
  position: relative;
  cursor: pointer;
}

.file-fallback input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.scanner-output {
  grid-row: 3;
  min-height: 0;
  height: 100%;
  margin-top: 1rem;
  max-height: none;
  overflow: auto;
  padding: clamp(1rem, 2.5vw, 1.4rem);
  border: 1px solid #d8e0ef;
  border-radius: 0.7rem;
  background: #fff;
  color: #172033;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

.scanner-loading {
  grid-row: 2;
  align-self: start;
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
  padding: 0.8rem 0.9rem;
  border: 1px solid #9fb2d9;
  border-radius: 0.65rem;
  background: var(--brand-soft);
  color: var(--brand-dark);
}

.scanner-loading[hidden] {
  display: none;
}

.scanner-loading__topline {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.35;
}

.scanner-loading__topline span {
  color: var(--muted);
  font-weight: 700;
}

.scanner-loading__track {
  overflow: hidden;
  height: 0.55rem;
  border-radius: 999px;
  background: #d8e0ef;
}

.scanner-loading__bar {
  width: var(--scanner-progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  transition: width 0.5s linear;
}

.scanner-loading.is-holding .scanner-loading__bar {
  animation: scanner-loading-flash 0.85s ease-in-out infinite alternate;
}

@keyframes scanner-loading-flash {
  from {
    opacity: 0.5;
  }

  to {
    opacity: 1;
  }
}

.scanner-empty {
  margin: 0;
  color: var(--muted);
  font-family: "Space Grotesk", "Trebuchet MS", sans-serif;
  line-height: 1.6;
}

.scanner-output__paragraph {
  margin: 0 0 1.35rem;
  line-height: 1.2;
}

.scanner-output__paragraph:last-child {
  margin-bottom: 0;
}

.pinyin-char,
.pinyin-punctuation {
  display: inline-grid;
  grid-template-rows: 1.35rem 2.15rem;
  min-width: 1.72em;
  min-height: 3.65rem;
  margin: 0 0.02em 0.32em;
  justify-items: center;
  vertical-align: top;
}

.pinyin-char {
  text-align: center;
}

.read-aloud-char {
  border-radius: 0.18rem;
  transition: background 0.12s ease, box-shadow 0.12s ease, color 0.12s ease;
}

.read-aloud-char--current {
  background: #e5e7eb;
  color: #111827;
  box-shadow: 0 0 0 0.12rem rgba(100, 116, 139, 0.2);
}

.pinyin-char__aid {
  grid-row: 1;
  color: #58708f;
  font-size: 0.78rem;
  line-height: 1;
  white-space: nowrap;
}

.scanner-output.is-pinyin-hidden .pinyin-char__aid {
  color: transparent;
  visibility: hidden;
}

.pinyin-char__han {
  grid-row: 2;
  align-self: center;
  font-size: 1.55rem;
  line-height: 1;
  text-align: center;
}

.pinyin-punctuation {
  min-width: 0.9em;
  color: #4b5563;
  font-size: 1.55rem;
  line-height: 1;
}

.pinyin-punctuation__mark {
  grid-row: 2;
  line-height: 1;
}

.pinyin-punctuation--bottom .pinyin-punctuation__mark {
  align-self: end;
}

.pinyin-punctuation--top .pinyin-punctuation__mark {
  align-self: start;
}

.pinyin-punctuation--middle .pinyin-punctuation__mark {
  align-self: center;
}

@media (max-width: 860px) {
  .scanner-workspace {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .camera-field {
    aspect-ratio: 4 / 3;
    min-height: 250px;
  }

  .scanner-output {
    height: auto;
    max-height: none;
    min-height: 360px;
  }
}

@media (max-width: 560px) {
  .scanner-panel__header {
    display: grid;
  }

  .scanner-status {
    text-align: left;
  }

  .scanner-result-tools {
    justify-content: end;
    margin-left: 0;
  }

  .scanner-result-tools .scanner-status {
    text-align: right;
  }

  .scanner-actions {
    display: grid;
    justify-content: stretch;
  }

  .scanner-actions__row {
    display: grid;
  }

  .scanner-action {
    width: 100%;
  }
}
