:root {
  color-scheme: dark;
  --bg: #000;
  --fg: #fff;
  --muted: #a7a7a7;
  --panel: rgba(0, 0, 0, 0.82);
  --line: rgba(255, 255, 255, 0.16);
  --button: #191919;
  --button-hover: #2a2a2a;
  --button-disabled: #101010;
  --accent: #fff;
  --bar-height: 68px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  font-family:
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  touch-action: manipulation;
}

button,
textarea {
  font: inherit;
}

.app-shell {
  position: fixed;
  top: var(--visual-offset-top, 0px);
  left: var(--visual-offset-left, 0px);
  width: var(--visual-width, 100vw);
  height: var(--visual-height, 100dvh);
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
}

.top-bar,
.bottom-bar {
  position: absolute;
  z-index: 10;
  left: 0;
  right: 0;
  height: var(--bar-height);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px calc(clamp(12px, 3vw, 28px) + var(--safe-right)) 10px
    calc(clamp(12px, 3vw, 28px) + var(--safe-left));
  background: var(--panel);
  border-color: var(--line);
  backdrop-filter: blur(10px);
}

.top-bar {
  top: 0;
  height: calc(var(--bar-height) + var(--safe-top));
  padding-top: calc(10px + var(--safe-top));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  justify-content: stretch;
  border-bottom: 1px solid var(--line);
}

.bottom-bar {
  bottom: 0;
  height: calc(var(--bar-height) + var(--safe-bottom));
  padding-bottom: calc(10px + var(--safe-bottom));
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  justify-content: stretch;
  border-top: 1px solid var(--line);
}

#fontControls {
  grid-column: 1;
  justify-self: start;
}

#playButton {
  grid-column: 2;
  justify-self: center;
}

.speed-cluster {
  grid-column: 3;
  justify-self: end;
}

.time-group {
  grid-column: 2;
  justify-self: center;
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 132px;
  justify-content: center;
}

.time-value {
  font-size: 24px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

#elapsedTime {
  color: #ffffff;
}

#remainingTime {
  color: #7dd3fc;
}

.time-separator {
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.top-actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 8px;
}

.reader-panel,
.editor-panel {
  position: absolute;
  inset: calc(var(--bar-height) + var(--safe-top)) 0 calc(var(--bar-height) + var(--safe-bottom));
  background: var(--bg);
}

.scroll-container {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: #666 #000;
  scrollbar-width: thin;
}

.script-content {
  width: min(1100px, 100%);
  margin: 0 auto;
  padding-inline: clamp(20px, 7vw, 92px);
  color: var(--fg);
  font-size: 48px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.end-marker {
  display: block;
  width: 1px;
  height: 0;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  font-size: 22px;
  pointer-events: none;
}

.script-editor {
  width: 100%;
  height: 100%;
  display: block;
  resize: none;
  border: 0;
  outline: 0;
  padding: clamp(20px, 7vw, 92px);
  background: var(--bg);
  color: var(--fg);
  font-size: 28px;
  line-height: 1.55;
}

.control-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.control-button,
.icon-button,
.primary-button {
  border: 1px solid var(--line);
  background: var(--button);
  color: var(--fg);
  cursor: pointer;
  transition:
    background 120ms ease,
    border-color 120ms ease,
    opacity 120ms ease;
}

.control-button:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.primary-button:hover:not(:disabled) {
  background: var(--button-hover);
  border-color: rgba(255, 255, 255, 0.34);
}

.control-button:disabled,
.icon-button:disabled,
.primary-button:disabled {
  color: #696969;
  cursor: not-allowed;
  background: var(--button-disabled);
}

.control-button {
  height: 42px;
  min-width: 76px;
  padding: 0 16px;
  border-radius: 8px;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: 8px;
}

.primary-button {
  width: clamp(92px, 18vw, 150px);
  height: 46px;
  border-radius: 8px;
  display: inline-grid;
  place-items: center;
}

.play-icon {
  width: 24px;
  height: 24px;
  display: block;
  fill: currentColor;
  pointer-events: none;
}

.play-icon * {
  pointer-events: none;
}

.control-value {
  min-width: 38px;
  text-align: center;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.notice {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: calc(var(--bar-height) + 12px);
  transform: translateX(-50%);
  max-width: min(90vw, 420px);
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151515;
  color: var(--fg);
  font-size: 14px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 640px) {
  :root {
    --bar-height: 64px;
  }

  .top-bar,
  .bottom-bar {
    padding-inline: 10px;
    gap: 8px;
  }

  .time-value {
    font-size: 20px;
  }

  .time-group {
    min-width: 112px;
    gap: 8px;
  }

  .icon-button {
    width: 36px;
    height: 38px;
  }

  .primary-button {
    width: 84px;
    font-size: 16px;
  }

  .control-value {
    min-width: 30px;
  }

  .script-content {
    padding-inline: 22px;
  }
}
