:root {
  color-scheme: dark;
  --bg: #101413;
  --surface: #18201f;
  --surface-2: #202927;
  --text: #f6f1e8;
  --muted: #b9c2bb;
  --accent: #2fb7a3;
  --accent-2: #d6a848;
  --danger: #9e3f44;
  --border: #33413d;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.38);
  font-family: "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 14px;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  padding:
    max(14px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
}

.watch,
.panel {
  min-width: 0;
  min-height: 0;
}

.watch {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding-bottom: 8px;
}

.kicker {
  margin: 0 0 4px;
  color: var(--accent-2);
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

.stage {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #050606;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.youtube-player,
.youtube-player iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.subtitle-layer {
  pointer-events: none;
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8%;
  display: flex;
  justify-content: center;
  padding: 0 28px;
  z-index: 4;
}

.subtitle-text {
  max-width: min(92%, 1100px);
  min-height: 1.4em;
  color: #fffaf0;
  font-size: 38px;
  font-weight: 800;
  line-height: 1.22;
  text-align: center;
  text-shadow:
    -2px -2px 0 #000,
    2px -2px 0 #000,
    -2px 2px 0 #000,
    2px 2px 0 #000,
    0 5px 18px rgba(0, 0, 0, 0.85);
  white-space: pre-line;
}

.subtitle-text:empty {
  min-height: 0;
  padding: 0 !important;
  background: transparent !important;
  text-shadow: none !important;
}

.loading-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  z-index: 2;
  color: var(--muted);
  background: #050606;
}

.loading-state.is-hidden {
  display: none;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 0 0;
}

.primary-button,
.control-button,
.icon-button,
.mini-button,
.episode-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.primary-button,
.control-button {
  min-height: 44px;
  padding: 0 14px;
}

.primary-button {
  border-color: transparent;
  background: var(--accent);
  color: #07100f;
  font-weight: 800;
}

.icon-button {
  width: 44px;
  height: 44px;
  font-size: 24px;
}

.mini-button {
  min-height: 36px;
  padding: 0 12px;
}

.primary-button:hover,
.control-button:hover,
.icon-button:hover,
.mini-button:hover,
.episode-button:hover {
  border-color: var(--accent);
}

.panel {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 12px;
  height: 100%;
  overflow: hidden;
  padding-top: 66px;
}

.episode-list {
  display: grid;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
  scrollbar-gutter: stable;
}

.episode-button {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 58px;
  padding: 8px 10px;
  text-align: left;
}

.episode-number {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  background: var(--surface-2);
  color: var(--accent-2);
  font-weight: 800;
}

.episode-name {
  display: block;
  color: var(--text);
  font-weight: 800;
}

.episode-duration {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 14px;
}

.episode-button.is-active {
  border-color: var(--accent);
  background: #162a27;
}

.settings {
  display: grid;
  gap: 10px;
  align-self: end;
  min-height: 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.settings label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

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

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

output {
  min-width: 62px;
  color: var(--accent-2);
  font-weight: 800;
  text-align: center;
}

@media (max-height: 740px) and (min-width: 981px) {
  .shell {
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .topbar {
    min-height: 50px;
    padding-bottom: 6px;
  }

  h1 {
    font-size: 22px;
  }

  .panel {
    gap: 8px;
    padding-top: 56px;
  }

  .episode-list {
    gap: 6px;
  }

  .episode-button {
    min-height: 48px;
    padding: 6px 8px;
  }

  .episode-number {
    width: 34px;
    height: 34px;
  }

  .settings {
    gap: 6px;
    padding: 8px 10px;
  }

  .controls {
    padding-top: 8px;
  }

  .primary-button,
  .control-button {
    min-height: 40px;
  }
}

.stage:fullscreen,
body.is-stage-expanded .stage {
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  aspect-ratio: auto;
  border: 0;
  box-shadow: none;
}

.stage:fullscreen .subtitle-text,
body.is-stage-expanded .stage .subtitle-text {
  max-width: min(94%, 1200px);
  font-size: clamp(28px, var(--fullscreen-subtitle-size, 48px), 72px);
}

body.is-stage-expanded .stage {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

body.is-stage-expanded #fullscreenButton {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 1010;
  border-color: transparent;
  background: rgba(5, 6, 6, 0.24);
  opacity: 0.12;
  transition: opacity 180ms ease, background 180ms ease;
}

body.is-stage-expanded.is-fullscreen-ui-visible #fullscreenButton,
body.is-stage-expanded #fullscreenButton:focus-visible {
  background: rgba(5, 6, 6, 0.72);
  opacity: 1;
  backdrop-filter: blur(8px);
}

body.is-stage-expanded .subtitle-layer {
  position: fixed;
  z-index: 1020;
  bottom: max(8dvh, calc(env(safe-area-inset-bottom) + 34px));
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
}

@media (max-width: 980px) {
  .shell {
    grid-template-rows: minmax(0, 1fr) auto;
    grid-template-columns: 1fr;
    gap: 10px;
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
    gap: 10px;
    height: auto;
    max-height: 180px;
    padding-top: 0;
  }

  .episode-list {
    grid-template-columns: repeat(5, minmax(92px, 1fr));
    overflow-x: auto;
  }

  .episode-button {
    grid-template-columns: 34px minmax(0, 1fr);
    min-height: 60px;
  }

  .episode-number {
    width: 34px;
    height: 34px;
  }

  .subtitle-text {
    font-size: 30px;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 22px;
  }

  .panel {
    grid-template-columns: 1fr;
    max-height: 170px;
  }

  .settings {
    display: none;
  }

  .subtitle-layer {
    bottom: 7%;
    padding: 0 14px;
  }

  .subtitle-text {
    font-size: 24px;
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .primary-button,
  .control-button {
    min-width: 0;
    padding: 0 10px;
  }
}

@media (max-width: 980px) and (pointer: coarse) {
  body {
    overflow-y: auto;
  }

  .shell {
    display: block;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .watch {
    display: block;
    height: auto;
  }

  .topbar {
    min-height: 0;
    padding-bottom: 12px;
  }

  .stage {
    height: auto;
    aspect-ratio: 16 / 9;
  }

  .controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 12px 0;
  }

  .primary-button,
  .control-button {
    min-width: 0;
    min-height: 52px;
    padding: 0 10px;
  }

  .panel {
    display: block;
    height: auto;
    max-height: none;
    overflow: visible;
    padding-top: 0;
  }

  .episode-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 8px;
    overflow: visible;
    padding: 0 0 max(20px, env(safe-area-inset-bottom));
  }

  .episode-button {
    display: grid;
    grid-template-columns: 1fr;
    place-items: center;
    min-height: 54px;
    padding: 6px;
    text-align: center;
  }

  .episode-number {
    width: auto;
    height: auto;
    background: transparent;
    font-size: 20px;
  }

  .episode-name,
  .episode-duration {
    display: none;
  }

  .settings {
    display: none;
  }

  .subtitle-layer {
    bottom: 6%;
    padding: 0 12px;
  }

  .subtitle-text {
    font-size: clamp(18px, 5vw, 24px) !important;
    padding: 0.08em 0.28em 0.12em;
    background: rgba(0, 0, 0, 0.62);
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
    -webkit-text-stroke: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9);
  }
}

@media (max-width: 980px) and (pointer: coarse) and (orientation: landscape) {
  body.is-stage-expanded .subtitle-layer {
    bottom: max(10dvh, calc(env(safe-area-inset-bottom) + 28px));
  }

  body.is-stage-expanded .stage .subtitle-text {
    font-size: clamp(18px, 4.2vw, 24px) !important;
    -webkit-text-stroke: 0;
  }

  body.is-stage-expanded .youtube-player,
  body.is-stage-expanded .youtube-player iframe {
    inset: auto;
    top: 50%;
    left: 50%;
    width: calc(177.778dvh * 1.06);
    height: calc(100dvh * 1.06);
    transform: translate(-50%, -50%);
  }
}
