/* ===== 主題色彩：預設淺色，系統為深色模式時自動切換 ===== */
:root {
  --bg: #fbfaf7;
  --bg-alt: #f2efe8;
  --surface: #ffffff;
  --text: #1f2328;
  --muted: #5b6370;
  --border: #e2ddd2;
  --accent: #c2410c;        /* Java 咖啡橘 */
  --accent-soft: #fde8db;
  --accent-text: #ffffff;
  --link: #b4410f;
  --code-bg: #1e1f24;
  --code-text: #e6e6e6;
  --inline-code-bg: #efe9de;
  --warn-bg: #fff6d6;
  --warn-border: #e0b400;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);

  --radius: 12px;
  --maxw: 880px;
  --font-sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC",
               system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas,
               "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161a;
    --bg-alt: #1b1c21;
    --surface: #22242a;
    --text: #e7e7ea;
    --muted: #a3a8b3;
    --border: #33363e;
    --accent: #f97316;
    --accent-soft: #3a2416;
    --accent-text: #1a1206;
    --link: #fb923c;
    --code-bg: #0f1013;
    --inline-code-bg: #2c2f37;
    --warn-bg: #3a3214;
    --warn-border: #b38f00;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25);
  }
}

/* ===== 基本設定 ===== */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; scroll-padding-top: 72px; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

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

.container { max-width: var(--maxw); margin: 0 auto; padding: 0 20px; }

h1, h2, h3 { line-height: 1.35; margin: 0 0 .6em; }
h1 { font-size: clamp(2rem, 6vw, 3rem); letter-spacing: .02em; }
h2 { font-size: clamp(1.5rem, 4vw, 1.9rem); margin-bottom: .8em; }
h3 { font-size: 1.2rem; margin-top: 1.8em; }
p, ul, ol { margin: 0 0 1em; }
ul, ol { padding-left: 1.4em; }
li { margin-bottom: .35em; }

a { color: var(--link); text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.muted { color: var(--muted); }
.small { font-size: .88rem; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: var(--accent-text); padding: 8px 14px; z-index: 100;
}
.skip-link:focus { left: 12px; top: 12px; }

/* ===== 頁首導覽 ===== */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; min-height: 60px; max-width: 1100px;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--text); text-decoration: none; white-space: nowrap; }
.site-nav { display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: flex-end; }
.site-nav a {
  color: var(--muted); text-decoration: none; font-size: .9rem; padding: 4px 2px;
  border-bottom: 2px solid transparent;
}
.site-nav a:hover, .site-nav a.active { color: var(--accent); border-bottom-color: var(--accent); }

.nav-toggle {
  display: none;
  font: inherit; font-size: .9rem;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 4px 12px; cursor: pointer;
}

@media (max-width: 860px) {
  .nav-toggle { display: inline-block; }
  .site-nav {
    display: none;
    position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; gap: 0;
    background: var(--surface); border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow); padding: 8px 20px 14px;
  }
  .site-nav.open { display: flex; }
  .site-nav a { padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 1rem; }
  .site-nav a:last-child { border-bottom: none; }
}

/* ===== Hero ===== */
.hero {
  padding: 72px 0 56px;
  background:
    radial-gradient(circle at 85% 20%, var(--accent-soft), transparent 55%),
    var(--bg);
  border-bottom: 1px solid var(--border);
}
.eyebrow { color: var(--accent); font-weight: 700; letter-spacing: .1em; margin-bottom: .4em; }
.lead { font-size: 1.15rem; color: var(--muted); max-width: 40em; }

/* ===== 按鈕 ===== */
.btn {
  display: inline-block;
  font: inherit; font-weight: 600; font-size: .95rem;
  background: var(--accent); color: var(--accent-text);
  border: 1px solid var(--accent); border-radius: 999px;
  padding: 8px 20px; cursor: pointer; text-decoration: none;
  transition: transform .1s ease, filter .15s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: transparent; color: var(--accent); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== 章節 ===== */
.section { padding: 64px 0; }
.section.alt { background: var(--bg-alt); }
.num {
  display: inline-grid; place-items: center;
  width: 1.6em; height: 1.6em; margin-right: .5em;
  border-radius: 50%; background: var(--accent); color: var(--accent-text);
  font-size: .8em; vertical-align: .1em;
}

/* ===== 卡片 ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin: 1.5em 0; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
}
.card h3 { margin-top: 0; font-size: 1.05rem; }
.card p { margin: 0; color: var(--muted); font-size: .95rem; }

/* ===== 提示框 ===== */
.callout {
  background: var(--accent-soft); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 12px 16px; margin: 1.4em 0;
}
.callout.warn { background: var(--warn-bg); border-left-color: var(--warn-border); }

/* ===== 表格 ===== */
.table-wrap { overflow-x: auto; margin: 1.2em 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: var(--bg-alt); font-weight: 700; white-space: nowrap; }
tr:last-child td { border-bottom: none; }

/* ===== 程式碼 ===== */
code {
  font-family: var(--font-mono); font-size: .9em;
  background: var(--inline-code-bg); padding: .1em .4em; border-radius: 5px;
}
pre.code {
  background: var(--code-bg); color: var(--code-text);
  border-radius: var(--radius); padding: 16px 18px; margin: .8em 0 1em;
  overflow-x: auto; line-height: 1.6; font-size: .9rem;
  -webkit-overflow-scrolling: touch;
}
pre.code code { background: none; padding: 0; font-size: inherit; color: inherit; }
.code-block { margin: 1em 0; }
.code-block pre.code { margin: 0; }
.code-title {
  display: inline-block;
  font-family: var(--font-mono); font-size: .8rem;
  background: var(--code-bg); color: #9aa0aa;
  padding: 4px 14px; border-radius: 8px 8px 0 0;
}
.code-title + pre.code { border-top-left-radius: 0; }

/* 簡易語法上色 */
.kw { color: #ff8f66; }
.ty { color: #7cc4ff; }
.fn { color: #ffd479; }
.str { color: #a5e07a; }
.num-lit { color: #d7a8ff; }
.cm { color: #7d8590; font-style: italic; }
.prompt { color: #6ee7a8; user-select: none; }

.output {
  white-space: pre-wrap; font-family: var(--font-mono); font-size: .9rem; line-height: 1.6;
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
  padding: 12px 16px; margin: .6em 0 1.4em;
}
.output-label {
  display: block; font-family: var(--font-sans); font-size: .75rem; font-weight: 700;
  color: var(--muted); letter-spacing: .1em; margin-bottom: 4px;
}

.explain li, .steps li { margin-bottom: .8em; }

/* ===== JDK / JRE / JVM 圖 ===== */
.nest { margin: 1.5em 0; }
.nest-box { border-radius: var(--radius); padding: 10px 14px 14px; border: 2px solid; }
.nest-box > span { display: block; font-weight: 700; font-size: .92rem; margin-bottom: 8px; }
.nest-box.jdk { border-color: var(--accent); background: var(--surface); }
.nest-box.jre { border-color: #3b82f6; background: color-mix(in srgb, #3b82f6 8%, var(--surface)); }
.nest-box.jvm { border-color: #10b981; background: color-mix(in srgb, #10b981 12%, var(--surface)); text-align: center; }
.nest-box.jvm > span { margin: 0; }

/* ===== 編譯流程圖 ===== */
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; margin: 1.5em 0; }
.flow-step {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 14px; font-family: var(--font-mono); font-size: .9rem; text-align: center;
  box-shadow: var(--shadow);
}
.flow-step small { display: block; font-family: var(--font-sans); color: var(--muted); font-size: .75rem; }
.flow-arrow { color: var(--accent); font-family: var(--font-mono); font-size: .85rem; font-weight: 700; }

/* ===== 陣列示意 ===== */
.array-viz { display: flex; gap: 6px; margin: 1.2em 0; flex-wrap: wrap; }
.array-viz .cell {
  width: 64px; text-align: center; background: var(--surface);
  border: 2px solid var(--accent); border-radius: 8px; padding: 6px 0 2px;
}
.array-viz b { display: block; font-family: var(--font-mono); font-size: 1.1rem; }
.array-viz small { color: var(--muted); font-family: var(--font-mono); }

/* ===== 假終端機 ===== */
.terminal {
  background: #0d0e11; color: #d6d6d6;
  border-radius: var(--radius); overflow: hidden;
  border: 1px solid #2a2c33; box-shadow: 0 8px 30px rgba(0,0,0,.25);
  font-family: var(--font-mono); font-size: .9rem; margin: 1.4em 0 1em;
}
.terminal-bar { display: flex; align-items: center; gap: 7px; padding: 10px 14px; background: #1b1c21; border-bottom: 1px solid #2a2c33; }
.dot { width: 12px; height: 12px; border-radius: 50%; }
.dot.red { background: #ff5f57; } .dot.yellow { background: #febc2e; } .dot.green { background: #28c840; }
.terminal-title { margin-left: 10px; color: #8b8f99; font-size: .8rem; }
.terminal-body {
  padding: 14px 16px; min-height: 260px; max-height: 420px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word; line-height: 1.6;
}
.terminal-body .line { min-height: 1.6em; }
.terminal-body .cmd::before { content: "$ "; color: #6ee7a8; }
.terminal-body .cmd { color: #ffffff; }
.terminal-body .ok { color: #a5e07a; }
.terminal-body .err { color: #ff7b72; }
.terminal-body .info { color: #8b8f99; font-style: italic; }
.terminal-body .file { color: #7cc4ff; }
.terminal-body .result { color: #ffd479; font-weight: 700; }
.terminal-body .cursor::after {
  content: "▋"; color: #6ee7a8; animation: blink 1s steps(1) infinite; margin-left: 1px;
}
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .terminal-body .cursor::after { animation: none; } }

.terminal-input {
  display: flex; align-items: center; gap: 8px;
  border-top: 1px solid #2a2c33; padding: 10px 16px; background: #121317;
}
.terminal-input input {
  flex: 1; min-width: 0; background: transparent; border: none; outline: none;
  color: #ffffff; font: inherit; font-size: 16px; /* 16px 避免 iOS 自動放大 */
}
.terminal-input input::placeholder { color: #5d616b; }
.terminal-input:focus-within { box-shadow: inset 0 0 0 2px var(--accent); }

.demo-controls { display: flex; flex-wrap: wrap; gap: 10px; }
.demo-hint { margin-top: 12px; color: var(--muted); min-height: 1.8em; }

/* ===== 頁尾 ===== */
.site-footer { padding: 36px 0 48px; border-top: 1px solid var(--border); color: var(--muted); text-align: center; }
.site-footer p { margin-bottom: .4em; }

.link-list li { word-break: break-all; }

/* ===== 手機調整 ===== */
@media (max-width: 600px) {
  body { font-size: 16px; }
  .section { padding: 48px 0; }
  .hero { padding: 52px 0 40px; }
  pre.code { font-size: .82rem; padding: 14px; }
  th, td { padding: 8px 10px; }
  .flow { flex-direction: column; align-items: stretch; }
  .flow-arrow { text-align: center; }
  .terminal-body { min-height: 220px; }
}
