:root {
  --bg: #09090b;
  --ink: #f6f1e7;
  --muted: #a39b8d;
  --gold: #e4c27a;
  --gold-deep: #c9a15a;
  --line: rgba(228, 194, 122, 0.28);
  --app-h: 100dvh;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Instrument Sans", "Segoe UI", sans-serif;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

button, p { font: inherit; }

button { touch-action: manipulation; }

#app {
  position: relative;
  height: var(--app-h);
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    max(10px, env(safe-area-inset-top))
    14px
    max(12px, env(safe-area-inset-bottom));
  background:
    radial-gradient(900px 420px at 50% -12%, rgba(228, 194, 122, 0.16), transparent 58%),
    var(--bg);
}

.brand {
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 28px;
  letter-spacing: 0.16em;
  line-height: 1;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 2px 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill, .icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  font-size: 14px;
}

.pill b { font-weight: 600; }

.pill { white-space: nowrap; }

.pill-balance {
  color: var(--gold);
  border-color: rgba(228, 194, 122, 0.45);
  background: rgba(228, 194, 122, 0.12);
  font-size: 13px;
}

.icon-btn {
  width: 36px;
  justify-content: center;
  padding: 0;
  cursor: pointer;
}

.icon-btn svg { width: 18px; height: 18px; display: block; }

.player {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 28px;
  overflow: hidden;
  background: #050506;
  box-shadow:
    0 0 0 1px var(--line),
    0 24px 50px rgba(0, 0, 0, 0.38);
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #050506;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

video::-webkit-media-controls,
video::-webkit-media-controls-start-playback-button,
video::-webkit-media-controls-overlay-play-button {
  display: none !important;
  -webkit-appearance: none;
}

.scrub {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 12px;
  height: 2px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.22);
  z-index: 2;
  pointer-events: none;
}

.scrub span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--gold);
}

#catch-wrap {
  position: absolute;
  left: 50%;
  top: 43%;
  transform: translate(-50%, -50%);
  z-index: 4;
}

.catch, #catch {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: min(78vw, 280px);
  height: 76px;
  padding: 0 22px 0 14px;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #f8e7c0 0%, #e0b85a 55%, #c8963e 100%);
  color: #1c1408;
  cursor: pointer;
  box-shadow:
    0 0 0 1px rgba(28, 20, 8, 0.45),
    0 16px 40px rgba(0, 0, 0, 0.45);
  animation: pop 0.28s ease, glow 1.35s ease-in-out infinite;
}

#catch:active { transform: scale(0.98); }

#catch.urgent {
  animation-duration: 0.28s, 0.55s;
}

.ring { width: 44px; height: 44px; transform: rotate(-90deg); flex: none; }

.ring circle {
  fill: none;
  stroke-width: 3;
  stroke: rgba(28, 20, 8, 0.2);
}

#ring { stroke: #1c1408; stroke-linecap: round; }

.catch-copy {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}

#catch-label {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

#catch-sec {
  font-style: normal;
  font-size: 13px;
  opacity: 0.72;
  font-variant-numeric: tabular-nums;
}

#toast, #resume, #error {
  position: absolute;
  z-index: 5;
}

#toast {
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(12, 12, 14, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 14px;
  letter-spacing: 0.02em;
}

#toast.ok { color: #d7eccf; }
#toast.miss { color: #f0c9c2; }

#resume, #error {
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  text-align: center;
}

#resume, #retry, #start, #block-btn {
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, #f6e7c4, #d7b56a);
  color: #1c1408;
  font-weight: 600;
  cursor: pointer;
}

#resume, #retry {
  height: 48px;
  padding: 0 18px;
}

#error {
  width: min(80%, 280px);
  color: var(--ink);
}

#error p { margin: 0 0 12px; }

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 3;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 12px;
  color: var(--gold);
  background: rgba(5, 5, 6, 0.28);
}

.foot {
  display: grid;
  gap: 10px;
  padding: 12px 4px 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.foot p { margin: 0; }

.volume {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 36px;
}

.vol-icon {
  width: 22px;
  height: 22px;
  flex: none;
  color: #f3e2bc;
}

.vol-icon svg { width: 22px; height: 22px; display: block; }

#volume {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 28px;
  margin: 0;
  background: transparent;
  touch-action: pan-x;
}

#volume::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.16);
}

#volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -9px;
  border: 0;
  border-radius: 50%;
  background: #f3e2bc;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

#volume::-moz-range-track {
  height: 4px;
  border: 0;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.16);
}

#volume::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: #f3e2bc;
}

#gate, #block {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding:
    max(22px, env(safe-area-inset-top))
    8px
    max(18px, env(safe-area-inset-bottom));
}

#block {
  z-index: 7;
  background:
    radial-gradient(700px 380px at 50% 0%, rgba(228, 194, 122, 0.18), transparent 60%),
    #09090b;
}

#gate { justify-content: flex-end; padding: 0; }

.gate-veil {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(700px 380px at 50% 0%, rgba(228, 194, 122, 0.18), transparent 60%),
    #09090b;
  transition: opacity 0.55s ease;
}

#gate.leaving .gate-veil,
#gate.leaving .gate-bottom { opacity: 0; }

.gate-brand {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 2;
  margin: 0;
  font-size: 52px;
  letter-spacing: 0.2em;
  line-height: 1;
  transform: translate(-50%, -50%);
}

#app:has(#gate:not([hidden])) > .top .brand { visibility: hidden; }

.gate-bottom {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 14px;
  padding:
    0
    8px
    max(18px, env(safe-area-inset-bottom));
  transition: opacity 0.28s ease;
}

#gate-text, #block-text {
  margin: 0;
  font-size: 18px;
  line-height: 1.4;
  max-width: 28ch;
}

#block-title {
  margin: 0;
  font-family: "Instrument Serif", Georgia, serif;
  font-size: 40px;
  font-weight: 400;
  line-height: 0.95;
}

#start, #block-btn {
  height: 56px;
  width: 100%;
  font-size: 17px;
}

#start:disabled {
  opacity: 0.45;
  cursor: default;
}

#gate[hidden],
#block[hidden],
#catch-wrap[hidden],
#toast[hidden],
#resume[hidden],
#error[hidden],
.loading[hidden] {
  display: none !important;
}

@keyframes pop {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: none; }
}

@keyframes glow {
  0%, 100% { box-shadow: 0 12px 30px rgba(228, 194, 122, 0.22); }
  50% { box-shadow: 0 16px 36px rgba(228, 194, 122, 0.48); }
}

@media (max-width: 360px) {
  .brand { font-size: 24px; letter-spacing: 0.12em; }
  .gate-brand { font-size: 42px; letter-spacing: 0.16em; }
  #catch { height: 70px; min-width: min(86vw, 260px); }
}

@media (prefers-reduced-motion: reduce) {
  .gate-veil, .gate-bottom, .gate-brand { transition: none; }
}

@media (min-width: 840px) {
  body { display: grid; place-items: center; }
  #app {
    width: min(420px, 100%);
    height: min(var(--app-h), 900px);
    border-radius: 32px;
    overflow: hidden;
    box-shadow: 0 30px 80px rgba(0, 0, 0, 0.45);
  }
}

@media (prefers-reduced-motion: reduce) {
  #catch { animation: none; }
}
