/* shadcn/ui inspired design system */
:root {
  --background: hsl(0 0% 100%);
  --foreground: hsl(240 10% 3.9%);
  --card: hsl(0 0% 100%);
  --card-foreground: hsl(240 10% 3.9%);
  --muted: hsl(240 4.8% 95.9%);
  --muted-foreground: hsl(240 3.7% 46.1%);
  --border: hsl(240 5.9% 90%);
  --input: hsl(240 5.9% 90%);
  --primary: hsl(240 5.9% 10%);
  --primary-foreground: hsl(0 0% 98%);
  --secondary: hsl(240 4.8% 95.9%);
  --secondary-foreground: hsl(240 5.9% 10%);
  --accent: hsl(240 4.8% 95.9%);
  --accent-foreground: hsl(240 5.9% 10%);
  --destructive: hsl(0 84.2% 60.2%);
  --ring: hsl(240 5.9% 10%);
  --radius: 0.5rem;

  /* Subject badge colors - light mode */
  --subj-korean: hsl(213 94% 68%);
  --subj-math: hsl(24 95% 64%);
  --subj-english: hsl(142 69% 50%);
  --subj-science: hsl(270 70% 68%);
  --subj-social: hsl(38 92% 60%);
  --subj-pe: hsl(120 40% 55%);
  --subj-art: hsl(340 75% 65%);
  --subj-music: hsl(24 90% 60%);
  --subj-moral: hsl(193 80% 55%);
  --subj-tech: hsl(210 80% 60%);
  --subj-info: hsl(195 85% 52%);
  --subj-chinese: hsl(0 78% 63%);
  --subj-default: hsl(240 4% 60%);

  --today-bg: hsl(213 94% 97%);
  --today-border: hsl(213 94% 68%);
  --current-bg: hsl(142 76% 95%);
  --current-border: hsl(142 69% 50%);
}

[data-theme="dark"] {
  --background: hsl(240 10% 3.9%);
  --foreground: hsl(0 0% 98%);
  --card: hsl(240 10% 3.9%);
  --card-foreground: hsl(0 0% 98%);
  --muted: hsl(240 3.7% 15.9%);
  --muted-foreground: hsl(240 5% 64.9%);
  --border: hsl(240 3.7% 15.9%);
  --input: hsl(240 3.7% 15.9%);
  --primary: hsl(0 0% 98%);
  --primary-foreground: hsl(240 5.9% 10%);
  --secondary: hsl(240 3.7% 15.9%);
  --secondary-foreground: hsl(0 0% 98%);
  --accent: hsl(240 3.7% 15.9%);
  --accent-foreground: hsl(0 0% 98%);
  --ring: hsl(240 4.9% 83.9%);

  --subj-korean: hsl(213 75% 55%);
  --subj-math: hsl(24 80% 55%);
  --subj-english: hsl(142 55% 42%);
  --subj-science: hsl(270 55% 58%);
  --subj-social: hsl(38 78% 52%);
  --subj-pe: hsl(120 35% 45%);
  --subj-art: hsl(340 62% 55%);
  --subj-music: hsl(24 75% 52%);
  --subj-moral: hsl(193 65% 45%);
  --subj-tech: hsl(210 65% 50%);
  --subj-info: hsl(195 70% 44%);
  --subj-chinese: hsl(0 65% 54%);
  --subj-default: hsl(240 5% 45%);

  --today-bg: hsl(213 40% 12%);
  --today-border: hsl(213 75% 55%);
  --current-bg: hsl(142 35% 12%);
  --current-border: hsl(142 55% 42%);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Noto Sans KR', 'Segoe UI', sans-serif;
  background: var(--background);
  color: var(--foreground);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.2s, color 0.2s;
}

/* ── Header ── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--border);
  background: var(--background);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 56px;
  max-width: 640px;
  margin: 0 auto;
}

.header-left {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.header-school {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted-foreground);
  letter-spacing: 0.04em;
}

.header-class {
  font-size: 18px;
  font-weight: 700;
  color: var(--foreground);
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* ── Icon Button ── */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--accent);
  color: var(--accent-foreground);
}

.icon-btn:active {
  opacity: 0.85;
  transform: scale(0.95);
}

.icon-btn.active {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}

.icon-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* ── Main ── */
.main-content {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px;
}

/* ── Week Selector ── */
.week-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 16px;
}

.week-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
}

.week-select-wrap {
  position: relative;
  width: 100%;
  display: flex;
  justify-content: center;
}

#week-select {
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  border: none;
  color: var(--foreground);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  text-align: center;
  padding: 0 20px;
  max-width: 100%;
}

#week-select option {
  background: var(--background);
  color: var(--foreground);
}

.week-range {
  font-size: 11px;
  color: var(--muted-foreground);
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: calc(var(--radius) - 2px);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted-foreground);
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}

.nav-btn:hover { background: var(--accent); color: var(--accent-foreground); }
.nav-btn:active { transform: scale(0.93); }
.nav-btn:disabled { opacity: 0.35; cursor: not-allowed; }
.nav-btn svg { width: 14px; height: 14px; }

/* ── Loading ── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 20px;
  gap: 12px;
  color: var(--muted-foreground);
  font-size: 13px;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--foreground);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Timetable Card ── */
.timetable-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
}

/* ── Grid ── */
.tt-grid {
  display: grid;
  grid-template-columns: 36px repeat(5, 1fr);
}

/* All grid children get right + bottom borders */
.tt-grid > * {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

/* Last column (every 6th child) — no right border */
.tt-grid > *:nth-child(6n) {
  border-right: none;
}

/* Last row — no bottom border */
.tt-cell.tt-last-row,
.tt-period-label.tt-last-row {
  border-bottom: none;
}

/* Header row */
.tt-day-cell {
  padding: 10px 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted-foreground);
  background: var(--muted);
}

.tt-day-cell.today {
  color: var(--today-border);
  background: var(--today-bg);
}

.tt-period-num-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 4px;
  background: var(--muted);
}

/* Period rows */
.tt-period-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 2px;
  background: var(--muted);
}

.period-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--foreground);
  line-height: 1;
}

.period-time {
  font-size: 9px;
  color: var(--muted-foreground);
  margin-top: 2px;
}

/* Subject cells */
.tt-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 4px;
  min-height: 58px;
  gap: 3px;
  transition: background 0.15s;
  position: relative;
}

.tt-cell.today-col {
  background: var(--today-bg);
}

.tt-cell.current {
  background: var(--current-bg);
}

.tt-cell.current::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--current-border);
  border-radius: 0 2px 2px 0;
}

/* Subject badge */
.subj-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 7px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  word-break: keep-all;
  white-space: nowrap;
  background: var(--subj-color-bg, var(--muted));
  color: var(--subj-color-text, var(--muted-foreground));
}

.subj-teacher {
  font-size: 10px;
  color: var(--muted-foreground);
}

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 20px;
  gap: 12px;
  color: var(--muted-foreground);
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.empty-state p { color: var(--muted-foreground); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--primary);
  color: var(--primary-foreground);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn:active { opacity: 0.8; transform: scale(0.97); }

/* ── Fetched info ── */
.fetched-info {
  text-align: center;
  font-size: 11px;
  color: var(--muted-foreground);
  margin-top: 12px;
  padding-bottom: 32px;
}

/* ── Pull-to-refresh ── */
#ptr-indicator {
  position: fixed;
  top: 0;
  left: 50%;
  transform: translateX(-50%) translateY(-100%);
  background: var(--primary);
  color: var(--primary-foreground);
  padding: 6px 16px;
  border-radius: 0 0 var(--radius) var(--radius);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  z-index: 200;
  transition: transform 0.3s;
}

#ptr-indicator.visible { transform: translateX(-50%) translateY(0); }

.ptr-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  opacity: 0;
  background: var(--foreground);
  color: var(--background);
  padding: 10px 20px;
  border-radius: 9999px;
  font-size: 13px;
  font-weight: 500;
  z-index: 300;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
  white-space: nowrap;
  max-width: calc(100vw - 40px);
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* ── Responsive ── */
@media (max-width: 360px) {
  .subj-badge { font-size: 10px; padding: 2px 5px; }
  .subj-teacher { font-size: 9px; }
  .tt-cell { min-height: 50px; padding: 6px 2px; }
  .period-num { font-size: 12px; }
}

@media (min-width: 480px) {
  .subj-badge { font-size: 12px; }
  .tt-cell { min-height: 64px; }
}
