:root {
  --bg-0: #06090f;
  --bg-1: #101927;
  --bg-2: #1a2232;
  --panel: rgba(12, 19, 32, 0.84);
  --line: rgba(255, 218, 128, 0.28);
  --accent: #ffd166;
  --accent-strong: #fca311;
  --progress-accent: rgba(138, 207, 149, 0.78);
  --text-main: #f4f2eb;
  --text-muted: #d2d0c7;
  --danger: #ffb4b4;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  overflow: auto;
  color: var(--text-main);
  font-family: "Alegreya Sans", sans-serif;
  background:
    radial-gradient(circle at 12% 18%, #26354f 0, transparent 36%),
    radial-gradient(circle at 84% 78%, #352c1f 0, transparent 40%),
    linear-gradient(140deg, var(--bg-0), var(--bg-1) 55%, var(--bg-2));
}

body.is-stage-visible,
body.is-fullscreen,
body.is-fullscreen-lock {
  overflow: hidden;
}

.background-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(90deg, rgba(255, 209, 102, 0.06) 0 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 209, 102, 0.04) 0 1px, transparent 1px);
  background-size: 32px 32px;
  opacity: 0.35;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
}

.auth-gate[hidden] {
  display: none;
}

.auth-card {
  width: min(460px, 100%);
  display: grid;
  gap: 10px;
  padding: 18px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(8, 15, 24, 0.92);
  backdrop-filter: blur(8px);
}

.auth-card h2 {
  margin: 0 0 6px;
  font-family: "Unbounded", cursive;
  font-size: 1rem;
  color: var(--accent);
}

.auth-card label {
  display: grid;
  gap: 4px;
}

.auth-card span {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.auth-card input {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(8, 14, 24, 0.85);
  color: var(--text-main);
  font: inherit;
}

.auth-status {
  min-height: 1.2em;
  margin: 0;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.auth-links {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin: 2px 0 0;
  font-size: 0.9rem;
}

.auth-links a {
  color: var(--accent);
}

.app-shell {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  min-height: 100%;
  height: auto;
  padding: 12px;
}

.app-shell[hidden] {
  display: none;
}

.controls {
  width: min(980px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(6px);
}

.top-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
}

.controls h1 {
  margin: 0;
  font-family: "Unbounded", cursive;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--accent);
}

.menu-button {
  width: 42px;
  height: 36px;
  padding: 0;
  border-radius: 9px;
  font-size: 20px;
  line-height: 1;
}

.account-chip {
  justify-self: end;
  min-width: 72px;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--text-muted);
  font-size: 0.86rem;
  text-align: center;
}

.primary-block {
  display: grid;
}

.file-select-control {
  display: grid;
  gap: 4px;
}

.file-select-control span {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.playback-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 92px minmax(180px, 1fr) 92px auto auto auto;
  gap: 10px;
  align-items: end;
}

.speed-control,
.font-control {
  display: grid;
  gap: 4px;
}

.speed-control span,
.font-control span {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.meta {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.file-select,
.wpm-input,
input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  min-width: 0;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(8, 14, 24, 0.88);
  color: var(--text-main);
  font: inherit;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent-strong);
}

button {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 209, 102, 0.12);
  color: var(--text-main);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 140ms ease, background-color 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  background: rgba(255, 209, 102, 0.2);
}

.danger-button {
  background: rgba(155, 41, 41, 0.28);
  border-color: rgba(255, 180, 180, 0.34);
  color: #ffe4e4;
}

.danger-button:hover {
  background: rgba(180, 52, 52, 0.4);
}

button:disabled,
button:disabled:hover {
  transform: none;
  cursor: default;
  opacity: 0.45;
  background: rgba(255, 209, 102, 0.08);
}

.stage-host {
  position: relative;
  min-height: 0;
  display: none;
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 24%),
    linear-gradient(140deg, rgba(8, 15, 24, 0.95), rgba(8, 14, 24, 0.85));
}

body.is-stage-visible .stage-host {
  display: block;
}

body.is-stage-visible .controls {
  display: none;
}

body.is-stage-visible .app-shell {
  padding: 0;
  gap: 0;
  grid-template-rows: 1fr;
  min-height: 100%;
  height: 100%;
}

body.is-stage-visible .stage-host {
  border: none;
  border-radius: 0;
}

.logical-stage {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 1600px;
  height: 900px;
  transform-origin: center;
  border: 2px solid rgba(255, 209, 102, 0.4);
  border-radius: 10px;
  box-shadow:
    inset 0 0 70px rgba(0, 0, 0, 0.55),
    0 20px 44px rgba(0, 0, 0, 0.4);
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 209, 102, 0.08), transparent 35%),
    linear-gradient(180deg, #03060d, #070d17);
}

.stage-progress-badge {
  position: absolute;
  top: 26px;
  left: 72px;
  z-index: 4;
  color: var(--progress-accent);
  font-family: "Unbounded", cursive;
  font-size: 86px;
  font-weight: 400;
  letter-spacing: 0.04em;
  opacity: 0.72;
  pointer-events: none;
  user-select: none;
  transform: scaleX(-1);
  text-shadow: 0 0 12px rgba(54, 103, 57, 0.16);
}

.mirror-surface {
  position: absolute;
  inset: 58px 72px;
  overflow: hidden;
  transform: scaleX(-1);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

body.is-dragging .mirror-surface {
  cursor: grabbing;
}

.fullscreen-exit,
.fullscreen-join {
  position: absolute;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  padding: 0;
  line-height: 1;
  opacity: 0;
  pointer-events: none;
  z-index: 5;
  background: rgba(10, 16, 28, 0.7);
  border-color: rgba(255, 218, 128, 0.55);
}

.fullscreen-exit {
  top: 18px;
  right: 18px;
  font-size: 24px;
}

.fullscreen-join {
  top: 18px;
  left: 18px;
  font-size: 18px;
}

body.show-fullscreen-join .fullscreen-join,
body.is-fullscreen .fullscreen-exit,
body.is-fullscreen-lock .fullscreen-exit {
  opacity: 1;
  pointer-events: auto;
}

body.show-fullscreen-join .fullscreen-join:hover,
body.is-fullscreen .fullscreen-exit:hover {
  background: rgba(255, 209, 102, 0.2);
}

.text-track {
  margin: 0;
  width: 100%;
  color: #f6f4ee;
  font-family: "Alegreya Sans", sans-serif;
  font-size: 170px;
  line-height: 1.26;
  letter-spacing: 0.018em;
  font-weight: 500;
  white-space: pre-wrap;
  text-wrap: pretty;
  text-shadow:
    0 0 3px rgba(255, 244, 214, 0.5),
    0 0 12px rgba(255, 179, 71, 0.14);
  will-change: transform;
}

.menu-drawer,
.task-panel,
.admin-panel {
  position: fixed;
  inset: 0;
}

.menu-drawer[hidden],
.task-panel[hidden],
.admin-panel[hidden] {
  display: none;
}

.menu-drawer {
  z-index: 40;
}

.menu-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.45);
  padding: 0;
}

.menu-sheet {
  position: absolute;
  top: 0;
  left: 0;
  width: min(320px, 88vw);
  height: 100%;
  padding: 14px;
  border-right: 1px solid var(--line);
  background: rgba(8, 15, 24, 0.98);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  box-shadow: 18px 0 36px rgba(0, 0, 0, 0.5);
}

.menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.menu-head h2 {
  margin: 0;
  font-family: "Unbounded", cursive;
  font-size: 0.95rem;
  color: var(--accent);
}

.menu-actions {
  display: grid;
  gap: 8px;
  align-content: start;
}

.android-server-settings {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
}

.android-server-settings label {
  display: grid;
  gap: 4px;
}

.android-server-settings span {
  color: var(--text-muted);
  font-size: 0.86rem;
}

.task-panel,
.admin-panel {
  z-index: 45;
  padding: 12px;
  background: rgba(0, 0, 0, 0.5);
  display: grid;
  place-items: center;
}

.task-card,
.admin-card {
  width: min(980px, 100%);
  max-height: 92vh;
  overflow: auto;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(8, 15, 24, 0.96);
}

.task-card-narrow {
  width: min(560px, 100%);
}

.task-head,
.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.task-head h2,
.admin-head h2 {
  margin: 0;
  font-family: "Unbounded", cursive;
  font-size: 0.95rem;
  color: var(--accent);
}

.panel-note {
  margin: 10px 0 12px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.panel-subnote {
  margin: -4px 0 12px;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.panel-link {
  color: var(--accent);
}

.pricing-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.plan-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: start;
  background: rgba(12, 19, 32, 0.58);
}

.plan-card-accent {
  background: linear-gradient(180deg, rgba(255, 209, 102, 0.12), rgba(12, 19, 32, 0.72));
  border-color: rgba(255, 209, 102, 0.42);
}

.plan-eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.plan-card h3 {
  margin: 0;
  font-size: 1.06rem;
}

.plan-feature-list {
  margin: 0;
  padding-left: 18px;
  color: var(--text-muted);
  display: grid;
  gap: 6px;
}

.plan-offers {
  display: grid;
  gap: 8px;
}

#restorePurchasesButton {
  width: 100%;
}

.plan-offer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 10px;
  border-radius: 10px;
  background: rgba(8, 14, 24, 0.72);
  border: 1px solid rgba(255, 209, 102, 0.18);
  color: var(--text-muted);
}

.file-tools {
  display: grid;
  grid-template-columns: repeat(3, minmax(140px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.editor-panel {
  display: grid;
  gap: 8px;
}

.controls .editor-panel {
  margin-top: 2px;
}

.editor-label {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.file-editor {
  width: 100%;
  min-height: 220px;
  resize: vertical;
  line-height: 1.35;
}

.controls .file-editor {
  min-height: 150px;
}

.editor-actions,
.account-actions,
.admin-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.admin-grid {
  margin-top: 12px;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
}

.admin-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.admin-block h3 {
  margin: 0;
  font-size: 1rem;
}

.admin-block label {
  display: grid;
  gap: 4px;
}

.admin-block span {
  color: var(--text-muted);
  font-size: 0.86rem;
}

.inline-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.inline-toggle input {
  margin: 0;
}

.admin-status {
  margin: 12px 0 4px;
  min-height: 1.2em;
  color: var(--text-muted);
}

.admin-adapter-meta {
  display: grid;
  gap: 2px;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid rgba(255, 209, 102, 0.18);
  background: rgba(8, 14, 24, 0.58);
}

.admin-adapter-meta .panel-subnote {
  margin: 0;
}

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

.admin-event-row {
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border-radius: 10px;
  background: rgba(8, 14, 24, 0.72);
  border: 1px solid rgba(255, 209, 102, 0.16);
}

.admin-event-row.is-selected {
  border-color: rgba(255, 209, 102, 0.55);
  box-shadow: 0 0 0 1px rgba(255, 209, 102, 0.18) inset;
}

.admin-event-row strong {
  font-size: 0.92rem;
}

.admin-event-row span {
  color: var(--text-muted);
  font-size: 0.8rem;
}

@media (max-width: 1080px) {
  .playback-row {
    grid-template-columns: 1fr 1fr;
  }

  .speed-control,
  .font-control,
  .meta,
  #toggleButton,
  #startFromStartButton,
  #resetButton,
  #fullscreenToggleButton,
  #wpmInput,
  #fontSizeInput {
    grid-column: 1 / -1;
    width: 100%;
  }

  .meta {
    gap: 8px 12px;
  }

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

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
  }

  .controls {
    padding: 10px;
    border-radius: 12px;
  }

  .top-row {
    grid-template-columns: auto 1fr;
  }

  .account-chip {
    grid-column: 1 / -1;
    justify-self: start;
  }

  .menu-sheet {
    width: min(360px, 92vw);
  }

  .task-panel,
  .admin-panel {
    padding: 8px;
  }

  .task-card,
  .admin-card {
    padding: 10px;
    border-radius: 12px;
  }

  .file-tools {
    grid-template-columns: 1fr;
  }

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

  .controls .file-editor {
    min-height: 120px;
  }

  .stage-progress-badge {
    top: 18px;
    left: 24px;
  }

  .editor-actions,
  .account-actions,
  .admin-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}
