/* =====================================================
   HK Fun Study — 主樣式
   設計目標：小朋友覺得好玩、家長覺得專業
   ===================================================== */

:root {
  --bg: #fff8f0;
  --bg-2: #fdf1e3;
  --card: #ffffff;
  --ink: #26303f;
  --ink-2: #5a677a;
  --muted: #8b96a8;
  --line: #ece4d9;

  --brand: #ff7a59;
  --brand-dark: #f2603c;
  --teal: #2ec4b6;
  --sun: #ffc857;
  --purple: #9b8afb;

  --radius: 24px;
  --radius-sm: 14px;
  --shadow: 0 6px 18px rgba(38, 48, 63, 0.07);
  --shadow-lg: 0 14px 36px rgba(38, 48, 63, 0.12);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang HK", "PingFang TC",
    "Microsoft JhengHei", "Noto Sans TC", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 12% 8%, rgba(255, 200, 87, 0.18), transparent 42%),
    radial-gradient(circle at 88% 12%, rgba(46, 196, 182, 0.14), transparent 40%),
    radial-gradient(circle at 50% 100%, rgba(255, 122, 89, 0.1), transparent 45%);
  pointer-events: none;
  z-index: 0;
}

.wrap {
  position: relative;
  z-index: 1;
  max-width: 980px;
  margin: 0 auto;
  padding: 0 18px 64px;
}

/* ---------- 頂欄 ---------- */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0 10px;
  flex-wrap: wrap;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
}

.logo-mark {
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--brand), var(--sun));
  display: grid;
  place-items: center;
  font-size: 22px;
  box-shadow: 0 5px 14px rgba(255, 122, 89, 0.32);
}

.logo-text b {
  display: block;
  font-size: 17px;
  letter-spacing: -0.2px;
}

.logo-text span {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.4px;
}

.nav {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav a, .nav button {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-2);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  cursor: pointer;
  transition: all 0.18s ease;
  font-family: inherit;
}

.nav a:hover, .nav button:hover {
  background: #fff;
  color: var(--brand-dark);
  border-color: rgba(255, 122, 89, 0.4);
  transform: translateY(-1px);
}

.nav a.active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

/* ---------- 標題區 ---------- */
.hero {
  text-align: center;
  padding: 26px 0 30px;
}

.hero h1 {
  font-size: clamp(26px, 6vw, 38px);
  margin: 0 0 10px;
  letter-spacing: -0.6px;
  line-height: 1.25;
}

.hero h1 em {
  font-style: normal;
  background: linear-gradient(120deg, var(--brand), var(--sun));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero p {
  margin: 0 auto;
  max-width: 520px;
  color: var(--ink-2);
  font-size: 15px;
}

.section-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin: 34px 0 16px;
}

.section-title h2 {
  font-size: 19px;
  margin: 0;
  letter-spacing: -0.2px;
}

.section-title span {
  font-size: 13px;
  color: var(--muted);
}

/* ---------- 年級卡片 ---------- */
.grade-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

@media (max-width: 720px) {
  .grade-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
}

.grade-card {
  position: relative;
  display: block;
  text-decoration: none;
  color: inherit;
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px 18px 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
  overflow: hidden;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
}

.grade-card::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 5px;
  background: var(--accent, var(--brand));
}

.grade-card .emoji {
  font-size: 34px;
  line-height: 1;
  display: block;
  margin-bottom: 10px;
}

.grade-card b {
  display: block;
  font-size: 17px;
  letter-spacing: -0.2px;
}

.grade-card small {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 3px;
}

.grade-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.grade-card:active { transform: translateY(-1px) scale(0.99); }

.badge {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: #fff2ee;
  color: var(--brand-dark);
}

.badge.soft { background: #eef7f6; color: #1a9a8e; }

/* ---------- 科目卡片 ---------- */
.subject-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}

@media (max-width: 560px) {
  .subject-grid { grid-template-columns: 1fr; }
}

.subject-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}

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

.subject-ico {
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 26px;
  background: var(--tint, #fff1ec);
}

.subject-body { flex: 1; min-width: 0; }

.subject-body b { display: block; font-size: 16px; }

.subject-body small {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 2px;
}

.chev { color: #c9d0db; font-size: 20px; flex: 0 0 auto; }

/* coming 狀態 */
.subject-card.coming {
  background: #fdfaf6;
  border-style: dashed;
  box-shadow: none;
  cursor: pointer;
}

.subject-card.coming .subject-ico { filter: grayscale(0.55); opacity: 0.75; }
.subject-card.coming b { color: var(--ink-2); }

/* 鎖頭 */
.lock-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: #f0f2f5;
  color: #8792a5;
}

.unlock-chip {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  background: #e8f8f4;
  color: #149e84;
}

/* ---------- 按鈕 ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  padding: 13px 26px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s;
  background: var(--brand);
  color: #fff;
  box-shadow: 0 6px 16px rgba(255, 122, 89, 0.32);
}

.btn:hover { background: var(--brand-dark); transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.985); }

.btn.ghost {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  box-shadow: none;
}

.btn.ghost:hover { border-color: var(--brand); color: var(--brand-dark); }

.btn.teal {
  background: var(--teal);
  box-shadow: 0 6px 16px rgba(46, 196, 182, 0.3);
}

.btn.teal:hover { background: #26ab9f; }

.btn.block { width: 100%; }
.btn.sm { font-size: 13px; padding: 8px 16px; }

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none !important;
}

/* ---------- 卡片容器 ---------- */
.panel {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 24px;
}

.panel.tight { padding: 18px; }

/* ---------- 表單 ---------- */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-2);
  margin-bottom: 7px;
}

.input, select, textarea {
  width: 100%;
  font-family: inherit;
  font-size: 16px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--line);
  background: #fffdfb;
  color: var(--ink);
  transition: border-color 0.16s, box-shadow 0.16s;
  outline: none;
}

.input:focus, select:focus, textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(255, 122, 89, 0.12);
}

.input.code {
  font-size: 22px;
  letter-spacing: 5px;
  text-align: center;
  font-weight: 700;
  text-transform: uppercase;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.hint {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 6px;
}

/* ---------- 提示訊息 ---------- */
.alert {
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  font-size: 14px;
  margin-bottom: 16px;
  display: none;
  line-height: 1.5;
}

.alert.show { display: block; }

.alert.err { background: #fff1f0; color: #c0392b; border: 1px solid #ffd9d4; }
.alert.ok { background: #eefaf4; color: #127a5c; border: 1px solid #c8f0dd; }
.alert.warn { background: #fff9e8; color: #8a6100; border: 1px solid #ffe9ad; }

/* ---------- 占位 / coming ---------- */
.placeholder {
  text-align: center;
  padding: 48px 24px;
}

.placeholder .big {
  font-size: 62px;
  line-height: 1;
  margin-bottom: 18px;
  display: block;
  filter: grayscale(0.3);
}

.placeholder h2 { margin: 0 0 10px; font-size: 21px; }

.placeholder p {
  color: var(--ink-2);
  max-width: 400px;
  margin: 0 auto 22px;
  font-size: 14.5px;
}

/* ---------- 授權卡 ---------- */
.lic-list { display: grid; gap: 12px; }

.lic-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #fffdfb;
}

.lic-item.expired { opacity: 0.62; }

.lic-main b { display: block; font-size: 15.5px; }

.lic-main small { color: var(--muted); font-size: 12.5px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

th {
  font-weight: 700;
  color: var(--ink-2);
  font-size: 12.5px;
  background: #fdfaf6;
}

tbody tr:hover { background: #fffdf9; }

/* ---------- 頁尾 ---------- */
.footer {
  margin-top: 56px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  line-height: 1.9;
}

.footer a { color: var(--ink-2); }

/* ---------- 小工具 ---------- */
.center { text-align: center; }
.mt-24 { margin-top: 24px; }
.mt-16 { margin-top: 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.grow { flex: 1; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.hidden { display: none !important; }

.loading {
  text-align: center;
  padding: 40px;
  color: var(--muted);
  font-size: 14px;
}

/* 多行文字（後台可以打回車分段） */
.preline { white-space: pre-line; }

.spin {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(255, 122, 89, 0.25);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -3px;
  margin-right: 8px;
}

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

/* 麵包屑 */
.crumb {
  font-size: 13px;
  color: var(--muted);
  margin: 4px 0 18px;
}

.crumb a { color: var(--ink-2); text-decoration: none; }
.crumb a:hover { color: var(--brand-dark); }
