:root {
  color-scheme: dark;
  --bg: #030303;
  --surface: #1d1a22;
  --surface-2: #252525;
  --text: #f6f1eb;
  --muted: #8f8a92;
  --purple: #8b4df6;
  --purple-2: #7e3ff0;
  --green: #80d86b;
  --line: rgba(255, 255, 255, 0.16);
  --line-strong: rgba(255, 255, 255, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Nunito", "Comic Neue", system-ui, sans-serif;
}

body.fake-fullscreen {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
}

button,
select,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(620px, 58.5vw) 1fr;
  gap: 22px;
  width: 100vw;
  height: 100vh;
  padding: 24px 38px 32px;
  background: #020202;
}

.pdf-panel {
  display: grid;
  grid-template-rows: 90px minmax(0, 1fr) 106px;
  min-width: 0;
  height: 100%;
}

.pdf-toolbar {
  position: relative;
  display: grid;
  grid-template-columns: minmax(560px, 1fr) 80px auto;
  gap: 20px;
  align-items: start;
  width: min(910px, 100%);
  min-height: 80px;
}

.pdf-toolbar::before {
  content: "";
  position: absolute;
  left: 26px;
  top: 25px;
  z-index: 1;
  width: 30px;
  height: 30px;
  pointer-events: none;
  background: url("/assets/book-open-fill.png") center / contain no-repeat;
}

.fullscreen-btn {
  position: fixed;
  top: 24px;
  right: 38px;
  z-index: 40;
}

.translation-toggle {
  position: fixed;
  top: 24px;
  right: 132px;
  z-index: 40;
  color: #817c86;
  font-size: 0;
  font-weight: 900;
  overflow: hidden;
  text-indent: -9999px;
}

.translation-toggle::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  display: block;
  width: 58%;
  height: 58%;
  background: url("/assets/translation-icon-v5.png") center / contain no-repeat;
  text-indent: 0;
  transform: translate(-50%, -50%);
}

.translation-toggle.is-on {
  border-color: rgba(139, 77, 246, 0.92);
  color: var(--text);
  box-shadow: 0 0 22px rgba(139, 77, 246, 0.2);
}

#exit-fullscreen-icon {
  display: none;
  width: 58%;
  height: 58%;
  object-fit: contain;
}

.fullscreen-btn.is-fullscreen #fullscreen-symbol {
  display: none;
}

.fullscreen-btn.is-fullscreen #exit-fullscreen-icon {
  display: block;
}

.book-picker {
  display: grid;
  grid-template-columns: minmax(250px, 1fr) minmax(210px, 0.72fr);
  gap: 12px;
  min-width: 0;
}

#pdf-select,
#book-search {
  min-width: 0;
  width: 100%;
  height: 80px;
  border: 2px solid #35313c;
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 26px;
  font-weight: 700;
  outline: none;
}

#pdf-select {
  padding: 0 26px 0 70px;
  appearance: none;
  background-image: url("/assets/chevron-down.png");
  background-position: calc(100% - 22px) center;
  background-size: 25px 25px;
  background-repeat: no-repeat;
}

.book-search {
  position: relative;
  display: block;
  min-width: 0;
}

#book-search {
  padding: 0 16px 0 54px;
}

#book-search::placeholder {
  color: #8f8a92;
}

.book-search-icon {
  position: absolute;
  left: 20px;
  top: 50%;
  width: 22px;
  height: 22px;
  border: 3px solid #f6f1eb;
  border-radius: 50%;
  opacity: 0.78;
  pointer-events: none;
  transform: translateY(-50%);
}

.book-search-icon::after {
  content: "";
  position: absolute;
  right: -8px;
  bottom: -6px;
  width: 10px;
  height: 3px;
  border-radius: 999px;
  background: #f6f1eb;
  transform: rotate(45deg);
}

#pdf-select:focus,
#book-search:focus {
  border-color: rgba(139, 77, 246, 0.92);
  box-shadow: 0 0 22px rgba(139, 77, 246, 0.2);
}

.tool-btn {
  display: grid;
  place-items: center;
  width: 80px;
  height: 80px;
  border: 2px solid #393342;
  border-radius: 12px;
  background: #211d29;
  color: var(--text);
  cursor: pointer;
  font-size: 42px;
  line-height: 1;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
}

.tool-btn:hover,
.icon-btn:hover,
.record-btn:hover,
.certificate-btn:hover,
.page-nav-btn:hover {
  border-color: rgba(139, 77, 246, 0.92);
  box-shadow: 0 0 22px rgba(139, 77, 246, 0.22);
  transform: translateY(-1px);
}

.page-indicator {
  display: inline-flex;
  align-items: center;
  height: 90px;
  color: var(--text);
  font-size: 34px;
  font-weight: 500;
  white-space: nowrap;
}

.pdf-stage {
  position: relative;
  display: grid;
  align-items: center;
  justify-items: center;
  min-height: 0;
  overflow: auto;
  background: #030303;
}

#pdf-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  border: 0;
  border-radius: 10px;
  background: #f7f7f3;
  box-shadow: none;
}

.highlight-layer {
  position: absolute;
  pointer-events: none;
}

.pdf-highlight {
  position: absolute;
  border-radius: 8px;
  background: rgba(255, 216, 77, 0.48);
  box-shadow: 0 0 0 2px rgba(255, 246, 178, 0.78);
}

.empty-state {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.empty-state strong {
  color: var(--text);
  font-size: 24px;
}

.empty-state.hidden {
  display: none;
}

.page-actions {
  display: grid;
  grid-template-columns: minmax(220px, 285px) minmax(220px, 285px);
  gap: 24px;
  align-items: center;
  justify-content: center;
  justify-self: center;
  width: min(100%, max(var(--pdf-render-width, 100%), 594px));
  padding-top: 6px;
}

.page-nav-btn {
  height: 66px;
  border: 3px solid #3b3840;
  border-radius: 12px;
  background: var(--surface);
  color: #817c86;
  cursor: pointer;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: 0;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease, transform 0.15s ease;
}

.page-nav-btn.next {
  border-color: var(--purple);
  color: var(--purple);
}

.next-book-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: min(285px, 100%);
  height: 66px;
  border: 3px solid var(--purple);
  background: var(--purple);
  color: #fff;
}

.next-book-btn::before {
  content: "";
  display: inline-block;
  width: 28px;
  height: 28px;
  background: url("/assets/book-open-fill.png") center / contain no-repeat;
  filter: brightness(0) invert(1);
}

.next-book-btn.hidden {
  display: none;
}

.page-nav-btn:disabled,
.tool-btn:disabled,
.icon-btn:disabled,
.record-btn:disabled {
  cursor: not-allowed;
  opacity: 0.48;
  transform: none;
  box-shadow: none;
}

.coach-panel {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  height: 100%;
  padding-top: 108px;
  overflow: hidden;
  background: #020202;
}

.coach-display,
.coach-controls {
  width: 100%;
}

.coach-display {
  display: flex;
  flex-direction: column;
  gap: 18px;
  align-items: center;
  min-height: 0;
}

.fox-frame {
  width: min(100%, 812px);
  aspect-ratio: 16 / 9;
  height: auto;
  max-height: 435px;
  overflow: hidden;
  border: 0;
  border-radius: 10px;
  background: #282828;
}

#fox-video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

#fox-img {
  display: none;
}

.status-text {
  display: none;
}

.fallback-list {
  display: none;
}

.fallback-list.visible {
  display: none;
}

.coach-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 24px;
}

.current-sentence,
.translation-sentence {
  width: min(100%, 760px);
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: clamp(34px, 2.45vw, 52px);
  font-weight: 500;
  line-height: 1.22;
  text-align: left;
  overflow-wrap: anywhere;
}

.current-sentence:not(:empty)::before,
.translation-sentence:not(:empty)::before {
  content: "-";
  display: inline-block;
  width: 44px;
  color: var(--text);
}

.translation-sentence:not(:empty)::before {
  color: #8f8f94;
}

.sentence-highlight {
  color: var(--green);
}

.word {
  cursor: pointer;
  border-radius: 6px;
  transition: color 0.12s ease, background-color 0.12s ease;
}

.word:hover,
.word:focus-visible {
  background: rgba(139, 77, 246, 0.22);
  outline: none;
}

.translation-sentence {
  margin-top: 8px;
  color: #8f8f94;
  font-size: clamp(28px, 2vw, 40px);
}

.read-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 62px;
  margin: 30px 0 0;
}

.icon-btn,
.record-btn,
.certificate-btn,
.close-btn {
  border: 0;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: transparent;
  color: var(--purple);
  line-height: 1;
}

.icon-btn img {
  display: block;
  max-width: 80%;
  max-height: 80%;
  object-fit: contain;
  pointer-events: none;
}

#speaker-icon,
#playback-icon {
  max-width: 70%;
  max-height: 70%;
}

#speaker-icon {
  max-width: 65%;
  max-height: 65%;
}

.fox-frame.hurray-mode {
  width: auto;
  height: min(72vh, 640px);
  max-width: 100%;
  max-height: none;
  aspect-ratio: 9 / 16;
  background: transparent;
}

.fox-frame.hurray-mode #fox-video {
  object-fit: contain;
  transform: none;
}

.record-btn {
  width: 94px;
  height: 94px;
  background: transparent;
}

.record-btn img {
  max-width: 100%;
  max-height: 100%;
}

.emoji-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 30;
}

.word-tip {
  position: fixed;
  z-index: 60;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 46px;
  gap: 12px;
  align-items: center;
  min-width: 174px;
  max-width: min(280px, calc(100vw - 24px));
  padding: 12px 16px;
  border: 2px solid rgba(139, 77, 246, 0.7);
  border-radius: 10px;
  background: #211d29;
  color: var(--text);
  box-shadow: 0 16px 38px rgba(0, 0, 0, 0.38);
  text-align: center;
}

.word-tip.hidden {
  display: none;
}

.word-tip-text {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.word-tip strong {
  color: var(--green);
  font-size: 24px;
  line-height: 1.1;
}

.word-tip span {
  color: #f6f1eb;
  font-size: 20px;
  line-height: 1.25;
}

.word-tip-audio {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.word-tip-audio img {
  display: block;
  width: 80%;
  height: 80%;
  object-fit: contain;
}

.score-toast {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 80;
  display: grid;
  gap: 8px;
  min-width: 260px;
  max-width: calc(100vw - 36px);
  padding: 22px 28px;
  border: 2px solid rgba(139, 77, 246, 0.82);
  border-radius: 14px;
  background: rgba(33, 29, 41, 0.96);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.52), 0 0 34px rgba(139, 77, 246, 0.24);
  text-align: center;
  transform: translate(-50%, -50%);
}

.score-toast.hidden {
  display: none;
}

.score-toast-stars {
  color: var(--purple);
  font-size: 40px;
  line-height: 1;
}

.score-toast-label {
  color: var(--green);
  font-size: 30px;
  font-weight: 900;
}

.score-toast-score {
  color: var(--text);
  font-size: 42px;
  font-weight: 900;
  line-height: 1;
}

.score-toast-detail {
  color: #b7b2bd;
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
}

.falling-emoji {
  position: absolute;
  top: -64px;
  animation-name: emoji-fall;
  animation-timing-function: cubic-bezier(0.18, 0.76, 0.32, 1);
  animation-fill-mode: forwards;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.35));
}

@keyframes emoji-fall {
  0% {
    opacity: 0;
    transform: translateY(-40px) rotate(0deg);
  }
  12% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translateY(112vh) rotate(220deg);
  }
}

.record-btn.ready {
  box-shadow: 0 0 0 2px rgba(139, 77, 246, 0.88), 0 0 28px rgba(139, 77, 246, 0.34);
}

.record-btn.recording {
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(139, 77, 246, 0.58);
  }
  70% {
    box-shadow: 0 0 0 22px rgba(139, 77, 246, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(139, 77, 246, 0);
  }
}

.score-card {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 42px;
  margin-top: 16px;
  color: var(--purple);
}

.score-card.visible {
  display: flex;
}

.stars {
  min-width: 92px;
  color: var(--purple);
  font-size: 30px;
  letter-spacing: 0;
}

.score-label {
  min-width: 92px;
  color: var(--green);
  font-size: 24px;
  font-weight: 900;
  text-align: left;
}

.score-value {
  min-width: 64px;
  color: var(--text);
  font-size: 30px;
  font-weight: 900;
  text-align: center;
}

.score-detail {
  flex-basis: 100%;
  color: #8f8f94;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
}

.certificate-btn {
  display: none;
  margin-top: 14px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 8px;
  background: #20302c;
  color: #d8fff4;
  font-size: 18px;
  font-weight: 900;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.72);
  z-index: 20;
}

.modal.hidden {
  display: none;
}

.modal-card {
  position: relative;
  width: min(420px, calc(100vw - 32px));
  padding: 28px;
  border: 1px solid rgba(139, 77, 246, 0.62);
  border-radius: 8px;
  background: #171717;
  text-align: center;
}

.modal-card h2 {
  margin: 0 0 12px;
  color: var(--purple);
}

.close-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #2b252c;
  font-size: 24px;
}

.browsing-only .read-controls,
.browsing-only .score-card {
  display: none;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
  }

  body {
    overflow: auto;
  }

  .pdf-panel {
    min-height: 720px;
  }

  .coach-panel {
    grid-template-rows: auto auto;
    padding-top: 0;
    min-height: 580px;
  }
}

@media (max-width: 768px) {
  .app-shell {
    gap: 14px;
    padding: 12px;
  }

  .pdf-panel {
    grid-template-rows: auto minmax(0, 1fr) auto;
    min-height: 560px;
  }

  .pdf-toolbar {
    grid-template-columns: minmax(0, 1fr) 54px auto;
    gap: 8px;
    min-height: 58px;
  }

  .pdf-toolbar::before {
    left: 14px;
    top: 17px;
    width: 20px;
    height: 20px;
  }

  .fullscreen-btn {
    top: 12px;
    right: 12px;
  }

  .translation-toggle {
    top: 12px;
  }

  .book-picker {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  #pdf-select,
  #book-search {
    height: 54px;
    font-size: 18px;
  }

  #pdf-select {
    padding: 0 12px 0 42px;
  }

  #book-search {
    padding: 0 12px 0 40px;
  }

  .book-search-icon {
    left: 14px;
    width: 17px;
    height: 17px;
    border-width: 2px;
  }

  .book-search-icon::after {
    right: -6px;
    bottom: -5px;
    width: 8px;
    height: 2px;
  }

  .tool-btn {
    width: 54px;
    height: 54px;
    border-radius: 10px;
    font-size: 32px;
  }

  .page-indicator {
    height: 54px;
    font-size: 20px;
  }

  .page-actions {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding-top: 16px;
  }

  .page-nav-btn {
    height: 58px;
    font-size: 20px;
  }

  .fox-frame {
    min-height: 220px;
    border-radius: 10px;
  }

  .coach-controls {
    padding-top: 24px;
  }

  .current-sentence,
  .translation-sentence {
    width: 100%;
    font-size: 28px;
  }

  .translation-sentence {
    font-size: 22px;
  }

  .read-controls {
    gap: 26px;
    margin-top: 28px;
  }

  .icon-btn {
    width: 64px;
    height: 64px;
  }

  .record-btn {
    width: 74px;
    height: 74px;
    font-size: 36px;
  }
}
