@font-face {
  font-family: "A Lodyx";
  src: url("./fonts/A-lodyx.ttf") format("truetype");
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #000000;
  --panel: #1a1a1a;
  --text: #ffffff;
  --muted: #bdbdbd;
  --track: #343434;
  --accent-blue: #52bfff;
  --accent-purple: #b354ff;
  --accent-green: #4dd979;
  --display-size: 36px;
  --display-active-size: 75px;
  --transition-ms: 250ms;
  --bottom-safe: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

button,
input[type="range"] {
  touch-action: manipulation;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100svh;
  min-height: 560px;
  overflow: hidden;
  background: var(--bg);
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  padding: max(18px, env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) max(26px, env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left));
}

.portal-tools {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: max(24px, env(safe-area-inset-left));
  max-width: 210px;
  display: grid;
  gap: 5px;
  justify-items: start;
  z-index: 5;
}

.portal-home,
.progress-code {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.portal-home {
  opacity: 0.78;
}

.portal-home:hover,
.portal-home:focus-visible {
  opacity: 1;
}

.progress-code {
  min-height: 28px;
  display: inline-flex;
  gap: 7px;
  align-items: center;
  padding: 4px 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.progress-code:disabled {
  cursor: default;
  opacity: 0.7;
}

.sync-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--muted);
}

.sync-dot.is-synced {
  background: var(--accent-green);
}

.sync-dot.is-pending {
  background: #e8b04b;
}

.sync-dot.is-offline {
  background: #d26a77;
}

.sync-status {
  min-height: 14px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.top-progress {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: 50%;
  width: min(46vw, 560px);
  transform: translateX(-50%);
  z-index: 2;
}

.progress-block {
  display: grid;
  gap: 4px;
  justify-items: center;
}

.progress-label,
.context-text {
  color: var(--muted);
  font-weight: 600;
}

.progress-label {
  min-height: 16px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
}

progress {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  background: var(--track);
}

progress::-webkit-progress-bar {
  border-radius: 999px;
  background: var(--track);
}

progress::-webkit-progress-value {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-green));
}

progress::-moz-progress-bar {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-blue), var(--accent-green));
}

.level-control {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  right: max(24px, env(safe-area-inset-right));
  display: grid;
  justify-items: center;
  gap: 8px;
  z-index: 3;
}

.level-viewport {
  position: relative;
  width: 54px;
  height: 58px;
  overflow: hidden;
  border-radius: 10px;
  background: var(--panel);
}

.level-number {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 34px;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  transition: transform 200ms ease, opacity 200ms ease;
}

.level-number.is-changing-up {
  animation: level-up 200ms ease;
}

.level-number.is-changing-down {
  animation: level-down 200ms ease;
}

@keyframes level-up {
  from {
    opacity: 0;
    transform: translateY(26px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes level-down {
  from {
    opacity: 0;
    transform: translateY(-26px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.reader-stage {
  position: absolute;
  inset: 92px 40px 210px;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  place-items: center;
  gap: 18px;
}

.display-text {
  width: min(100%, 1180px);
  max-height: 100%;
  display: block;
  overflow: hidden;
  color: var(--text);
  font-family: "A Lodyx", cursive;
  font-size: var(--display-size);
  font-weight: 400;
  line-height: 1.35;
  text-align: center;
  overflow-wrap: anywhere;
}

.display-text.single-line {
  white-space: nowrap;
  text-overflow: clip;
}

.display-text.multi-line {
  white-space: normal;
}

.display-char,
.display-word {
  display: inline-block;
  min-width: 0.02em;
  color: var(--text);
  font-family: "A Lodyx", cursive;
  font-size: var(--display-size);
  font-weight: 400;
  line-height: 1.05;
  vertical-align: baseline;
  transition:
    color var(--transition-ms) cubic-bezier(0.2, 0.8, 0.2, 1),
    font-size var(--transition-ms) cubic-bezier(0.2, 0.8, 0.2, 1),
    font-weight var(--transition-ms) cubic-bezier(0.2, 0.8, 0.2, 1),
    transform var(--transition-ms) cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: color, font-size, transform;
}

.display-word + .display-word {
  margin-left: 0.28em;
}

.display-char.is-active,
.display-word.is-active {
  color: var(--accent-purple);
  font-size: var(--display-active-size);
  font-weight: 800;
}

.display-char.is-entering,
.display-word.is-entering {
  animation: highlight-color var(--transition-ms) ease forwards;
}

@keyframes highlight-color {
  from {
    color: var(--accent-blue);
  }
  to {
    color: var(--accent-purple);
  }
}

.context-text {
  width: min(100%, 960px);
  min-height: 24px;
  overflow: hidden;
  font-size: 18px;
  line-height: 1.35;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.case-control {
  position: absolute;
  left: max(24px, env(safe-area-inset-left));
  bottom: calc(122px + var(--bottom-safe));
  z-index: 4;
}

.case-toggle {
  min-height: 48px;
  display: inline-flex;
  gap: 10px;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  background: rgba(26, 26, 26, 0.92);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.case-toggle input {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--accent-green);
  cursor: pointer;
}

.case-toggle:focus-within {
  outline: 3px solid var(--accent-blue);
  outline-offset: 3px;
}

.transport {
  position: absolute;
  left: 50%;
  bottom: calc(116px + var(--bottom-safe));
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: center;
  transform: translateX(-50%);
  z-index: 4;
}

.icon-button {
  width: 56px;
  height: 56px;
  display: inline-grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background-color 140ms ease, color 140ms ease, opacity 140ms ease, transform 140ms ease;
}

.icon-button:active {
  transform: scale(0.94);
  background: rgba(255, 255, 255, 0.12);
}

.icon-button:focus-visible {
  outline: 3px solid var(--accent-blue);
  outline-offset: 3px;
}

.icon-button:disabled {
  cursor: default;
  opacity: 0.35;
  transform: none;
}

.icon-button svg {
  width: 32px;
  height: 32px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.level-button {
  width: 48px;
  height: 44px;
  border-radius: 10px;
}

.level-button svg {
  width: 28px;
  height: 28px;
}

.mastered-button.is-mastered {
  color: var(--accent-green);
}

.speed-panel {
  position: absolute;
  left: max(24px, env(safe-area-inset-left));
  right: max(24px, env(safe-area-inset-right));
  bottom: calc(18px + var(--bottom-safe));
  display: grid;
  gap: 6px;
  z-index: 3;
}

.speed-label {
  justify-self: center;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  font-weight: 650;
  line-height: 1;
}

.speed-slider,
.story-slider {
  width: 100%;
  height: 40px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}

.story-slider {
  height: 34px;
}

.speed-slider::-webkit-slider-runnable-track,
.story-slider::-webkit-slider-runnable-track {
  height: 8px;
  border-radius: 999px;
  background: var(--track);
}

.speed-slider::-moz-range-track,
.story-slider::-moz-range-track {
  height: 8px;
  border-radius: 999px;
  background: var(--track);
}

.speed-slider::-webkit-slider-thumb,
.story-slider::-webkit-slider-thumb {
  width: 34px;
  height: 34px;
  margin-top: -13px;
  border: 0;
  border-radius: 50%;
  appearance: none;
  -webkit-appearance: none;
  background: var(--text);
  box-shadow: 0 0 0 10px rgba(255, 255, 255, 0.08);
}

.speed-slider::-moz-range-thumb,
.story-slider::-moz-range-thumb {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: var(--text);
  box-shadow: 0 0 0 10px rgba(255, 255, 255, 0.08);
}

.speed-ticks {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  color: #b8b8b8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  line-height: 1;
}

.speed-ticks span {
  min-width: 0;
  text-align: center;
}

.is-hidden {
  display: none !important;
}

@media (orientation: portrait) {
  .top-progress {
    width: min(58vw, 560px);
  }

  .reader-stage {
    inset: 104px 34px 222px;
  }
}

@media (max-width: 620px) {
  .portal-tools {
    top: max(12px, env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    max-width: 145px;
  }

  .portal-home,
  .progress-code {
    font-size: 11px;
  }

  .sync-status {
    max-width: 140px;
  }

  .top-progress {
    top: max(72px, env(safe-area-inset-top));
    width: min(64vw, 420px);
  }

  .reader-stage {
    top: 122px;
  }

  .level-control {
    right: max(12px, env(safe-area-inset-right));
  }

  .display-text.level-3 {
    --excerpt-size: 20px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow: visible;
  }

  .display-text.level-3 .display-word {
    position: relative;
    font-size: var(--excerpt-size);
    transform: scale(1);
  }

  .display-text.level-3 .display-word.is-active {
    z-index: 2;
    color: var(--accent-purple);
    font-size: var(--excerpt-size);
    transform: scale(1.8);
    background: var(--bg);
  }

  .case-control {
    left: 50%;
    bottom: calc(172px + var(--bottom-safe));
    transform: translateX(-50%);
  }
}

@media (max-height: 680px) {
  :root {
    --display-size: 32px;
    --display-active-size: 64px;
  }

  .reader-stage {
    top: 82px;
    bottom: 200px;
  }

  .transport {
    bottom: calc(94px + var(--bottom-safe));
  }

  .case-control {
    bottom: calc(150px + var(--bottom-safe));
  }

  .speed-panel {
    bottom: calc(16px + var(--bottom-safe));
    gap: 5px;
  }

  .speed-slider {
    height: 34px;
  }
}

@media (pointer: fine) {
  .icon-button:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.08);
  }
}
