:root {
  --bg: #f6f1e8;
  --surface: #fffaf1;
  --ink: #1f1c18;
  --muted: #6f665d;
  --accent: #ff5e2e;
  --accent-2: #ff9c2a;
  --line: #eadfce;
  --shadow: 0 10px 35px rgba(93, 67, 34, 0.12);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 10%, #fff6e2 0%, var(--bg) 48%, #f0e5d7 100%);
  color: var(--ink);
  font-family: "Space Grotesk", sans-serif;
  overflow-x: hidden;
}

body[data-theme="dark"] {
  --bg: #15171b;
  --surface: #1d2128;
  --ink: #eceef3;
  --muted: #aeb3bf;
  --line: #2d3440;
  --shadow: 0 10px 35px rgba(0, 0, 0, 0.35);
  background: radial-gradient(circle at 20% 10%, #232834 0%, #15171b 56%, #111319 100%);
}

body[data-theme="dark"] .topbar {
  background: rgba(21, 23, 27, 0.9);
}

body[data-theme="dark"] .search-wrap,
body[data-theme="dark"] .menu-toggle,
body[data-theme="dark"] .chip,
body[data-theme="dark"] .card,
body[data-theme="dark"] .card-menu,
body[data-theme="dark"] .card-menu-trigger,
body[data-theme="dark"] .close-btn,
body[data-theme="dark"] .sidebar,
body[data-theme="dark"] .player-dialog,
body[data-theme="dark"] .upload-dialog,
body[data-theme="dark"] .short-nav,
body[data-theme="dark"] .upload-form input {
  background: #1d2128;
  color: var(--ink);
  border-color: var(--line);
}

body[data-theme="dark"] .search-wrap button,
body[data-theme="dark"] .upload-submit {
  background: #0f1116;
}

body[data-theme="dark"] .nav-item:hover {
  background: #232835;
}

body[data-theme="dark"] .nav-item.active {
  background: #283247;
}

body[data-theme="dark"] .card-menu button:hover {
  background: #232835;
}

.bg-shape {
  position: fixed;
  z-index: -1;
  border-radius: 999px;
  filter: blur(20px);
  opacity: 0.55;
}

.bg-shape-a {
  width: 380px;
  height: 380px;
  background: #ffd6a5;
  top: -120px;
  right: -120px;
}

.bg-shape-b {
  width: 280px;
  height: 280px;
  background: #ffc79a;
  left: -100px;
  bottom: -80px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(180px, 680px) auto;
  gap: 14px;
  align-items: center;
  padding: 14px 20px;
  backdrop-filter: blur(6px);
  background: rgba(246, 241, 232, 0.9);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: url("/favicon-light.ico") center / cover no-repeat;
  color: transparent;
  font-size: 0;
  display: grid;
  place-items: center;
  font-family: "Archivo Black", sans-serif;
  box-shadow: var(--shadow);
}

body[data-theme="dark"] .brand-logo {
  background-image: url("/favicon.ico");
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1;
}

.brand-main {
  font-weight: 700;
  letter-spacing: 0.04em;
}

.brand-sub {
  color: var(--muted);
  font-size: 0.88rem;
}

.search-wrap {
  display: flex;
  align-items: center;
  background: white;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
}

.search-wrap input {
  width: 100%;
  border: 0;
  outline: none;
  padding: 13px 16px;
  background: transparent;
  font: inherit;
}

.search-wrap button {
  border: 0;
  padding: 12px 16px;
  background: var(--ink);
  color: white;
  cursor: pointer;
  font: inherit;
}

.menu-toggle {
  border: 1px solid var(--line);
  background: white;
  border-radius: 12px;
  padding: 8px 10px;
  font-size: 1.1rem;
  cursor: pointer;
  display: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.theme-toggle {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.upload-btn {
  border: 1px solid transparent;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 22px;
  padding: 18px 20px 32px;
}

.sidebar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  align-self: start;
  position: sticky;
  top: 84px;
}

.nav-item {
  display: block;
  text-decoration: none;
  color: var(--ink);
  padding: 11px 12px;
  border-radius: 12px;
  margin-bottom: 6px;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.nav-item:hover {
  background: #fff3df;
  transform: translateX(2px);
}

.nav-item.active {
  background: #ffe3c4;
  font-weight: 700;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.chip {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
  font: inherit;
}

.chip.active {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}

.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.card {
  border: 1px solid var(--line);
  background: white;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 3px 14px rgba(110, 81, 46, 0.08);
  cursor: pointer;
  position: relative;
  transform: translateY(10px);
  opacity: 0;
  animation: rise 0.45s ease forwards;
}

.card:hover {
  box-shadow: var(--shadow);
}

.thumb {
  aspect-ratio: 16 / 9;
  width: 100%;
  object-fit: cover;
  display: block;
}

.card-body {
  padding: 12px 12px 14px;
}

.card-title {
  margin: 0 0 8px;
  font-size: 1rem;
  line-height: 1.35;
}

.card-meta {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.card-menu-wrap {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 5;
}

.card-menu-trigger {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
  border-radius: 10px;
  width: 34px;
  height: 30px;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}

.card-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 34px;
  min-width: 170px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
  box-shadow: var(--shadow);
}

.card-menu.open {
  display: grid;
}

.card-menu button {
  border: 0;
  background: transparent;
  color: var(--ink);
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}

.card-menu button:hover {
  background: #fff3df;
}

.card-menu .danger {
  color: #c43e20;
}

.player-dialog {
  width: min(920px, calc(100% - 26px));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 0;
  background: #fffdf7;
}

.player-dialog::backdrop {
  background: rgba(26, 22, 16, 0.5);
  backdrop-filter: blur(2px);
}

.dialog-head {
  display: flex;
  justify-content: flex-end;
  padding: 8px;
}

.close-btn {
  border: 1px solid var(--line);
  background: white;
  border-radius: 10px;
  width: 34px;
  height: 34px;
  cursor: pointer;
}

.player-shell {
  padding: 0 14px 16px;
}

.iframe-wrap {
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--line);
  position: relative;
}

#playerVideo {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
}

.custom-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: #1f1c18;
}

#playerViewport:fullscreen {
  border: 0;
  border-radius: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
}

#playerViewport:fullscreen #playerVideo {
  width: 100vw;
  height: 100vh;
  aspect-ratio: auto;
  object-fit: contain;
}

#playerViewport:fullscreen .custom-controls {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 68px;
  z-index: 7;
  padding: 8px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.45);
}

#playerViewport:fullscreen .volume {
  display: none;
}

.player-fs .custom-controls {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 68px;
  z-index: 7;
  padding: 8px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.45);
}

.player-fs .volume {
  display: none;
}

.control-btn {
  border: 1px solid #444;
  background: #2d2924;
  color: #fff;
  border-radius: 10px;
  padding: 6px 10px;
  cursor: pointer;
  min-width: 42px;
}

.seek {
  width: 100%;
}

.time-label {
  color: #f4ede3;
  font-size: 0.85rem;
  min-width: 78px;
  text-align: center;
}

.volume {
  width: 84px;
}

#playerTitle {
  margin: 12px 0 6px;
  font-size: 1.2rem;
}

#playerMeta {
  margin: 0;
  color: var(--muted);
}

.upload-dialog {
  width: min(540px, calc(100% - 26px));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 0;
  background: #fffdf7;
}

.upload-dialog::backdrop {
  background: rgba(26, 22, 16, 0.5);
}

.upload-form {
  display: grid;
  gap: 12px;
  padding: 0 16px 16px;
}

.upload-form h2 {
  margin: 0 0 4px;
}

.upload-form label {
  display: grid;
  gap: 6px;
  font-weight: 500;
}

.check-row,
.short-flag {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.3;
}

.check-row input[type="checkbox"],
.short-flag input[type="checkbox"] {
  margin: 0;
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
}

.upload-form input {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 11px;
  font: inherit;
}

.upload-submit {
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  font: inherit;
  cursor: pointer;
}

.upload-status {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.local-thumb {
  aspect-ratio: 16 / 9;
  display: grid;
  place-items: center;
  font-family: "Archivo Black", sans-serif;
  font-size: 1.2rem;
  color: #fff;
  background: linear-gradient(135deg, #ff6f3d, #e23d1c 55%, #8f2e13);
}

.watch-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  padding: 18px 20px 28px;
}

.watch-page {
  height: 100vh;
  overflow: hidden;
}

.watch-page .watch-layout {
  height: calc(100vh - 86px);
  overflow: hidden;
}

.watch-main {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 10px;
}

.watch-player-wrap {
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  background: #000;
  min-height: 0;
}

#watchVideo {
  width: 100%;
  height: 100%;
  min-height: 220px;
  max-height: calc(100vh - 220px);
  background: #000;
  display: block;
  object-fit: contain;
}

.watch-title {
  margin: 0;
  font-size: 1.24rem;
  line-height: 1.35;
}

.watch-meta {
  margin: 0;
  color: var(--muted);
}

.watch-sidebar {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 12px;
  align-self: start;
  position: sticky;
  top: 86px;
  max-height: calc(100vh - 110px);
  overflow: hidden;
}

.watch-side-title {
  margin: 0 0 10px;
  font-size: 1rem;
}

.watch-list {
  display: grid;
  gap: 10px;
  overflow-y: auto;
  max-height: calc(100vh - 170px);
  padding-right: 4px;
}

.watch-item {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr);
  gap: 10px;
  text-decoration: none;
  color: inherit;
}

.watch-item-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 10px;
  display: block;
  border: 1px solid var(--line);
}

.watch-item-fallback {
  display: grid;
  place-items: center;
  font-family: "Archivo Black", sans-serif;
  font-size: 0.86rem;
  color: #fff;
  background: linear-gradient(135deg, #ff6f3d, #e23d1c 55%, #8f2e13);
}

.watch-item-body {
  display: grid;
  gap: 4px;
  align-content: start;
}

.watch-item-title {
  font-size: 0.92rem;
  line-height: 1.3;
}

.watch-item-meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.watch-empty {
  margin: 0;
  color: var(--muted);
}

.watch-back-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  justify-content: center;
  padding: 6px 10px;
  z-index: 2;
}

.watch-home-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 110px;
  padding: 9px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  line-height: 1;
  box-shadow: none;
}

.watch-home-btn:hover {
  background: var(--surface);
}

.watch-home-btn:active {
  transform: translateY(1px);
}

.watch-page .topbar {
  grid-template-columns: auto;
}

.shorts-page {
  height: 100vh;
  overflow: hidden;
}

.shorts-topbar {
  position: fixed;
  width: 100%;
}

.shorts-main {
  height: 100vh;
  padding-top: 72px;
  position: relative;
}

.shorts-feed {
  height: 100%;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
}

.short-feed-card {
  height: calc(100vh - 72px);
  display: grid;
  place-items: center;
  scroll-snap-align: start;
  padding: 14px;
}

.short-feed-media {
  width: min(420px, 100%);
  height: 100%;
  max-height: calc(100vh - 120px);
  border-radius: 20px;
  border: 1px solid var(--line);
  overflow: hidden;
  background-size: cover;
  background-position: center;
  background-color: #131313;
  position: relative;
  display: grid;
}

.short-feed-fallback {
  background-image: linear-gradient(165deg, #ff7a35, #cd3517 60%, #71230f);
}

.short-feed-video {
  width: 100%;
  height: 100%;
  border: 0;
  background: rgba(0, 0, 0, 0.25);
  object-fit: cover;
}

.short-custom-controls {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 68px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.45);
}

.short-feed-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px 14px;
  color: #fff;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.62) 70%);
}

.short-feed-overlay h2 {
  margin: 0 0 6px;
  font-size: 1rem;
}

.short-feed-overlay p {
  margin: 0;
  font-size: 0.9rem;
  opacity: 0.9;
}

.short-nav {
  position: fixed;
  right: 20px;
  z-index: 30;
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 1.3rem;
  cursor: pointer;
}

.short-nav-up {
  top: calc(50% - 54px);
}

.short-nav-down {
  top: calc(50% + 8px);
}

.shorts-empty {
  text-align: center;
  padding-top: 80px;
}

@keyframes rise {
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (max-width: 920px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: 10px;
    padding: 10px 12px;
  }

  .brand {
    grid-column: 1 / 2;
  }

  .brand-logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
  }

  .search-wrap {
    grid-column: 1 / 2;
    order: 3;
    width: 100%;
  }

  .menu-toggle {
    display: block;
  }

  .topbar-actions {
    gap: 6px;
  }

  .theme-toggle,
  .upload-btn,
  .menu-toggle {
    padding: 8px 10px;
    border-radius: 10px;
    font-size: 0.92rem;
  }

  .layout {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }

  .sidebar {
    position: fixed;
    top: 66px;
    right: 10px;
    width: min(78vw, 320px);
    max-height: calc(100vh - 78px);
    overflow-y: auto;
    display: block;
    z-index: 40;
    transform: translateX(120%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .chip-row {
    margin-bottom: 12px;
  }

  .video-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .player-dialog {
    width: calc(100% - 10px);
    border-radius: 14px;
  }

  .player-shell {
    padding: 0 8px 10px;
  }

  .custom-controls {
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
  }

  .control-btn {
    min-width: 38px;
    padding: 6px 8px;
  }

  .time-label {
    min-width: 68px;
    font-size: 0.8rem;
  }

  .volume {
    width: 100%;
  }

  .upload-dialog {
    width: calc(100% - 10px);
    border-radius: 14px;
  }

  .upload-form {
    padding: 0 10px 10px;
  }

  .watch-layout {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
    height: calc(100vh - 66px);
  }

  .watch-page .topbar {
    grid-template-columns: 1fr;
  }

  .watch-page .brand {
    justify-self: start;
  }

  .watch-back-wrap {
    position: static;
    transform: none;
    padding-left: 0;
  }

  #watchVideo {
    max-height: calc(100vh - 280px);
  }

  .watch-sidebar {
    position: static;
    max-height: none;
  }

  .watch-item {
    grid-template-columns: 140px minmax(0, 1fr);
  }

  .watch-list {
    max-height: 28vh;
  }

  .shorts-main {
    padding-top: 64px;
  }

  .short-feed-card {
    height: calc(100vh - 64px);
    padding: 6px;
  }

  .short-feed-media {
    width: min(100%, 420px);
    max-height: calc(100vh - 86px);
    border-radius: 14px;
  }

  .short-custom-controls {
    left: 8px;
    right: 8px;
    bottom: 62px;
    padding: 6px;
    gap: 6px;
  }

  .short-feed-overlay {
    padding: 12px 10px;
  }

  .short-nav {
    width: 40px;
    height: 40px;
    right: 10px;
    font-size: 1.1rem;
  }
}

@media (max-width: 560px) {
  .brand-main {
    font-size: 0.95rem;
  }

  .brand-sub {
    font-size: 0.78rem;
  }

  .theme-toggle,
  .upload-btn {
    font-size: 0.82rem;
    padding: 7px 8px;
  }

  .search-wrap input {
    padding: 10px 12px;
  }

  .search-wrap button {
    padding: 10px 12px;
  }

  .chip {
    padding: 7px 10px;
    font-size: 0.88rem;
  }

  .card-title {
    font-size: 0.95rem;
  }

  .card-meta {
    font-size: 0.84rem;
  }

  .short-feed-overlay h2 {
    font-size: 0.92rem;
  }

  .short-feed-overlay p {
    font-size: 0.82rem;
  }
}
