:root {
  color-scheme: dark;
  --bg: #070707;
  --ink: #fff6e8;
  --muted: #e4ddd0;
  --amber: #ffbf3c;
  --amber-ink: #1a1406;
  --red: #9d1c1c;
  --panel: #121212;
  --line: #2e2e2e;
  --guide-top: calc(env(safe-area-inset-top, 0px) + 2.6rem);
  --scrim: 0.35;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
}

body { overflow: hidden; }

#app {
  height: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

[hidden] { display: none !important; }

button,
.button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button,
.button {
  min-height: 48px;
  padding: 0.65rem 0.8rem;
  border-radius: 14px;
  border: 1px solid #3a3a3a;
  background: #1a1a1a;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 600;
  line-height: 1.2;
}

button.primary,
.button.primary {
  background: var(--amber);
  color: var(--amber-ink);
  border-color: transparent;
}

button.danger {
  background: var(--red);
  color: #fff;
  border-color: transparent;
}

button:disabled {
  color: #b3adA3;
  background: #141414;
  border-color: #2a2a2a;
}

button:focus-visible,
.button:focus-within,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}

button:active { transform: scale(0.98); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  overflow: hidden;
  touch-action: none;
}

.preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #000;
  z-index: 0;
  pointer-events: none;
}

.preview.mirrored { transform: scaleX(-1); }

#stage.layout-pip .preview {
  inset: auto;
  width: 9.5rem;
  height: 12.75rem;
  border: 2px solid rgba(255, 246, 232, 0.9);
  border-radius: 18px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.55);
  z-index: 6;
  pointer-events: auto;
  touch-action: none;
}

.scrim {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--guide-top) - 2.2rem);
  height: 42vh;
  z-index: 1;
  pointer-events: none;
  background: #000;
  opacity: var(--scrim);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 18%, #000 62%, transparent 100%);
  mask-image: linear-gradient(to bottom, transparent 0%, #000 18%, #000 62%, transparent 100%);
}

.prompter {
  position: absolute;
  inset: 0;
  z-index: 2;
  overflow: hidden;
  padding-left: max(1.1rem, env(safe-area-inset-left, 0px));
  padding-right: max(1.1rem, env(safe-area-inset-right, 0px));
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent calc(var(--guide-top) - 2.2rem),
    #000 var(--guide-top),
    #000 calc(var(--guide-top) + 16vh),
    transparent calc(var(--guide-top) + 38vh)
  );
  mask-image: linear-gradient(
    to bottom,
    transparent calc(var(--guide-top) - 2.2rem),
    #000 var(--guide-top),
    #000 calc(var(--guide-top) + 16vh),
    transparent calc(var(--guide-top) + 38vh)
  );
}

.script {
  margin: 0;
  padding-top: var(--guide-top);
  color: var(--ink);
  font-size: 52px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.02em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.95), 0 0 14px rgba(0, 0, 0, 0.55);
  transform-origin: center top;
  will-change: transform;
}

.guide {
  position: absolute;
  z-index: 3;
  left: 0;
  right: 0;
  top: var(--guide-top);
  border-top: 2px solid var(--amber);
  pointer-events: none;
}

.guide span {
  position: absolute;
  top: -0.85rem;
  right: max(0.8rem, env(safe-area-inset-right, 0px));
  padding: 0 0.35rem;
  background: #070707;
  color: var(--amber);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.taplayer {
  position: absolute;
  inset: 0;
  z-index: 4;
}

.empty {
  position: absolute;
  z-index: 3;
  left: max(1.1rem, env(safe-area-inset-left, 0px));
  right: max(1.1rem, env(safe-area-inset-right, 0px));
  top: var(--guide-top);
  margin: 0;
  color: var(--ink);
  font-size: 1.7rem;
  font-weight: 600;
  line-height: 1.35;
  pointer-events: none;
}

.banner {
  position: absolute;
  z-index: 6;
  left: max(0.75rem, env(safe-area-inset-left, 0px));
  right: max(0.75rem, env(safe-area-inset-right, 0px));
  bottom: 0.75rem;
  margin: 0;
  padding: 0.8rem 0.9rem;
  border: 1px solid var(--amber);
  border-radius: 12px;
  background: #2a2108;
  color: #fff6df;
  font-size: 1rem;
  line-height: 1.35;
}

.countdown {
  position: absolute;
  inset: 0;
  z-index: 7;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 0;
  background: rgba(0, 0, 0, 0.45);
  color: var(--amber);
}

#count-num {
  font-size: 8rem;
  font-weight: 700;
  line-height: 0.9;
  font-variant-numeric: tabular-nums;
}

.count-hint {
  color: var(--ink);
  font-size: 1.15rem;
  font-weight: 600;
}

.truth {
  background: #0b0b0b;
  border-top: 1px solid var(--line);
}

.truth summary {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.9rem;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}

.truth summary::-webkit-details-marker { display: none; }

.truth summary::after {
  content: "Details";
  margin-left: auto;
  color: var(--amber);
  font-weight: 700;
  flex: none;
}

#status-line { line-height: 1.3; }

.truth pre,
.review pre {
  margin: 0;
  max-height: 40vh;
  overflow: auto;
  padding: 0.75rem 0.9rem 0.9rem;
  background: #101010;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 0.85rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  -webkit-user-select: text;
  user-select: text;
}

.dock {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  background: #0b0b0b;
  border-top: 1px solid var(--line);
}

#play,
#record {
  flex: 1 1 calc(50% - 8px);
  min-height: 56px;
}

#font-dec,
#font-inc,
#speed-dec,
#speed-inc {
  flex: 1 1 calc(25% - 8px);
}

#top,
#settings-open {
  flex: 1 1 calc(50% - 8px);
}

.fine {
  flex: 1 1 100%;
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.35;
}

.review {
  position: fixed;
  inset: 0;
  z-index: 15;
  overflow: auto;
  padding:
    calc(0.85rem + env(safe-area-inset-top, 0px))
    max(1rem, env(safe-area-inset-right, 0px))
    calc(1rem + env(safe-area-inset-bottom, 0px))
    max(1rem, env(safe-area-inset-left, 0px));
  background: var(--bg);
}

.review h2,
.review h3 { margin: 0 0 0.6rem; }

.review h2 { font-size: 1.5rem; }

#review-video {
  width: 100%;
  max-height: 32vh;
  object-fit: contain;
  background: #000;
  border-radius: 12px;
}

#review-video.mirrored { transform: scaleX(-1); }

.comparison {
  margin: 0.8rem 0;
  font-size: 1.15rem;
  font-weight: 600;
  line-height: 1.35;
}

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat {
  padding: 0.75rem;
  border-radius: 12px;
  background: var(--panel);
}

.stat b {
  display: block;
  font-size: 1.35rem;
  font-variant-numeric: tabular-nums;
}

.stat span {
  color: var(--muted);
  font-size: 0.85rem;
}

.review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 0.9rem;
}

.review-actions button { flex: 1 1 calc(50% - 8px); }

#share {
  flex-basis: 100%;
  min-height: 56px;
}

.hint {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.4;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
}

.sheet-card {
  width: min(40rem, 100%);
  max-height: min(92dvh, 100%);
  overflow: auto;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
  border-radius: 18px 18px 0 0;
  background: #121212;
  -webkit-overflow-scrolling: touch;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 0.6rem;
}

.sheet-head h2 { margin: 0; font-size: 1.35rem; }

.sheet-head button { flex: none; }

.sheet-card label {
  display: block;
  margin: 0.9rem 0 0.35rem;
  font-weight: 600;
}

.sheet-card textarea,
.sheet-card input[type="range"] {
  width: 100%;
}

.sheet-card textarea {
  min-height: 10rem;
  padding: 0.75rem;
  border: 1px solid #3a3a3a;
  border-radius: 12px;
  background: #0e0e0e;
  font-size: 1rem;
  line-height: 1.4;
}

.sheet-card input[type="range"] {
  accent-color: var(--amber);
  min-height: 48px;
}

.check {
  display: flex !important;
  align-items: center;
  gap: 0.75rem;
  min-height: 48px;
  margin-top: 0.35rem !important;
  font-weight: 600;
}

.check input {
  width: 1.4rem;
  height: 1.4rem;
  accent-color: var(--amber);
  flex: none;
}

fieldset {
  margin: 1rem 0 0;
  padding: 0.4rem 0.8rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
}

legend { padding: 0 0.3rem; font-weight: 700; }

.file-btn {
  position: relative;
  display: flex !important;
  align-items: center;
  justify-content: center;
  margin-top: 0.7rem !important;
}

.file-btn input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.noscript {
  padding: 1.5rem;
  font-size: 1.2rem;
}

::selection {
  background: var(--amber);
  color: var(--amber-ink);
}

@media (orientation: landscape) {
  :root { --guide-top: calc(env(safe-area-inset-top, 0px) + 1.15rem); }
  .stats { grid-template-columns: repeat(4, 1fr); }
  .sheet { align-items: center; }
  .sheet-card {
    width: min(44rem, calc(100% - 2rem));
    max-height: 92dvh;
    border-radius: 18px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  #play,
  #record,
  #font-dec,
  #font-inc,
  #speed-dec,
  #speed-inc,
  #top,
  #settings-open {
    flex: 1 1 0;
    min-width: 0;
    min-height: 48px;
    padding-left: 0.3rem;
    padding-right: 0.3rem;
    font-size: 0.95rem;
  }
  .dock { padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
  .fine { display: none; }
  .truth summary { min-height: 40px; padding-top: 0.2rem; padding-bottom: 0.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  button:active { transform: none; }
}
