:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-hover: #fcfdff;
  --text: #152238;
  --text-muted: #56657c;
  --border: #e2e8f0;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --accent-orange: #ea580c;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
  --shadow-hover: 0 12px 28px rgba(29, 78, 216, 0.12);
  --radius: 18px;

  /* 晴空藍 */
  --sky-bg: #e0f2fe;
  --sky-fg: #0369a1;
  --sky-solid: #0284c7;
  --sky-border: #7dd3fc;

  /* 校徽藍 */
  --royal-bg: #dbeafe;
  --royal-fg: #1d4ed8;
  --royal-solid: #1d4ed8;
  --royal-border: #93c5fd;

  /* 活力橘 */
  --orange-bg: #ffedd5;
  --orange-fg: #c2410c;
  --orange-solid: #ea580c;
  --orange-border: #fdba74;

  /* 暖金橘（呼應校徽金穗） */
  --amber-bg: #fef3c7;
  --amber-fg: #b45309;
  --amber-solid: #d97706;
  --amber-border: #fcd34d;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1425;
    --surface: #162033;
    --surface-hover: #1d2a42;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #2a3a54;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.28);
    --shadow-hover: 0 12px 28px rgba(0, 0, 0, 0.45);

    --sky-bg: rgba(14, 165, 233, 0.18);
    --sky-fg: #7dd3fc;
    --sky-solid: #0284c7;
    --sky-border: rgba(125, 211, 252, 0.35);

    --royal-bg: rgba(59, 130, 246, 0.2);
    --royal-fg: #93c5fd;
    --royal-solid: #2563eb;
    --royal-border: rgba(147, 197, 253, 0.35);

    --orange-bg: rgba(249, 115, 22, 0.2);
    --orange-fg: #fdba74;
    --orange-solid: #ea580c;
    --orange-border: rgba(253, 186, 116, 0.35);

    --amber-bg: rgba(245, 158, 11, 0.2);
    --amber-fg: #fcd34d;
    --amber-solid: #d97706;
    --amber-border: rgba(252, 211, 77, 0.35);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: "Noto Sans TC", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.top-accent-bar {
  height: 5px;
  width: 100%;
  background: linear-gradient(90deg, #1d4ed8 0%, #0284c7 40%, #f59e0b 75%, #ea580c 100%);
}

.page-shell {
  max-width: 960px;
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 20px max(40px, env(safe-area-inset-bottom));
}

.hero {
  margin-bottom: 24px;
}

.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 22px 24px;
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand-identity {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.emblem-frame {
  width: 72px;
  height: 72px;
  border-radius: 18px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(29, 78, 216, 0.08);
}

.emblem-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.brand-text {
  min-width: 0;
}

.school-name {
  display: inline-block;
  padding: 3px 10px;
  margin-bottom: 6px;
  border-radius: 999px;
  background: var(--royal-bg);
  color: var(--royal-fg);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.hero h1 {
  margin: 0 0 4px;
  font-size: clamp(1.35rem, 3.5vw, 1.85rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

@media (max-width: 680px) {
  .hero-card {
    padding: 18px;
  }
  .emblem-frame {
    width: 60px;
    height: 60px;
    border-radius: 14px;
  }
  .hero-actions {
    width: 100%;
  }
  .hero-actions .icon-btn {
    flex: 1;
    justify-content: center;
  }
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 14px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-hover);
  transform: translateY(-1px);
}

.icon-btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

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

.line-banner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  margin-bottom: 20px;
  border-radius: 14px;
  background: var(--amber-bg);
  border: 1px solid var(--amber-border);
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.5;
}

.line-banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.line-banner-close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

@media (max-width: 680px) {
  .cards-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
}

.portal-card {
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.portal-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
}

.portal-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-hover);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.card-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.card-badges {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-recent {
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

/* 主題色系：晴空藍、校徽藍、活力橘、暖金橘 */
.theme-sky::before { background: var(--sky-solid); }
.theme-sky .card-icon,
.theme-sky .badge-theme { background: var(--sky-bg); color: var(--sky-fg); }
.theme-sky:hover { border-color: var(--sky-border); }
.theme-sky .open-link { background: var(--sky-solid); color: #ffffff; }

.theme-royal::before { background: var(--royal-solid); }
.theme-royal .card-icon,
.theme-royal .badge-theme { background: var(--royal-bg); color: var(--royal-fg); }
.theme-royal:hover { border-color: var(--royal-border); }
.theme-royal .open-link { background: var(--royal-solid); color: #ffffff; }

.theme-orange::before { background: var(--orange-solid); }
.theme-orange .card-icon,
.theme-orange .badge-theme { background: var(--orange-bg); color: var(--orange-fg); }
.theme-orange:hover { border-color: var(--orange-border); }
.theme-orange .open-link { background: var(--orange-solid); color: #ffffff; }

.theme-amber::before { background: var(--amber-solid); }
.theme-amber .card-icon,
.theme-amber .badge-theme { background: var(--amber-bg); color: var(--amber-fg); }
.theme-amber:hover { border-color: var(--amber-border); }
.theme-amber .open-link { background: var(--amber-solid); color: #ffffff; }

.card-grade {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.card-title {
  margin: 0 0 8px;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.3;
}

.card-desc {
  margin: 0 0 20px;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.55;
  flex-grow: 1;
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.open-link {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border-radius: 12px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.95rem;
  transition: filter 0.15s ease, transform 0.15s ease;
}

.open-link:hover {
  filter: brightness(1.07);
}

.open-link:active {
  transform: scale(0.98);
}

.copy-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.copy-link-btn:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.footer {
  margin-top: 32px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
  line-height: 1.6;
}

.footer p {
  margin: 4px 0;
}

.footer-meta {
  font-size: 0.8rem;
  opacity: 0.85;
}

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  width: 100%;
  max-width: 460px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-close {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
}

.modal-body {
  padding: 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.guide-block h3 {
  margin: 0 0 8px;
  font-size: 0.98rem;
}

.guide-block ol {
  margin: 0;
  padding-left: 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.65;
}

.modal-footer {
  padding: 14px 22px 20px;
  display: flex;
  justify-content: flex-end;
}

.btn-done {
  padding: 10px 20px;
  border-radius: 10px;
  border: none;
  background: var(--primary);
  color: #ffffff;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(20px);
  background: #152238;
  color: #ffffff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 200;
}

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