:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --text: #1f2733;
  --text-muted: #6b7685;
  --border: #e3e7ee;
  --header-bg: #22303f;
  --header-text: #ffffff;
  --hour-bg: #eef1f6;
  --radius: 14px;
  --shadow: 0 2px 8px rgba(20, 25, 35, 0.06);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.top-bar {
  background: var(--bg);
  position: relative;
  isolation: isolate;
}

.top-bar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: clamp(10px, 3vw, 28px) clamp(10px, 3vw, 28px) 0;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 14px clamp(10px, 3vw, 28px) clamp(10px, 3vw, 28px);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.page-header h1 {
  font-size: clamp(1.1rem, 3vw, 1.6rem);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-header .class-name {
  background: linear-gradient(135deg, #4A90D9, #9013FE);
  color: #ffffff;
  font-weight: 700;
  font-size: clamp(0.85rem, 2.2vw, 1rem);
  padding: 7px 16px;
  border-radius: 999px;
  letter-spacing: 0.02em;
  box-shadow: 0 3px 10px rgba(74, 144, 217, 0.35);
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding-bottom: 12px;
}

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

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.legend-dot.past { background: #b7bfc9; }
.legend-dot.current { background: #ffffff; border: 3px solid #2ecc71; }
.legend-dot.future { background: linear-gradient(135deg,#4A90D9,#9013FE); }

@media (max-width: 700px) {
  .top-bar {
    position: sticky;
    top: 0;
    z-index: 60;
    box-shadow: 0 4px 12px rgba(20, 25, 35, 0.10);
  }
  .top-bar-inner {
    padding: 10px 12px 8px;
  }
  .page-header {
    margin-bottom: 8px;
  }
  .page-header h1 {
    font-size: 1rem;
  }
  .page-header .class-name {
    font-size: 0.8rem;
    padding: 5px 12px;
  }
  .legend {
    gap: 10px;
    font-size: 0.7rem;
    padding-bottom: 8px;
  }
  .page {
    padding-top: 10px;
  }
}

/* ---------- Table wrapper: horizontal scroll on small screens ---------- */
.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  background: var(--panel);
  -webkit-overflow-scrolling: touch;
}

table.plan {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  min-width: 760px; /* forces horizontal scroll on phones instead of squashing */
  table-layout: fixed;
}

table.plan thead th {
  background: var(--header-bg);
  color: var(--header-text);
  font-size: clamp(0.7rem, 1.6vw, 0.85rem);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 12px 6px;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 3;
  isolation: isolate;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

table.plan thead th:first-child {
  left: 0;
  z-index: 4;
  width: 110px;
}

table.plan th.day-today {
  background: #2e4257;
}

table.plan td.hour-cell {
  background: var(--hour-bg);
  color: var(--text-muted);
  font-size: clamp(0.65rem, 1.5vw, 0.8rem);
  text-align: center;
  font-weight: 600;
  white-space: nowrap;
  padding: 6px 4px;
  position: sticky;
  left: 0;
  z-index: 2;
  border-bottom: 1px solid var(--border);
  isolation: isolate;
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
}

table.plan td {
  border-bottom: 1px solid var(--border);
  padding: 6px;
  vertical-align: middle;
  height: 78px;
}

table.plan td.lesson-td {
  padding: 6px;
}

/* ---------- Flip card ---------- */
.flip-card {
  perspective: 800px;
  height: 100%;
  min-height: 66px;
  isolation: isolate;
}

.flip-card.is-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #c3c9d1;
  font-size: 1rem;
}

.flip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 66px;
  transition: transform 0.5s cubic-bezier(.4,.2,.2,1);
  transform-style: preserve-3d;
  cursor: pointer;
}

.lesson-cell.flipped .flip-inner {
  transform: rotateY(180deg);
}

.flip-front, .flip-back {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 6px 4px;
  gap: 3px;
}

.flip-front {
  background: var(--subject-tint, #f2f2f2);
  border: 2px solid transparent;
}

.flip-front .icon {
  font-size: 1.15rem;
  line-height: 1;
}

.flip-front .name {
  font-size: clamp(0.62rem, 1.4vw, 0.78rem);
  font-weight: 600;
  color: var(--text);
  line-height: 1.15;
}

.flip-back {
  background: var(--subject-color);
  color: #fff;
  transform: rotateY(180deg);
  font-size: clamp(0.6rem, 1.3vw, 0.76rem);
}

.flip-back .teacher {
  font-weight: 700;
}

.flip-back .room {
  opacity: 0.9;
}

.flip-back .time-range {
  margin-top: 3px;
  font-size: 0.65rem;
  font-weight: 600;
  opacity: 0.9;
  letter-spacing: 0.02em;
}

/* ---------- Timeline statuses ---------- */
/* future = default colored */
.status-future .flip-front {
  border-color: var(--subject-color);
}

/* current = strong border + subtle glow, animated */
.status-current .flip-front {
  border-color: #2ecc71;
  border-width: 3px;
  box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.18);
  animation: pulse 2.2s infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(46, 204, 113, 0.18); }
  50% { box-shadow: 0 0 0 6px rgba(46, 204, 113, 0.28); }
}

/* past = grayed out */
.status-past .flip-front {
  background: #eceff2;
  border-color: #dde1e6;
}

.status-past .flip-front .name {
  color: #9aa2ad;
}

.status-past .flip-front .icon {
  filter: grayscale(1);
  opacity: 0.55;
}

.status-past .flip-back {
  background: #b7bfc9;
}

/* ---------- Mobile: single-column day list ---------- */
.mobile-schedule {
  display: none;
}

.day-block {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  scroll-margin-top: calc(var(--topbar-h, 0px) + 44px);
}

.day-title {
  margin: 0;
  background: var(--header-bg);
  color: var(--header-text);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 10px 14px;
  border-radius: var(--radius) var(--radius) 0 0;
  position: sticky;
  top: var(--topbar-h, 0px);
  z-index: 40;
}

.day-block.day-today-block .day-title {
  background: #2e4257;
}

.day-lessons {
  display: flex;
  flex-direction: column;
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
}

.m-row {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  scroll-margin-top: calc(var(--topbar-h, 0px) + 44px);
}

.m-row:last-child {
  border-bottom: none;
}

.m-time {
  flex: 0 0 58px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--text-muted);
  line-height: 1.3;
}

.m-lesson {
  flex: 1;
  min-width: 0;
}

.m-lesson .flip-card {
  min-height: 54px;
}

.m-lesson .flip-card.is-empty {
  justify-content: flex-start;
  padding-left: 6px;
  font-size: 0.85rem;
}

.mobile-schedule .flip-front,
.mobile-schedule .flip-back {
  flex-direction: row;
  justify-content: flex-start;
  text-align: left;
  padding: 8px 12px;
  gap: 10px;
}

.mobile-schedule .flip-front .name {
  font-size: 0.85rem;
}

.mobile-schedule .flip-front .icon {
  font-size: 1.3rem;
}

.mobile-schedule .flip-back {
  flex-wrap: wrap;
  align-items: center;
  font-size: 0.72rem;
  row-gap: 2px;
}

.mobile-schedule .flip-back .teacher {
  flex: 1 1 100%;
}

.mobile-schedule .flip-back .room,
.mobile-schedule .flip-back .time-range {
  opacity: 0.9;
}

.mobile-schedule .flip-back .room::after {
  content: "•";
  margin: 0 6px;
  opacity: 0.6;
}

@media (max-width: 700px) {
  .table-scroll,
  .scroll-hint {
    display: none;
  }
  .mobile-schedule {
    display: block;
  }
}

footer.note {
  margin-top: 18px;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: center;
}