:root {
  --bg: #0d0820;
  --bg2: #1a0f33;
  --panel: #150a24;
  --text: #f1eaff;
  --muted: #a898c8;
  --line: #2e1f4d;
  --special: #3ec6f5;
  --ppm: 1.7px; /* pixels per minute in the timetable */
  --axis: 38px;
}

@media (min-width: 700px) {
  :root { --ppm: 2.1px; --axis: 50px; }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: radial-gradient(ellipse at 50% 120%, #3b1a6b 0%, var(--bg2) 45%, var(--bg) 100%) fixed;
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Poppins', system-ui, sans-serif;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px calc(130px + env(safe-area-inset-bottom));
}

.top { padding: 22px 0 8px; }
.top h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: 0.5px; }
.top p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* Timetable */
.timetable { margin-top: 18px; }

.stage-heads {
  position: sticky; top: 0; z-index: 5;
  display: grid; grid-template-columns: var(--axis) repeat(3, 1fr); gap: 4px;
  padding: 8px 0; background: var(--bg);
}
.stage-head { text-align: center; line-height: 1.1; }
.stage-head b { display: block; font-size: 14px; font-weight: 800; color: var(--c); }
.stage-head span { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.grid {
  position: relative;
  display: grid; grid-template-columns: var(--axis) repeat(3, 1fr); gap: 4px;
}
.axis, .col { position: relative; height: calc(var(--span) * var(--ppm)); }
.axis span {
  position: absolute; right: 6px; transform: translateY(-50%);
  font-size: 11px; font-weight: 600; color: var(--muted);
}
.axis span.half { font-size: 9px; opacity: 0.6; }
.col { border-left: 1px solid var(--line); }
.col::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(to bottom, var(--line) 0 1px, transparent 1px calc(30 * var(--ppm)));
  opacity: 0.6;
}

.set {
  position: absolute; left: 4px; right: 4px;
  top: calc(var(--s) * var(--ppm) + 1.5px);
  height: calc(var(--d) * var(--ppm) - 3px);
  font: inherit; text-align: left; color: var(--text);
  background: rgba(21, 10, 36, 0.92);
  border: 2px solid color-mix(in srgb, var(--c) 55%, transparent);
  border-radius: 6px; padding: 3px 6px;
  overflow: hidden; cursor: pointer;
  display: flex; flex-direction: column; justify-content: center;
  transition: background 0.12s, transform 0.08s;
}
.set:active { transform: scale(0.97); }
.set .n { font-size: 11px; font-weight: 800; line-height: 1.15; overflow-wrap: normal; }
.set .n small { font-weight: 600; font-size: 9px; opacity: 0.8; }
.set .t { font-size: 10px; font-weight: 600; color: var(--muted); }
.set .sub { font-size: 9px; color: var(--muted); font-style: italic; }
.set.short { flex-direction: row; align-items: center; gap: 6px; padding: 0 6px; }
.set.short .n { font-size: 9px; white-space: nowrap; }
.set.short .t, .set.short .sub { display: none; }
.set.tiny .sub { display: none; }

.set.on { background: var(--c); border-color: var(--c); color: var(--t); }
.set.on .t, .set.on .sub { color: inherit; opacity: 0.85; }


@media (min-width: 700px) {
  .set .n { font-size: 13px; }
  .set .t { font-size: 11px; }
  .set .sub { font-size: 10px; }
  .set.short .n { font-size: 10px; }
  .stage-head b { font-size: 18px; }
}

.footnote { color: var(--muted); font-size: 11px; text-align: center; margin: 24px 0 0; }

.socials { display: flex; justify-content: center; gap: 10px; margin: 4px 0 0; }
.socials a {
  display: inline-flex; align-items: center; gap: 4px;
  color: var(--muted); text-decoration: none; font-size: 10px; font-weight: 500;
}
.socials a:hover { color: #ff2bd6; }
.socials svg { width: 10px; height: 10px; }

/* Bottom bar */
.bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: rgba(13, 8, 32, 0.94); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.bar-row { max-width: 868px; margin: 0 auto; display: flex; align-items: center; gap: 10px; }
.count { flex: 1; font-weight: 600; font-size: 14px; }
.clash {
  max-width: 868px; margin: 0 auto 8px;
  font-size: 11px; line-height: 1.35; color: #ffd66b;
  background: rgba(245, 197, 24, 0.1); border: 1px solid rgba(245, 197, 24, 0.4);
  border-radius: 8px; padding: 6px 10px;
}

.btn {
  font: inherit; font-weight: 700; font-size: 15px;
  border-radius: 10px; padding: 10px 18px; cursor: pointer; border: 2px solid transparent;
}
.btn.primary { background: linear-gradient(90deg, #a53dff, #ff2bd6); color: #fff; }
.btn.primary:disabled { opacity: 0.35; cursor: default; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }

/* Preview modal */
.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(5, 2, 12, 0.88);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal[hidden] { display: none; }
.modal-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; max-height: 100%; }
.modal img {
  max-height: 72vh; max-width: 100%;
  border-radius: 18px; border: 1px solid var(--line);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}
.hint { margin: 0; color: var(--muted); font-size: 12px; text-align: center; max-width: 320px; }
.modal-actions { display: flex; gap: 10px; }
