:root {
  --bg: #111214;
  --panel: #1a1c1f;
  --panel-2: #24272b;
  --border: #2c3036;
  --text: #e9ecef;
  --muted: #8d939a;
  --accent: #c00000;
  --accent-soft: #3a1212;
  --ok: #3fb950;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 16px;
  overflow-x: hidden;
  width: 100%;
}

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 0.9rem 1.1rem;
  border-radius: 10px;
  font-weight: 600;
  min-height: 48px; /* mobile tap target */
}
button.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
button:disabled { opacity: 0.5; cursor: not-allowed; }

.muted { color: var(--muted); }

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

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
}
.login-card {
  width: 100%;
  max-width: min(420px, calc(100vw - 2rem));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.5rem 1.5rem;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  margin: 0 auto;
}
.brand { margin-bottom: 2rem; }
.brand-mark {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  letter-spacing: 3px;
  padding: 0.7rem 1.3rem;
  border-radius: 10px;
  font-size: 2rem;
}
.brand-mark.small {
  padding: 0.35rem 0.7rem;
  font-size: 1.1rem;
  letter-spacing: 2px;
  border-radius: 7px;
}
.brand-sub {
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 500;
  margin-top: 1.1rem;
}
.brand-tag {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.3rem;
}

#login-form { display: grid; gap: 1.1rem; }
#login-form > * { min-width: 0; }
#login-form label {
  text-align: center;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.5px;
}
#login-form input {
  font: inherit;
  font-size: 1.75rem;
  letter-spacing: 0.4rem;
  text-align: center;
  padding: 0.9rem 0.5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  min-height: 60px;
  width: 100%;
}
#login-form input:focus {
  outline: none;
  border-color: var(--accent);
}
#login-form button {
  font-size: 1.05rem;
  padding: 1rem;
  min-height: 54px;
}
.error { color: #ff6b6b; margin: 0; font-size: 0.95rem; }
.login-foot {
  margin-top: 1.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.5;
}

/* ---------- app page — topbar ---------- */

.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}
.brand-row > div:last-child { min-width: 0; }
.topbar-title {
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-sub {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}
.topbar-actions a,
.topbar-actions button {
  color: var(--muted);
  text-decoration: none;
  padding: 0.55rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: transparent;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}

@media (max-width: 500px) {
  .topbar-inner { padding: 0.6rem 0.75rem; gap: 0.5rem; }
  .topbar-sub { font-size: 0.75rem; }
  .topbar-actions a,
  .topbar-actions button {
    padding: 0.45rem 0.65rem;
    font-size: 0.8rem;
    min-height: 36px;
  }
}

/* ---------- episode grid ---------- */

.episode-main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem;
  padding-bottom: 160px;
}

.part-section { margin: 1.75rem 0; }
.part-header {
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 2px;
  text-transform: uppercase;
  margin: 0 0 0.4rem;
  font-weight: 600;
}
.part-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 1rem;
}

.episode-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.85rem;
}

@media (max-width: 560px) {
  .episode-grid { grid-template-columns: 1fr; gap: 0.7rem; }
  .part-section { margin: 1.25rem 0; }
  .part-title { font-size: 1.15rem; }
}

.episode-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.episode-card.unavailable { opacity: 0.55; }

.episode-number {
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 1.5px;
  font-weight: 600;
  text-transform: uppercase;
}
.episode-title { font-weight: 600; line-height: 1.3; font-size: 1.02rem; }
.episode-actions { display: flex; gap: 0.5rem; margin-top: auto; }
.episode-actions button {
  flex: 1;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.7rem 0.5rem;
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  border-radius: 8px;
}
.episode-actions button:hover:not(:disabled) { border-color: var(--accent); }
.episode-actions button.playing { background: var(--accent); border-color: var(--accent); color: #fff; }

.progress-bar {
  height: 3px;
  background: var(--panel-2);
  border-radius: 2px;
  overflow: hidden;
}
.progress-fill { height: 100%; background: var(--accent); transition: width 0.3s ease; }
.progress-fill.done { background: var(--ok); }

.tick { color: var(--ok); font-weight: 700; }

/* ---------- player dock ---------- */

.player-dock {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 0.75rem 1rem calc(0.75rem + env(safe-area-inset-bottom));
  display: flex;
  gap: 1rem;
  align-items: center;
  z-index: 10;
}
.player-meta { flex: 0 0 auto; min-width: 0; max-width: 260px; }
.player-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-sub { color: var(--muted); font-size: 0.8rem; }
#audio { flex: 1; min-width: 0; height: 40px; }
.player-dock #player-close {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.4rem;
  line-height: 1;
  min-height: 40px;
  border-radius: 8px;
}

@media (max-width: 640px) {
  .player-dock {
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    padding: 0.6rem 0.75rem calc(0.6rem + env(safe-area-inset-bottom));
  }
  .player-meta {
    flex: 1 1 calc(100% - 48px);
    max-width: none;
    order: 1;
  }
  .player-dock #player-close { order: 2; }
  #audio {
    flex: 1 1 100%;
    order: 3;
    height: 36px;
  }
  .player-title { font-size: 0.95rem; }
  .player-sub { font-size: 0.75rem; }
}

/* ---------- admin ---------- */

.admin-main { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.matrix { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.matrix th, .matrix td { border: 1px solid var(--border); padding: 0.4rem 0.6rem; text-align: center; }
.matrix th { background: var(--panel); position: sticky; top: 0; }
.matrix td.name { text-align: left; font-weight: 600; }
.matrix .c-done { background: var(--accent-soft); color: var(--ok); font-weight: 700; }
.matrix .c-part { background: var(--panel-2); color: var(--text); }
.matrix .c-none { color: var(--muted); }

.admin-section { margin: 2rem 0; }
.admin-section h2 { margin: 0 0 1rem; font-size: 1.1rem; }
