/* Clean and minimal: system font, black / gray / white, no effects. */

:root {
  color-scheme: dark;

  --bg: #000;
  --surface: #1c1c1e;
  --fill: #2c2c2e;
  --separator: rgba(255, 255, 255, 0.1);
  --text: #fff;
  --text-2: rgba(235, 235, 245, 0.62);
  --text-3: rgba(235, 235, 245, 0.42);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --radius: 12px;
  --gutter: 20px;
  --bar-h: 52px;
  --tab-h: 50px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);

  --budget: 1; /* share of today's time left, set live by app.js */
}

/* ------------------------------------------------------------------ base */

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

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
}

button {
  font: inherit;
  color: inherit;
}

p,
h1,
h2,
h3 {
  margin: 0;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.85);
  outline-offset: 2px;
  border-radius: 6px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  width: 20px;
  height: 20px;
  flex: none;
}

.nums {
  font-variant-numeric: tabular-nums;
}

/* ------------------------------------------------------------------ top bar */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  padding-top: var(--safe-t);
  background: rgba(0, 0, 0, 0.78);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid transparent;
}

.is-scrolled .topbar {
  border-bottom-color: var(--separator);
}

.topbar-inner {
  max-width: 1200px;
  height: var(--bar-h);
  margin: 0 auto;
  padding: 0 calc(var(--gutter) + var(--safe-r)) 0 calc(var(--gutter) + var(--safe-l));
  display: flex;
  align-items: center;
  gap: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.back {
  display: none;
  align-items: center;
  gap: 2px;
  margin-left: -8px;
  padding: 6px 10px 6px 2px;
  border: 0;
  border-radius: 8px;
  background: none;
  font-size: 17px;
  cursor: pointer;
}

.back .icon {
  width: 22px;
  height: 22px;
}

.nav-top {
  display: none;
}

.time {
  margin-left: auto;
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  font-size: 15px;
  text-decoration: none;
  white-space: nowrap;
}

.time-value {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.time-unit {
  color: var(--text-2);
}

.is-locked .time-value {
  color: var(--text-3);
}

body[data-view="watch"] .page-title {
  display: none;
}

body[data-view="watch"] .back {
  display: inline-flex;
}

/* ------------------------------------------------------------------ layout */

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 4px calc(var(--gutter) + var(--safe-r)) calc(var(--tab-h) + var(--safe-b) + 32px)
    calc(var(--gutter) + var(--safe-l));
}

.tabbar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 0 var(--safe-r) var(--safe-b) var(--safe-l);
  border-top: 1px solid var(--separator);
  background: rgba(18, 18, 18, 0.84);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}

.tab {
  height: var(--tab-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-3);
  text-decoration: none;
}

.tab .icon {
  width: 24px;
  height: 24px;
}

.tab[aria-current="page"] {
  color: var(--text);
}

body[data-view="boot"] .tabbar,
body[data-view="watch"] .tabbar,
body[data-view="login"] .tabbar,
body[data-view="login"] .topbar {
  display: none;
}

.section-title {
  margin: 28px 0 12px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.label {
  font-size: 14px;
  color: var(--text-2);
}

/* ------------------------------------------------------------------ buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.btn .icon {
  width: 17px;
  height: 17px;
}

.btn-primary {
  background: var(--text);
  color: #000;
  font-weight: 600;
}

.btn-block {
  width: 100%;
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
}

@media (hover: hover) {
  .btn:hover {
    background: var(--fill);
  }
  .btn-primary:hover {
    background: rgba(255, 255, 255, 0.88);
  }
}

.spinner {
  width: 16px;
  height: 16px;
  flex: none;
  border: 2px solid var(--fill);
  border-top-color: var(--text-2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* One bar style everywhere: white on gray. */
.bar {
  position: relative;
  display: block;
  height: 4px;
  overflow: hidden;
  border-radius: 2px;
  background: var(--fill);
}

.bar > span {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--p, 0) * 100%);
  background: var(--text);
}

.bar--budget > span {
  width: calc(var(--budget) * 100%);
}

.is-locked .bar--budget > span {
  width: 0;
}

/* ------------------------------------------------------------------ VOD list */

.notice-locked {
  display: none;
}

.is-locked .notice-locked {
  display: block;
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 15px;
  color: var(--text-2);
}

.notice-locked strong {
  color: var(--text);
  font-weight: 600;
}

.continue-card {
  display: grid;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 24px 16px;
}

.card {
  display: block;
  color: inherit;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
}

.thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

img.is-missing {
  visibility: hidden;
}

.thumb-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.badge {
  position: absolute;
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.75);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
}

.badge--duration {
  right: 8px;
  bottom: 9px;
}

.badge--tag {
  top: 8px;
  left: 8px;
}

.thumb-progress {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.3);
}

.thumb-progress > span {
  display: block;
  width: max(3px, calc(var(--p) * 100%));
  height: 100%;
  background: var(--text);
}

.card-title {
  margin-top: 10px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-2);
}

.continue-card .card-title {
  margin-top: 0;
  font-size: 17px;
  font-weight: 600;
}

.continue-card .card-meta {
  font-size: 14px;
}

@media (hover: hover) {
  .card:hover .card-title,
  .continue-card:hover .card-title {
    color: var(--text-2);
  }
}

.card--skeleton .thumb {
  background: var(--surface);
}

.skel-line {
  width: 80%;
  height: 12px;
  margin-top: 12px;
  border-radius: 4px;
  background: var(--surface);
}

.skel-line--short {
  width: 35%;
  margin-top: 8px;
}

.grid-foot {
  margin-top: 28px;
}

.grid-foot:empty {
  display: none;
}

.foot-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-3);
}

.notice {
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 15px;
  color: var(--text-2);
}

.notice-title {
  margin-bottom: 2px;
  color: var(--text);
  font-weight: 600;
}

.notice .btn {
  margin-top: 14px;
  background: var(--fill);
}

.sentinel {
  height: 1px;
}

/* ------------------------------------------------------------------ watch */

body[data-view="watch"] main {
  padding: 0 0 calc(var(--safe-b) + 32px);
}

.watch {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-areas:
    "stage"
    "info"
    "side";
}

.watch-stage {
  grid-area: stage;
}

.watch-info {
  grid-area: info;
  padding: 16px calc(var(--gutter) + var(--safe-r)) 0 calc(var(--gutter) + var(--safe-l));
}

.watch-side {
  grid-area: side;
  padding: 0 calc(var(--gutter) + var(--safe-r)) 0 calc(var(--gutter) + var(--safe-l));
}

.player {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #000;
}

.player-slot,
.player-slot > * {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

.player-status {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #0e0e0f;
  text-align: center;
}

.status-loading {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  color: var(--text-2);
}

.status-msg {
  max-width: 34ch;
  display: grid;
  justify-items: center;
  gap: 4px;
  font-size: 14px;
  color: var(--text-2);
}

.status-title {
  color: var(--text);
  font-size: 17px;
  font-weight: 600;
}

.status-msg .btn {
  margin-top: 12px;
}

.watch-title {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.watch-date {
  margin-top: 4px;
  font-size: 14px;
  color: var(--text-2);
}

.panel {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--separator);
}

.panel-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 14px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.panel .bar {
  margin: 12px 0 10px;
}

.big-number {
  margin-top: 4px;
  font-size: 40px;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.big-number small {
  margin-left: 6px;
  font-size: 17px;
  font-weight: 400;
  letter-spacing: 0;
  color: var(--text-2);
}

.is-locked .budget .big-number {
  color: var(--text-3);
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.live::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-3);
}

.is-counting .live {
  color: var(--text);
}

.is-counting .live::before {
  background: var(--text);
}

.position .btn {
  margin-top: 16px;
}

/* ------------------------------------------------------------------ stats */

#view-stats {
  max-width: 820px;
}

.today .big-number {
  margin-top: 0;
}

.today .bar {
  margin: 12px 0 10px;
}

.when-locked {
  display: none;
}

.is-locked .when-locked {
  display: inline;
}

.is-locked .when-open {
  display: none;
}

.chart {
  position: relative;
}

.chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

.chart-placeholder {
  height: 180px;
  border-radius: var(--radius);
  background: var(--surface);
}

.chart-grid {
  stroke: var(--separator);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.chart-limit {
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.chart-axis,
.chart-limit-label {
  fill: var(--text-3);
  font-family: var(--font);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.chart-axis--today {
  fill: var(--text);
  font-weight: 600;
}

.chart-bar {
  fill: #5a5a5e;
}

.chart-bar--today {
  fill: var(--text);
}

.chart-hit {
  fill: transparent;
  outline: none;
}

.chart-hit:focus-visible {
  fill: rgba(255, 255, 255, 0.06);
}

.chart-tip {
  position: absolute;
  z-index: 3;
  display: grid;
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--fill);
  font-size: 12px;
  line-height: 1.3;
  color: var(--text-2);
  white-space: nowrap;
  transform: translate(-50%, -100%);
  pointer-events: none;
}

.chart-tip strong {
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.figures {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.figure {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--surface);
}

.figure-value {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.figure-label {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-2);
}

.recent-row {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  padding: 10px 0;
  color: inherit;
  text-decoration: none;
}

.recent-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 8px;
  background: var(--surface);
}

.recent-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.recent-title {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.recent-meta {
  margin-top: 2px;
  font-size: 13px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.recent-row .bar {
  height: 3px;
  margin-top: 8px;
}

.empty-note {
  font-size: 15px;
  color: var(--text-2);
}

/* ------------------------------------------------------------------ login */

body[data-view="login"] main {
  padding-bottom: 0;
}

.login {
  min-height: calc(100vh - 40px);
  min-height: calc(100dvh - 40px);
  max-width: 320px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 20px;
  border-radius: 14px;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.login-text {
  margin: 6px 0 20px;
  color: var(--text-2);
}

.field input {
  width: 100%;
  height: 50px;
  padding: 0 14px;
  border: 0;
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 17px;
}

.field input:focus {
  outline: 2px solid rgba(255, 255, 255, 0.5);
  outline-offset: 0;
}

.login-error {
  margin-top: 10px;
  font-size: 14px;
  color: #ff6961;
}

.login .btn {
  min-height: 50px;
  margin-top: 12px;
  font-size: 17px;
}

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  bottom: calc(var(--tab-h) + var(--safe-b) + 12px);
  left: 50%;
  z-index: 40;
  max-width: min(92vw, 420px);
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--fill);
  font-size: 14px;
  opacity: 0;
  transform: translateX(-50%);
  pointer-events: none;
  transition: opacity 0.2s;
}

.toast.is-visible {
  opacity: 1;
}

body[data-view="watch"] .toast {
  bottom: calc(var(--safe-b) + 16px);
}

/* ------------------------------------------------------------------ larger screens */

@media (min-width: 700px) {
  .continue-card {
    grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
    gap: 24px;
    align-items: center;
  }

  .continue-card .card-title {
    font-size: 20px;
  }

  .figures {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

@media (min-width: 900px) {
  :root {
    --gutter: 32px;
  }

  main {
    padding-bottom: 64px;
  }

  .tabbar,
  .page-title,
  body[data-view="watch"] .back {
    display: none;
  }

  .nav-top {
    display: flex;
    gap: 22px;
  }

  .nav-top a {
    font-size: 17px;
    font-weight: 600;
    color: var(--text-3);
    text-decoration: none;
  }

  .nav-top a[aria-current="page"] {
    color: var(--text);
  }

  .toast,
  body[data-view="watch"] .toast {
    bottom: 24px;
  }
}

@media (min-width: 900px) and (hover: hover) {
  .nav-top a:hover {
    color: var(--text);
  }
}

@media (min-width: 1040px) {
  body[data-view="watch"] main {
    padding: 24px calc(var(--gutter) + var(--safe-r)) 56px calc(var(--gutter) + var(--safe-l));
  }

  .watch {
    grid-template-columns: minmax(0, 1fr) 320px;
    grid-template-areas:
      "stage side"
      "info side";
    column-gap: 32px;
    align-items: start;
  }

  .player {
    border-radius: var(--radius);
  }

  .watch-info,
  .watch-side {
    padding: 0;
  }

  .watch-info {
    padding-top: 16px;
  }

  .watch-title {
    font-size: 20px;
  }

  .watch-side > .panel:first-child {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
  }
}

@media (min-width: 1100px) {
  #view-stats:not([hidden]) {
    max-width: none;
    display: grid;
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    grid-template-areas:
      "today recent"
      "history recent"
      "figures recent";
    column-gap: 56px;
    align-items: start;
  }

  .today {
    grid-area: today;
  }

  .history {
    grid-area: history;
  }

  .figures-section {
    grid-area: figures;
  }

  .recent {
    grid-area: recent;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2s;
  }
}
