/* Solo Endurance Trainer - Clean, Responsive Dark UI */

/* Global container overrides when on Endurance */
html, body {
  overflow-x: hidden !important;
  max-width: 100vw !important;
}

body.play-shell {
  background: #0b0d12 !important;
  color: #f5f7fa !important;
}

body.play-shell .play-header {
  background: #0b0d12 !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1) !important;
}

body.play-shell .play-header a {
  color: #f5f7fa !important;
}

body.play-shell .play-container {
  padding-left: 0 !important;
  padding-right: 0 !important;
  max-width: 100% !important;
  width: 100% !important;
  overflow-x: hidden !important;
}

/* Base Page */
.en-page {
  --en-bg: #0b0d12;
  --en-card: rgba(255, 255, 255, 0.05);
  --en-border: rgba(255, 255, 255, 0.1);
  --en-lime: #c8fa46;
  --en-cyan: #55cde0;
  --en-coral: #ff695e;
  --en-text: #f5f7fa;
  --en-muted: #9aa4b2;

  position: relative;
  isolation: isolate;
  color: var(--en-text);
  background: var(--en-bg);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 40px) max(14px, env(safe-area-inset-right)) max(56px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overflow-x: hidden;
  min-height: calc(100dvh - 70px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.en-page *, .en-page *::before, .en-page *::after {
  box-sizing: border-box;
}

/* Background Ambient Orbs */
.en-bg {
  position: absolute;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(85, 205, 224, 0.18), transparent 60%),
    radial-gradient(ellipse at 100% 100%, rgba(200, 250, 70, 0.1), transparent 55%);
}

.en-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.45;
  animation: en-float 14s ease-in-out infinite;
}

.en-orb-a {
  width: min(320px, 80vw);
  height: min(320px, 80vw);
  background: #2a6df4;
  top: -80px;
  left: -60px;
}

.en-orb-b {
  width: min(280px, 75vw);
  height: min(280px, 75vw);
  background: #7c3aed;
  bottom: -60px;
  right: -60px;
  animation-delay: -6s;
}

@keyframes en-float {
  50% { transform: translate(30px, 25px) scale(1.08); }
}

/* Header Section */
.en-hero {
  text-align: center;
  max-width: 680px;
  margin: 0 auto clamp(18px, 3vw, 32px);
  padding: 0 8px;
}

.en-pill {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 999px;
  background: var(--en-card);
  border: 1px solid var(--en-border);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--en-cyan);
  font-weight: 700;
}

.en-hero h1 {
  font-family: "Arial Black", system-ui, sans-serif;
  font-weight: 900;
  font-size: clamp(1.8rem, 5.5vw, 3.4rem);
  line-height: 1.1;
  margin: 10px 0 8px;
  color: #fff;
}

.en-grad {
  background: linear-gradient(90deg, var(--en-lime), var(--en-cyan));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.en-hero p {
  color: var(--en-muted);
  font-size: clamp(0.9rem, 2vw, 1.1rem);
  margin: 0;
  line-height: 1.4;
}

/* Layout Grid */
.en-layout {
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: clamp(16px, 2.5vw, 28px);
  align-items: start;
}

/* Stage Card (Left) */
.en-stage {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.07), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--en-border);
  border-radius: 24px;
  padding: clamp(16px, 3vw, 28px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  width: 100%;
  max-width: 100%;
}

/* Ring & Camera View */
.en-ring {
  width: 100%;
  max-width: 440px;
  padding: 5px;
  border-radius: 24px;
  background: conic-gradient(from 0deg, var(--en-cyan), var(--en-lime), var(--en-cyan));
  box-shadow: 0 0 35px rgba(85, 205, 224, 0.25);
  transition: box-shadow 0.4s, background 0.4s;
}

.en-page[data-state="staring"] .en-ring {
  animation: en-pulse 1.6s ease-in-out infinite;
  background: conic-gradient(from 0deg, var(--en-lime), #fff, var(--en-lime));
}

.en-page[data-state="finished"] .en-ring {
  background: var(--en-coral);
  box-shadow: 0 0 50px rgba(255, 105, 94, 0.5);
}

@keyframes en-pulse {
  50% { box-shadow: 0 0 65px rgba(200, 250, 70, 0.6); }
}

.en-camera {
  position: relative;
  aspect-ratio: 4 / 3;
  width: 100%;
  border-radius: 19px;
  overflow: hidden;
  background: #05070a;
}

.en-camera video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  display: block;
}

.en-camera video[hidden] {
  display: none;
}

.en-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--en-muted);
  background: transparent;
  padding: 12px;
  text-align: center;
}

.en-placeholder[hidden] {
  display: none;
}

/* Live & Face Badges on Camera */
.en-rec {
  position: absolute;
  top: 10px;
  left: 10px;
  display: none;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.en-rec i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--en-coral);
  animation: en-blink 1s infinite;
}

.en-page[data-state="staring"] .en-rec {
  display: inline-flex;
}

@keyframes en-blink {
  50% { opacity: 0.2; }
}

.en-face-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.65);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--en-lime);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 2;
  transition: all 0.2s;
}

.en-face-badge.badge-warning {
  color: var(--en-coral);
  border-color: var(--en-coral);
}

.en-face-badge[hidden] {
  display: none;
}

/* Countdown Overlay */
.en-countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(5, 7, 10, 0.74);
  z-index: 3;
}

.en-countdown[hidden] {
  display: none;
}

.en-countdown span {
  font-family: "Arial Black", sans-serif;
  font-size: clamp(3.5rem, 16vw, 7rem);
  color: var(--en-lime);
  text-shadow: 0 0 40px rgba(200, 250, 70, 0.6);
  animation: en-pop 0.9s ease-out infinite;
}

@keyframes en-pop {
  from { transform: scale(1.35); opacity: 0.35; }
  to { transform: scale(1); opacity: 1; }
}

/* Stopwatch Timer */
.en-timer-wrap {
  text-align: center;
  width: 100%;
}

.en-timer {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: clamp(2.6rem, 10vw, 5rem);
  line-height: 1;
  letter-spacing: -0.02em;
  color: #fff;
  text-shadow: 0 0 28px rgba(85, 205, 224, 0.35);
}

.en-page[data-state="staring"] .en-timer {
  color: var(--en-lime);
  text-shadow: 0 0 34px rgba(200, 250, 70, 0.45);
}

.en-tier {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  margin-top: 10px;
  padding: 6px 16px;
  border-radius: 999px;
  background: var(--en-card);
  border: 1px solid var(--en-border);
  font-weight: 700;
  font-size: 0.95rem;
}

.en-progress {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  margin: 16px auto 0;
  max-width: 440px;
  width: 100%;
  overflow: hidden;
}

.en-progress-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--en-cyan), var(--en-lime));
  transition: width 0.15s linear;
}

/* Action Buttons */
.en-controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}

.en-btn {
  appearance: none;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 24px;
  border-radius: 14px;
  font-weight: 800;
  font-size: 0.98rem;
  transition: transform 0.12s, box-shadow 0.2s, background 0.2s;
  touch-action: manipulation;
}

.en-btn[hidden] {
  display: none;
}

.en-btn:hover {
  transform: translateY(-2px);
}

.en-btn:active {
  transform: translateY(0);
}

.en-btn:focus-visible {
  outline: 3px solid var(--en-cyan);
  outline-offset: 3px;
}

.en-btn-primary {
  background: linear-gradient(135deg, var(--en-lime), #8ee03a);
  color: #0b0d12;
  box-shadow: 0 8px 26px rgba(200, 250, 70, 0.35);
  font-size: 1.05rem;
  padding: 14px 32px;
}

.en-btn-ghost {
  background: var(--en-card);
  color: var(--en-text);
  border-color: var(--en-border);
}

.en-btn-ghost:hover {
  background: rgba(255, 255, 255, 0.12);
}

.en-btn-lime {
  background: var(--en-lime);
  color: #0b0d12;
  width: 100%;
}

.en-btn-close-action {
  background: rgba(255, 255, 255, 0.08);
  color: var(--en-muted);
  border: 1px solid var(--en-border);
}

.en-btn-close-action:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.en-status {
  margin: 0;
  color: var(--en-muted);
  text-align: center;
  font-size: 0.92rem;
  min-height: 1.4em;
  line-height: 1.35;
}

/* Sidebar (Right) */
.en-side {
  display: grid;
  gap: 16px;
  width: 100%;
}

.en-card {
  background: var(--en-card);
  border: 1px solid var(--en-border);
  border-radius: 20px;
  padding: 20px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.en-card h3 {
  margin: 0 0 10px;
  font-size: 1rem;
  color: var(--en-text);
  font-weight: 800;
}

.en-card p {
  margin: 0 0 14px;
  color: var(--en-muted);
  font-size: 0.92rem;
}

.en-best {
  background: linear-gradient(135deg, rgba(200, 250, 70, 0.14), rgba(85, 205, 224, 0.1));
  border-color: rgba(200, 250, 70, 0.3);
  text-align: center;
}

.en-best-time {
  font-family: ui-monospace, Consolas, monospace;
  font-weight: 800;
  font-size: clamp(2rem, 5vw, 2.7rem);
  color: var(--en-lime);
}

.en-best p {
  margin: 6px 0 0;
}

.en-tiers {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.en-tiers .tier-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid transparent;
  transition: all 0.25s;
  color: var(--en-text);
  font-size: 0.92rem;
}

.en-tiers .tier-time {
  color: var(--en-muted);
  font-size: 0.84rem;
  white-space: nowrap;
}

.en-tiers .tier-item.tier-active {
  background: rgba(200, 250, 70, 0.15);
  border-color: var(--en-lime);
  transform: scale(1.02);
  box-shadow: 0 0 20px rgba(200, 250, 70, 0.25);
}

/* Result Modal Dialog */
.en-dialog {
  border: 0;
  padding: 0;
  background: transparent;
  width: min(92vw, 420px);
  max-width: 92vw;
  color: var(--en-text, #fff);
  margin: auto;
  border-radius: 24px;
}

.en-dialog::backdrop {
  background: rgba(5, 7, 10, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.en-dialog-body {
  position: relative;
  background: linear-gradient(160deg, #181d28, #0e1118);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 24px;
  padding: 30px 22px 24px;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7);
  animation: en-rise 0.35s ease-out;
  max-height: 88dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

@keyframes en-rise {
  from { transform: translateY(20px) scale(0.96); opacity: 0; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

.en-dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
  font-size: 1.8rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.1s;
  z-index: 10;
  touch-action: manipulation;
}

.en-dialog-close:hover {
  background: rgba(255, 255, 255, 0.22);
  transform: scale(1.05);
}

.en-dialog-close:active {
  transform: scale(0.95);
}

.en-dialog-eyebrow {
  margin: 0;
  color: #9aa4b2;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.74rem;
  font-weight: 700;
}

.en-dialog h2 {
  margin: 6px 0 10px;
  font-family: "Arial Black", sans-serif;
  font-size: 1.9rem;
  color: #ff695e;
}

.en-dialog-time {
  font-family: ui-monospace, Consolas, monospace;
  font-weight: 800;
  font-size: clamp(2.4rem, 11vw, 3.4rem);
  color: #fff;
  margin: 4px 0;
}

.en-dialog-tier {
  display: inline-flex;
  gap: 8px;
  margin: 10px 0 6px;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  font-weight: 700;
  font-size: 0.95rem;
}

.en-pb {
  margin: 12px 0 0;
  color: #c8fa46;
  font-weight: 800;
  animation: en-blink 1.2s infinite;
}

.en-dialog-actions {
  display: grid;
  gap: 10px;
  margin-top: 20px;
}

.en-dialog-actions .en-btn {
  width: 100%;
}

/* =========================================================
   Responsive Breakpoints: Tablet & Mobile (including iPhone)
   ========================================================= */

@media (max-width: 860px) {
  .en-layout {
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
  }
  .en-side {
    grid-template-columns: 1fr 1fr;
  }
  .en-cta {
    grid-column: 1 / -1;
  }
}

@media (max-width: 560px) {
  .en-page {
    padding: 12px 10px 48px;
  }
  .en-hero {
    margin-bottom: 14px;
  }
  .en-hero h1 {
    font-size: clamp(1.6rem, 8vw, 2.2rem);
  }
  .en-hero p {
    font-size: 0.88rem;
  }
  .en-stage {
    border-radius: 18px;
    padding: 12px 10px;
    gap: 14px;
  }
  .en-ring {
    border-radius: 18px;
    padding: 4px;
    max-width: 100%;
  }
  .en-camera {
    border-radius: 15px;
  }
  .en-timer {
    font-size: clamp(2.3rem, 12vw, 3.2rem);
  }
  .en-tier {
    font-size: 0.88rem;
    padding: 5px 14px;
  }
  .en-controls {
    flex-direction: column;
    width: 100%;
  }
  .en-btn {
    width: 100%;
    min-height: 48px;
    font-size: 0.95rem;
  }
  .en-side {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }
  .en-card {
    border-radius: 16px;
    padding: 16px 14px;
  }
  .en-tiers .tier-item {
    font-size: 0.88rem;
    padding: 9px 12px;
  }
  .en-dialog-body {
    padding: 24px 16px 20px;
    border-radius: 20px;
  }
  .en-dialog h2 {
    font-size: 1.6rem;
  }
  .en-dialog-time {
    font-size: clamp(2.2rem, 11vw, 2.8rem);
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .en-ring {
    width: min(55%, 300px);
  }
  .en-hero {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .en-orb, .en-ring, .en-rec i, .en-countdown span, .en-pb {
    animation: none !important;
  }
}
