:root {
  --bg: #ffffff;
  --bg-soft: #f5f6f8;
  --bg-tint: #eef1f6;
  --text: #0f1216;
  --muted: #6b7280;
  --line: #e3e6ea;
  --accent: #111827;
  --accent-2: #d92027;
  --accent-tint: #fdecec;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Barlow', 'Helvetica Neue', Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overscroll-behavior-y: contain;
}

button, input { font: inherit; }

/* Screens */
.screen { display: none; flex: 1; }
.screen.active { display: flex; flex-direction: column; }

/* ================= Login screen ================= */
#loginScreen.active {
  align-items: center;
  justify-content: space-between;
  padding: calc(28px + var(--safe-top)) 20px calc(20px + var(--safe-bottom));
  min-height: 100vh;
  background:
    radial-gradient(circle at 15% 0%, #fdecec 0, transparent 55%),
    radial-gradient(circle at 90% 100%, #eef1f6 0, transparent 55%),
    #ffffff;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 40px 28px 32px;
  text-align: center;
  margin: auto 0;
  box-shadow: 0 20px 40px -25px rgba(15,18,22,0.15);
}

.brand-mark {
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
  margin-bottom: 18px;
  font-family: 'Barlow Condensed', 'Barlow', sans-serif;
  font-weight: 800;
  letter-spacing: -1px;
}
.brand-mark-w { font-size: 46px; color: var(--accent); }
.brand-mark-4 {
  font-size: 46px;
  color: var(--accent-2);
  margin: 0 2px;
}
.brand-mark-u { font-size: 46px; color: var(--accent); }

.login-card h1 {
  font-family: 'Barlow Condensed', 'Barlow', sans-serif;
  font-weight: 800;
  font-size: 30px;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 6px;
  color: var(--accent);
}
.login-sub {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 26px;
  line-height: 1.5;
}

#googleBlock { display: none; margin: 6px 0; }
#googleSignInDiv { display: flex; justify-content: center; }

.notice-box {
  background: var(--bg-soft);
  border: 1px dashed var(--line);
  border-radius: 10px;
  padding: 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.login-note {
  margin-top: 22px;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.2px;
}

.login-footer, .app-footer {
  text-align: center;
  padding: 18px 10px calc(16px + var(--safe-bottom));
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.4px;
}
.login-footer { border-top: 1px solid var(--line); width: 100%; max-width: 640px; margin-top: 24px; }
.app-footer { border-top: 1px solid var(--line); background: #fff; }
.footer-strong { font-weight: 700; color: var(--accent); letter-spacing: 0.6px; }
.footer-partner { font-weight: 600; color: var(--accent-2); }

/* ================= App shell ================= */
#appScreen.active { min-height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 20px 14px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(10px);
  z-index: 10;
}

.topbar .user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 4px 8px 4px 4px;
  border-radius: 10px;
  transition: background .15s ease;
}
.topbar .user-info:hover { background: var(--bg-soft); }
.topbar .user-info:active { background: var(--bg-tint); }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-tint);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--line);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.user-meta { text-align: left; line-height: 1.2; }
.user-meta .name {
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
}
.user-meta .email {
  font-size: 11px;
  color: var(--muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-btn {
  background: none;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  letter-spacing: 0.3px;
}
.logout-btn:hover { border-color: var(--accent); }
.logout-btn:active { background: var(--bg-soft); }

/* Profile drawer */
.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,18,22,0.45);
  z-index: 40;
}
.drawer-backdrop.show { display: block; }
.profile-drawer {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 100%;
  max-width: 340px;
  background: #fff;
  border-left: 1px solid var(--line);
  transform: translateX(100%);
  transition: transform .25s ease;
  z-index: 50;
  overflow-y: auto;
}
.profile-drawer.open { transform: translateX(0); }
.drawer-inner {
  padding: calc(28px + var(--safe-top)) 24px 28px;
  text-align: center;
}
.drawer-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  margin: 0 auto 16px;
  background: var(--bg-tint);
  border: 1px solid var(--line);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-weight: 700;
  font-size: 30px;
}
.drawer-avatar img { width: 100%; height: 100%; object-fit: cover; }
.drawer-name {
  font-family: 'Barlow Condensed', 'Barlow', sans-serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.drawer-email { color: var(--muted); font-size: 13px; margin-bottom: 6px; word-break: break-all; }
.drawer-last { color: var(--muted); font-size: 12px; margin-bottom: 22px; }

.upload-photo-btn {
  display: inline-block;
  border: 1px solid var(--line);
  padding: 10px 18px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  transition: border-color .15s ease, background .15s ease;
}
.upload-photo-btn:hover { border-color: var(--accent); background: var(--bg-soft); }
.photo-status { font-size: 12px; color: var(--muted); margin-top: 10px; min-height: 16px; }

.drawer-close {
  margin-top: 26px;
  width: 100%;
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
  letter-spacing: 0.4px;
}
.drawer-close:hover { background: var(--accent-2); }

.container {
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 20px 20px;
  flex: 1;
}

header.hero { margin-bottom: 24px; }
header.hero h1 {
  font-family: 'Barlow Condensed', 'Barlow', sans-serif;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--accent);
}
header.hero p { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* Category grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
}

.tile {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 18px;
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
  -webkit-user-select: none;
  user-select: none;
  position: relative;
  overflow: hidden;
}
.tile::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--accent-2);
  transform: scaleY(0.4);
  transform-origin: center;
  transition: transform .2s ease;
}
.tile:hover::before { transform: scaleY(1); }
.tile:hover { transform: translateY(-2px); border-color: var(--accent); }
.tile:active { transform: scale(.98); background: var(--bg-soft); }
.tile .name {
  font-family: 'Barlow Condensed', 'Barlow', sans-serif;
  font-weight: 800;
  font-size: 22px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--accent);
  line-height: 1.1;
}
.tile .count { color: var(--muted); font-size: 12px; margin-top: 6px; font-weight: 500; }

/* Category page */
.page { display: none; }
.page.active { display: block; }

.back-btn {
  display: inline-flex;
  align-items: center;
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 20px;
  padding: 8px 0;
  letter-spacing: 0.3px;
}
.back-btn:hover { color: var(--accent-2); }

.page-title {
  font-family: 'Barlow Condensed', 'Barlow', sans-serif;
  font-size: 28px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 18px;
  border-bottom: 3px solid var(--accent-2);
  padding-bottom: 10px;
  display: inline-block;
}

.video-list { border-top: 1px solid var(--line); }

.video-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 4px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  min-height: 56px;
  transition: background .12s ease;
}
.video-item:hover { background: var(--bg-soft); }
.video-item:active { background: var(--bg-tint); }
.video-item .left { display: flex; align-items: center; gap: 14px; }
.video-item .num {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: 'Barlow Condensed', sans-serif;
}
.video-item .title { font-size: 15px; font-weight: 500; color: var(--accent); }
.video-item .arrow { color: var(--muted); font-size: 16px; font-weight: 600; }

.empty-msg, .loading-msg {
  color: var(--muted);
  font-size: 14px;
  padding: 30px 4px;
  text-align: center;
  grid-column: 1 / -1;
}

/* Player */
.player {
  display: none;
  margin-top: 18px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.player.show { display: block; }

video {
  width: 100%;
  border-radius: 10px;
  background: #000;
  display: block;
  max-height: 70vh;
}

.nav {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
  gap: 10px;
}
.nav button {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  letter-spacing: 0.3px;
}
.nav button:hover:not(:disabled) { background: var(--accent-2); border-color: var(--accent-2); }
.nav button:disabled {
  background: var(--bg-tint);
  color: var(--muted);
  border-color: var(--line);
  cursor: not-allowed;
}

/* Small screens */
@media (max-width: 480px) {
  .container { padding: 22px 16px 16px; }
  header.hero h1 { font-size: 26px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tile { padding: 18px 14px; }
  .tile .name { font-size: 18px; }
  .login-card { padding: 32px 22px 26px; }
  .user-meta .email { max-width: 130px; }
  .user-meta .name { font-size: 13px; }
  .logout-btn { padding: 8px 12px; font-size: 12px; }
  .brand-mark-w, .brand-mark-4, .brand-mark-u { font-size: 40px; }
  .login-card h1 { font-size: 26px; }
}
