:root {
  --base: #181825;
  --mantle: #13131e;
  --surface0: #272836;
  --surface1: #8a6b4d;
  --surface1-muted: #5c564c;
  --text: #b2cdee;
  --subtext0: #bbb5ac;
  --overlay0: #9c9386;
  --green: #9be096;
  --teal: #8ce0d2;
  --lavender: #98c2fe;
  --peach: #f9ab7a;
  --blue: #7bbbf9;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: "JetBrains Mono";
  src: url("fonts/JetBrainsMono-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: block;
}

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

html {
  color-scheme: dark;
  background: var(--mantle);
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

/* Allow rubber-band / pull-to-refresh on touch phones without affecting desktop layout */
@media (max-width: 640px), ((hover: none) and (pointer: coarse)) {
  html,
  body {
    height: auto;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior-y: auto;
  }

  /* While dragging/resizing a window, freeze document scroll */
  html.is-scroll-locked,
  html.is-scroll-locked body {
    overflow: hidden;
    overscroll-behavior-y: none;
  }

  .page-shell {
    height: auto;
    max-height: none;
    min-height: 100dvh;
  }

  .page-shell.ascii-scroll {
    overflow: visible;
  }

  .page-shell > .ascii-scroll-viewport {
    overflow: visible;
  }

  .page-shell > .ascii-scrollbar {
    display: none;
  }
}

body {
  min-height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: center;
  background: var(--mantle);
  color: var(--text);
  font-family: "JetBrains Mono", ui-monospace, "Cascadia Code", "Fira Code",
    monospace;
  font-size: 14px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.page-shell {
  width: 100%;
  height: 100%;
  max-height: 100%;
}

.page-shell > .ascii-scroll-viewport {
  display: flex;
  align-items: center;
  justify-content: center;
}

.dashboard {
  width: min(100%, 40ch);
  padding: 2rem 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.brand {
  margin: 0 0 1.25rem;
  color: var(--text);
  font: inherit;
  font-size: 1.25rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-align: center;
  user-select: none;
}

.header {
  margin: 0;
  padding: 0;
  color: var(--teal);
  font: inherit;
  font-size: clamp(0.7rem, 2.4vw, 0.95rem);
  line-height: 1.15;
  white-space: pre;
  overflow: hidden;
  max-width: 100%;
  user-select: none;
}

.footer[hidden] {
  display: none;
}

.menu[hidden] {
  display: none;
}

.menu {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.15rem;
  margin: 1.75rem 0 0;
  width: min(100%, 22ch);
  padding: 0;
}

.menu-item {
  display: flex;
  align-items: baseline;
  gap: 1.25rem;
  width: 100%;
  margin: 0;
  padding: 0.35rem 0.75rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
  outline: none;
}

.menu-item .shortcut {
  color: var(--lavender);
  flex: 0 0 auto;
}

#item-playlist .shortcut {
  display: inline-block;
  transform-origin: center center;
}

#item-playlist.is-armed .shortcut {
  animation: spin-p 2.4s linear infinite;
  animation-play-state: paused;
}

#item-playlist.is-armed.is-playing .shortcut {
  animation-play-state: running;
}

@keyframes spin-p {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  #item-playlist.is-armed .shortcut {
    animation: none;
  }
}

.menu-item .label {
  color: var(--blue);
}

.menu-item:hover {
  background: color-mix(in srgb, var(--surface0) 70%, transparent);
}

.menu-item.is-selected {
  background: var(--surface0);
}

.menu-item.is-selected .shortcut {
  color: var(--peach);
}

.menu-item.is-selected .label {
  color: var(--green);
  font-weight: 500;
}

.menu-item:focus-visible {
  box-shadow: inset 0 0 0 1px var(--lavender);
}

.footer {
  margin: 1.75rem 0 0;
  color: var(--overlay0);
  font-size: 0.8rem;
  text-align: center;
  white-space: nowrap;
  user-select: none;
}

.popup-window {
  position: fixed;
  z-index: 20;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(36rem, calc(100vw - 2.5rem));
  max-height: min(72vh, 30rem);
  display: flex;
  flex-direction: column;
  background: var(--mantle);
  border: 1px solid var(--surface1-muted);
  color: var(--subtext0);
  font: inherit;
  box-shadow: 0 12px 40px rgba(14, 14, 22, 0.53);
}

.popup-window.is-active {
  border-color: var(--surface1);
}

.popup-window[hidden] {
  display: none;
}

.popup-window.is-resizing {
  user-select: none;
}

.popup-window.is-dragging .popup-titlebar {
  cursor: grabbing;
}

.popup-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 0.65rem;
  background: var(--surface0);
  border-bottom: 1px solid var(--surface1-muted);
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.popup-window.is-active .popup-titlebar {
  border-bottom-color: var(--surface1);
}

.popup-resize-handle {
  position: absolute;
  z-index: 2;
  background: transparent;
  touch-action: none;
}

.popup-resize-handle[data-resize="n"],
.popup-resize-handle[data-resize="s"] {
  left: 8px;
  right: 8px;
  height: 6px;
  cursor: ns-resize;
}

.popup-resize-handle[data-resize="n"] {
  top: -3px;
}

.popup-resize-handle[data-resize="s"] {
  bottom: -3px;
}

.popup-resize-handle[data-resize="e"],
.popup-resize-handle[data-resize="w"] {
  top: 8px;
  bottom: 8px;
  width: 6px;
  cursor: ew-resize;
}

.popup-resize-handle[data-resize="e"] {
  right: -3px;
}

.popup-resize-handle[data-resize="w"] {
  left: -3px;
}

.popup-resize-handle[data-resize="nw"],
.popup-resize-handle[data-resize="ne"],
.popup-resize-handle[data-resize="sw"],
.popup-resize-handle[data-resize="se"] {
  width: 12px;
  height: 12px;
}

.popup-resize-handle[data-resize="nw"] {
  top: -4px;
  left: -4px;
  cursor: nwse-resize;
}

.popup-resize-handle[data-resize="ne"] {
  top: -4px;
  right: -4px;
  cursor: nesw-resize;
}

.popup-resize-handle[data-resize="sw"] {
  bottom: -4px;
  left: -4px;
  cursor: nesw-resize;
}

.popup-resize-handle[data-resize="se"] {
  bottom: -4px;
  right: -4px;
  cursor: nwse-resize;
}

.popup-title {
  color: var(--subtext0);
  font: inherit;
}

.popup-title-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.popup-close {
  margin: 0;
  padding: 0.1rem 0.25rem;
  border: none;
  background: transparent;
  color: var(--peach);
  font: inherit;
  cursor: pointer;
  line-height: 1;
  text-decoration: none;
}

.popup-player-info {
  width: min(28rem, calc(100vw - 2.5rem));
  max-height: min(40vh, 16rem);
  color: var(--text);
}

.popup-player-info .popup-titlebar {
  cursor: default;
}

.popup-close:hover,
.popup-close:focus-visible {
  color: var(--green);
  outline: none;
}

.popup-body {
  padding: 0;
  overflow: hidden;
  font: inherit;
  color: inherit;
  line-height: inherit;
  min-height: 0;
  flex: 1 1 auto;
}

.popup-body > .ascii-scroll-viewport {
  padding: 1rem 0.85rem 1.2rem 1.1rem;
}

.popup-body > .ascii-scroll-viewport[contenteditable="true"] {
  outline: none;
  caret-color: var(--text);
}

.popup-body a {
  color: var(--blue);
}

.popup-body a:hover {
  color: var(--teal);
}

.popup-body p {
  margin: 0 0 0.85rem;
}

.popup-body p:last-child {
  margin-bottom: 0;
}

.ascii-scroll {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  min-height: 0;
  overflow: hidden;
}

.ascii-scroll-viewport {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  scrollbar-width: none;
  /* Keep list overscroll from scrolling the page / stealing pull-to-refresh */
  overscroll-behavior: contain;
}

.ascii-scroll-viewport::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.ascii-scrollbar {
  flex: 0 0 1.25ch;
  margin: 0;
  padding: 0.15rem 0;
  border: none;
  background: transparent;
  color: var(--overlay0);
  font: inherit;
  line-height: 1.15;
  letter-spacing: 0;
  text-align: center;
  white-space: pre;
  user-select: none;
  cursor: default;
  overflow: hidden;
}

.ascii-scrollbar .cap {
  color: var(--subtext0);
  cursor: pointer;
}

.ascii-scrollbar .cap:hover {
  color: var(--green);
}

.ascii-scrollbar .track {
  color: #b6afa6;
}

.ascii-scrollbar .thumb {
  color: var(--lavender);
}

.ascii-scrollbar.is-idle {
  display: none;
}

.popup-playlist {
  left: 1rem;
  bottom: 1rem;
  top: auto;
  transform: none;
  width: min(34rem, calc(100vw - 2.5rem));
  height: min(74vh, 38rem);
  max-height: min(74vh, 38rem);
  color: var(--text);
}

.popup-cv {
  right: 1rem;
  bottom: 1rem;
  left: auto;
  top: auto;
  transform: none;
  /* 1.5× player window (34rem × 74vh/38rem) */
  width: min(51rem, calc(100vw - 2.5rem));
  height: min(111vh, 57rem, calc(100vh - 2rem));
  max-height: none;
}

.popup-cv-body {
  padding: 0;
  overflow: hidden;
  background: #fff;
}

.popup-cv-body iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.popup-dcss {
  width: min(34rem, calc(100vw - 2.5rem));
  max-height: min(74vh, 38rem);
}

.dcss-links-sep {
  margin: 0 0.35rem;
  opacity: 0.5;
}

.popup-dcss-console {
  width: min(51rem, calc(100vw - 2.5rem));
  height: min(111vh, 57rem, calc(100vh - 2rem));
  max-height: none;
}

.popup-dcss-console-body {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.dcss-console-meta {
  flex: 0 0 auto;
  padding: 0.4rem 0.65rem 0.45rem;
  border-bottom: 1px solid var(--surface1);
}

.dcss-blurb,
.dcss-login,
.dcss-controls,
.dcss-status {
  margin: 0;
}

.dcss-blurb {
  margin-bottom: 0.35rem;
}

.dcss-login,
.dcss-controls,
.dcss-status {
  font-size: 0.8rem;
  line-height: 1.35;
}

.dcss-login code {
  font-family: inherit;
}

.dcss-copy {
  appearance: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 0.15em;
}

.dcss-copy:hover,
.dcss-copy:focus-visible {
  color: var(--green, #9be096);
  outline: none;
}

.dcss-copy.is-copied {
  color: var(--teal, #8ce0d2);
  text-decoration-style: solid;
}

.dcss-controls {
  margin-top: 0.25rem;
}

.dcss-controls-sep {
  margin: 0 0.35rem;
  opacity: 0.45;
}

.dcss-status {
  margin-top: 0.25rem;
  opacity: 0.75;
}

.dcss-term {
  flex: 1 1 auto;
  min-height: 0;
  padding: 0.35rem;
  background: #000;
}

.dcss-term .xterm {
  height: 100%;
}

.dcss-term .xterm-viewport {
  overflow-y: auto !important;
}

.playlist-transport {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex: 0 0 auto;
  position: relative;
  padding: 0.35rem 0.65rem 0.5rem;
  border-bottom: 1px solid var(--surface1);
  background: var(--base);
}

.playlist-transport .playlist-ctrl#playlist-youtube {
  position: absolute;
  right: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
}

.playlist-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  flex: 0 0 auto;
  padding: 0.4rem 0.65rem;
  border-bottom: 1px solid var(--surface1);
  background: var(--mantle);
}

.playlist-tab {
  margin: 0;
  padding: 0.1rem 0;
  border: none;
  background: transparent;
  color: var(--overlay0);
  font: inherit;
  cursor: pointer;
  line-height: 1.3;
}

.playlist-tab:hover,
.playlist-tab:focus-visible {
  color: var(--blue);
  outline: none;
}

.playlist-tab.is-active {
  color: var(--green);
}

.playlist-ctrl {
  margin: 0;
  padding: 0.15rem 0.2rem;
  border: none;
  background: transparent;
  color: var(--lavender);
  font: inherit;
  cursor: pointer;
  line-height: 1;
}

.playlist-ctrl:hover,
.playlist-ctrl:focus-visible {
  color: var(--green);
  outline: none;
}

.playlist-timebar {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  width: 100%;
  box-sizing: border-box;
  margin: 0;
  padding: 0.4rem 0.65rem 0.15rem;
  border-bottom: none;
  background: var(--base);
  color: #b6afa6;
  font: inherit;
  line-height: 1;
  letter-spacing: 0;
  white-space: pre;
  overflow: hidden;
  user-select: none;
  cursor: pointer;
}

.playlist-timebar .edge {
  flex: 0 0 auto;
  color: var(--subtext0);
}

.playlist-timebar .ticks {
  flex: 1 1 auto;
  display: flex;
  min-width: 0;
}

.playlist-timebar .tick {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  color: #b6afa6;
}

.playlist-timebar .tick.is-elapsed {
  color: var(--green);
}

.playlist-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.playlist-video {
  flex: 2 1 0;
  min-height: 0;
  position: relative;
  background: #0e0e16;
  border-bottom: 1px solid var(--surface1);
  pointer-events: none;
}

.popup-playlist.is-video-minimized .playlist-video {
  display: none;
}

.yt-stage iframe,
.yt-stage #yt-player-host {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
}

.yt-stage {
  /* Always hosts the iframe — never reparent (that reloads the video) */
  position: fixed;
  left: 0;
  bottom: 0;
  width: 1px;
  height: 1px;
  opacity: 1;
  pointer-events: none;
  overflow: hidden;
  z-index: -1;
}

.yt-stage.is-docked {
  bottom: auto;
}

.playlist-body {
  flex: 1 1 0;
  min-height: 0;
  padding: 0;
  overflow: hidden;
}

.playlist-body > .ascii-scroll-viewport {
  padding: 0.35rem 0.25rem 0.5rem 0.4rem;
}

.playlist-tracks {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.playlist-track {
  display: flex;
  align-items: baseline;
  gap: 0.65rem;
  width: 100%;
  margin: 0;
  padding: 0.3rem 0.5rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  outline: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.playlist-track:hover:not(:disabled) {
  background: color-mix(in srgb, var(--surface0) 70%, transparent);
}

.playlist-track.is-current {
  background: var(--surface0);
}

.playlist-track:disabled {
  color: var(--overlay0);
  cursor: not-allowed;
}

.playlist-track .num {
  flex: 0 0 auto;
  color: var(--lavender);
}

.playlist-track.is-current .num {
  color: var(--peach);
}

.playlist-track .title {
  color: var(--blue);
  font-size: inherit;
}

.playlist-track .title-wrap {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.playlist-track.is-current .title {
  color: var(--green);
}

.playlist-track.is-playing .title-wrap.is-overflow {
  text-overflow: clip;
}

.playlist-track.is-playing .title-wrap.is-overflow .title {
  display: inline-block;
  padding-right: 2ch;
  animation: playlist-marquee 12s linear infinite;
}

@keyframes playlist-marquee {
  0% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(calc(-100% + 4ch));
  }
}

@media (max-width: 640px) {
  body {
    align-items: flex-start;
  }

  .dashboard {
    padding-top: 1.25rem;
  }

  .header {
    font-size: 0.65rem;
  }

  .menu {
    width: min(100%, 22ch);
  }

  .popup-playlist {
    width: calc(100vw - 2.5rem);
    height: min(68vh, 30rem);
    max-height: min(68vh, 30rem);
  }

  .popup-cv {
    width: calc(100vw - 2.5rem);
    height: min(102vh, 45rem, calc(100vh - 2rem));
  }

  .popup-dcss {
    width: calc(100vw - 2.5rem);
  }

  .popup-dcss-console {
    width: calc(100vw - 2.5rem);
    height: min(102vh, 45rem, calc(100vh - 2rem));
  }
}
