:root {
  --bg: #f7f9fc;
  --surface: #ffffff;
  --surface-alt: #f1f5f9;
  --text: #0f172a;
  --text-muted: #475569;
  --text-soft: #64748b;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --accent: #059669;
  --accent-soft: #ecfdf5;
  --payme: #db0011;
  --payme-hover: #b8000e;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 26px rgba(15, 23, 42, 0.08);
  --font-sans: "Inter", "PingFang HK", "Microsoft JhengHei", "Noto Sans TC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-kai: "DFKai-SB", "BiauKai", "標楷體", "STKaiti", "KaiTi", "Noto Serif TC", serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.container {
  width: min(1120px, 92vw);
  margin: 0 auto;
}

/* Header & Navigation */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.nav-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.9rem;
  padding: 0.8rem 0;
  flex-wrap: wrap;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 800;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
}

.brand-link:hover {
  text-decoration: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #1d4ed8, #0f766e);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.86rem;
  flex-shrink: 0;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.nav-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.4rem 0.78rem;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-muted);
  border: 1px solid var(--border);
  background: var(--surface);
  transition: all 0.15s ease;
  text-decoration: none;
}

.nav-pill:hover {
  color: var(--primary);
  border-color: var(--primary);
  text-decoration: none;
}

.nav-pill.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: #bfdbfe;
}

.lang-toggle {
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
}

.lang-btn {
  border: 0;
  background: transparent;
  padding: 0.32rem 0.72rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
}

.lang-btn.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1.05rem;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.88rem;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn:hover {
  text-decoration: none;
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

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

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-payme {
  background: var(--payme);
  color: #fff;
}

.btn-payme:hover {
  background: var(--payme-hover);
  color: #fff;
}

.btn-ghost {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}

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

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

/* Cards & Layout */
.hero-box {
  margin: 2rem 0 1.75rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 55%, #0f4c81 100%);
  color: #f8fafc;
  border-radius: var(--radius-lg);
  padding: 2.2rem;
  box-shadow: var(--shadow-md);
}

.hero-eyebrow {
  display: inline-block;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.25rem 0.7rem;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.25);
  border: 1px solid rgba(147, 197, 253, 0.35);
  color: #bfdbfe;
  margin-bottom: 0.8rem;
}

.hero-box h1 {
  margin: 0 0 0.7rem;
  font-size: clamp(1.55rem, 3vw, 2.25rem);
  line-height: 1.24;
}

.hero-box p {
  margin: 0 0 1.25rem;
  color: #cbd5e1;
  max-width: 66ch;
}

.tools-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.2rem;
  margin-bottom: 2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 1.35rem;
  box-shadow: var(--shadow-sm);
}

.tool-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 1rem;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.tool-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.tool-tag {
  display: inline-block;
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.22rem 0.6rem;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  margin-bottom: 0.55rem;
}

.tool-card h2 {
  margin: 0 0 0.45rem;
  font-size: 1.12rem;
}

.tool-card p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.89rem;
}

.page-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 1.5rem 0 1.25rem;
}

.page-title-row h1 {
  margin: 0;
  font-size: 1.55rem;
}

.page-sub {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.split-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.field {
  display: grid;
  gap: 0.3rem;
}

.field label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 0.52rem 0.72rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.88rem;
  background: #fff;
  color: var(--text);
}

.field textarea {
  font-family: var(--font-sans);
  resize: vertical;
}

.code-output {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 0.9rem;
  overflow-x: auto;
  white-space: pre;
  line-height: 1.5;
  margin: 0;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin-top: 0.9rem;
}

.kpi-box {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.78rem;
}

.kpi-box span {
  display: block;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.kpi-box strong {
  font-size: 1.25rem;
}

.notice {
  padding: 0.75rem 0.95rem;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  line-height: 1.5;
}

.notice-info {
  background: var(--primary-soft);
  border: 1px solid #bfdbfe;
  color: #1e40af;
}

.notice-success {
  background: var(--accent-soft);
  border: 1px solid #a7f3d0;
  color: #065f46;
}

.notice-warn {
  background: var(--warn-soft);
  border: 1px solid #fde68a;
  color: #92400e;
}

.notice-danger {
  background: var(--danger-soft);
  border: 1px solid #fecaca;
  color: #991b1b;
}

/* Tip Jar & Ad Slot Containers (hidden automatically when unconfigured) */
.tip-jar-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  background: linear-gradient(90deg, #fff5f5 0%, #eff6ff 100%);
  border: 1px solid #fecdd3;
  border-radius: var(--radius-md);
  padding: 1.15rem 1.35rem;
  margin: 1.5rem 0;
}

.ad-slot-container {
  display: none; /* Revealed by common.js only when adsenseClientId/ethicalAdsPublisher is set */
  margin: 1.25rem 0;
  padding: 0.75rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  text-align: center;
  background: var(--surface);
}

.ad-slot-container.active {
  display: block;
}

/* Printable Dictation Sheet Preview */
.sheet-preview-wrap {
  margin-top: 1.25rem;
  display: grid;
  gap: 1.25rem;
  justify-items: center;
}

.a4-sheet {
  width: 210mm;
  max-width: 100%;
  min-height: 297mm;
  background: #ffffff;
  color: #000000;
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  padding: 14mm 15mm;
  display: flex;
  flex-direction: column;
  gap: 5mm;
}

.sheet-header {
  border-bottom: 1.5px solid #111827;
  padding-bottom: 3.5mm;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
}

.sheet-title {
  font-family: var(--font-kai);
  font-size: 18pt;
  font-weight: 700;
  margin: 0;
}

.sheet-meta {
  font-family: var(--font-kai);
  font-size: 11pt;
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.grid-rows {
  display: flex;
  flex-direction: column;
  gap: 3.2mm;
}

.grid-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
}

.grid-cell {
  position: relative;
  border: 1px solid #1f2937;
  margin-left: -1px;
  margin-top: -1px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  background: #fff;
}

.grid-cell svg.cell-guide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.grid-char {
  position: relative;
  z-index: 2;
  font-family: var(--font-kai);
  line-height: 1;
  user-select: none;
}

.grid-char.trace {
  color: #9ca3af;
}

.grid-char.solid {
  color: #111827;
}

.lined-row {
  width: 100%;
  border-bottom: 1px solid #374151;
  display: flex;
  align-items: flex-end;
  padding: 0 2mm 1.5mm;
  font-family: var(--font-kai);
  letter-spacing: 0.22em;
}

/* IEEE Three-Line Table Preview */
.ieee-table-wrap {
  overflow-x: auto;
  padding: 1rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.ieee-caption {
  text-align: center;
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  font-family: "Times New Roman", Georgia, var(--font-sans), serif;
}

table.ieee-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "Times New Roman", Georgia, serif;
  font-size: 0.95rem;
  border-top: 2px solid #000;
  border-bottom: 2px solid #000;
}

table.ieee-table thead th {
  border-bottom: 1px solid #000;
  padding: 0.45rem 0.7rem;
  font-weight: 700;
  background: transparent;
}

table.ieee-table tbody td {
  padding: 0.38rem 0.7rem;
  border: 0;
}

/* General Data Table (GPA) */
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

table.data-table th,
table.data-table td {
  padding: 0.5rem 0.45rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

table.data-table th {
  font-size: 0.76rem;
  text-transform: uppercase;
  color: var(--text-soft);
  background: var(--surface-alt);
}

/* Footer */
.site-footer {
  margin-top: 2.5rem;
  padding: 1.5rem 0 2.25rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.84rem;
}

.footer-inner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 200;
  background: #0f172a;
  color: #fff;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: all 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .tools-grid,
  .split-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  .field-grid,
  .kpi-row {
    grid-template-columns: 1fr;
  }
  .a4-sheet {
    padding: 8mm;
  }
}

/* Print Stylesheet for A4 Dictation PDF Export */
@page {
  size: A4 portrait;
  margin: 12mm;
}

@media print {
  body {
    background: #fff !important;
  }
  .no-print,
  .site-header,
  .site-footer,
  .ad-slot-container,
  .tip-jar-card,
  .toast {
    display: none !important;
  }
  .container {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
  }
  .sheet-preview-wrap {
    margin: 0 !important;
    gap: 0 !important;
  }
  .a4-sheet {
    width: 100% !important;
    min-height: auto !important;
    border: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    page-break-after: always;
    break-after: page;
  }
  .a4-sheet:last-child {
    page-break-after: auto;
    break-after: auto;
  }
}
