/* Aero Visualizer — 飛機科學視覺教室
   Light, projector-friendly theme. Force colours are the pedagogical spine:
   the same four hues mean the same four things in all eight tabs. */

:root {
  --lift:   #16a34a;
  --drag:   #f97316;
  --thrust: #2563eb;
  --weight: #dc2626;
  --hot:    #ef4444;
  --cold:   #3b82f6;

  --ink:    #10243e;
  --ink-2:  #3c5a7d;
  --muted:  #5b7290;
  --line:   #d5e3f2;
  --card:   #ffffff;
  --bg:     #eef5fd;
  --bg-2:   #dcebfb;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 22px;
  --shadow: 0 2px 4px rgba(16, 36, 62, .06), 0 10px 26px rgba(16, 36, 62, .09);
  --font: "Nunito", "Segoe UI Rounded", "SF Pro Rounded", system-ui, -apple-system,
          "PingFang HK", "Noto Sans HK", "Microsoft JhengHei", "Heiti TC", sans-serif;
  --mono: "SF Mono", "Roboto Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  background-image:
    radial-gradient(1100px 520px at 78% -8%, #ffffff 0%, rgba(255, 255, 255, 0) 62%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
  background-attachment: fixed;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}

/* ---------------------------------------------------------------- top bar */

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 16px;
  padding: 10px clamp(12px, 3vw, 28px);
  background: rgba(255, 255, 255, .86);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}

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

.brand-mark {
  width: 34px; height: 34px; flex: none;
  border-radius: 11px;
  background: linear-gradient(140deg, #38bdf8, #1d4ed8);
  position: relative;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .12);
}
.brand-mark::after {
  content: ""; position: absolute; inset: 0;
  background:
    linear-gradient(90deg, transparent 44%, #fff 44%, #fff 56%, transparent 56%),
    linear-gradient(0deg, transparent 52%, #fff 52%, #fff 60%, transparent 60%);
  border-radius: inherit; opacity: .92;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.brand-text strong { font-size: 1.06rem; letter-spacing: -.01em; }
.brand-text em {
  font-style: normal; font-size: .76rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.langsw { margin-left: auto; display: flex; gap: 3px; padding: 3px;
          background: var(--bg-2); border-radius: 999px; }
.langsw button {
  font: inherit; font-size: .82rem; font-weight: 700;
  color: var(--muted); background: none; border: 0; cursor: pointer;
  padding: 6px 14px; border-radius: 999px; line-height: 1;
}
.langsw button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }

/* -------------------------------------------------------------- tab strip */

.tabstrip {
  position: sticky; top: 55px; z-index: 35;
  display: flex; gap: 8px;
  padding: 10px clamp(12px, 3vw, 28px);
  overflow-x: auto; overflow-y: hidden;
  background: rgba(238, 245, 253, .9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.tabbtn {
  flex: none; display: flex; align-items: center; gap: 9px;
  font: inherit; font-weight: 700; font-size: .88rem;
  color: var(--muted); background: var(--card);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 16px 8px 11px; cursor: pointer; white-space: nowrap;
  transition: transform .12s, box-shadow .12s, color .12s, border-color .12s;
}
.tabbtn .ti { font-size: 1.15rem; line-height: 1; }
.tabbtn:hover { transform: translateY(-1px); box-shadow: var(--shadow); color: var(--ink); }
.tabbtn[aria-selected="true"] {
  color: #fff; border-color: transparent;
  background: linear-gradient(140deg, #0ea5e9, #1d4ed8);
  box-shadow: 0 6px 16px rgba(29, 78, 216, .32);
}
.tabbtn:focus-visible, .btn:focus-visible, .chip:focus-visible,
input:focus-visible, select:focus-visible {
  outline: 3px solid #0ea5e9; outline-offset: 2px;
}

/* ------------------------------------------------------------------ panel */

#main { flex: 1 0 auto; }

.panel { display: none; padding: clamp(14px, 2.4vw, 26px) clamp(12px, 3vw, 28px) 34px; }
.panel.active { display: block; animation: fade .22s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.tabhead { margin: 0 0 14px; }
.tabhead h1 { margin: 0; font-size: clamp(1.3rem, 2.9vw, 1.85rem); letter-spacing: -.02em; }
.tabhead p { margin: 3px 0 0; color: var(--muted); font-size: clamp(.84rem, 1.6vw, .97rem); }

.tabbody { display: flex; flex-direction: column; gap: 14px; }

.loading, .boot {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 30px; color: var(--muted); font-weight: 700;
}
.spin {
  width: 20px; height: 20px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: #0ea5e9;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

/* ------------------------------------------------------------------- card */

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--shadow);
  padding: 14px; min-width: 0;
}
.card > h2 {
  margin: 0 0 10px; font-size: 1rem; letter-spacing: -.01em;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.card > h2 .n {
  font-size: .7rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase;
  color: #fff; background: #0ea5e9; border-radius: 999px; padding: 3px 8px;
}
.card-sub { margin: -6px 0 10px; font-size: .82rem; color: var(--muted); }

.grid2 { display: grid; gap: 14px; grid-template-columns: 1fr; }
.grid3 { display: grid; gap: 14px; grid-template-columns: 1fr; }
.split  { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (min-width: 900px) {
  .grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (min-width: 1080px) {
  .split { grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); }
}

.row { display: flex; gap: 9px; flex-wrap: wrap; align-items: center; }
.row.tight { gap: 6px; }
.grow { flex: 1 1 220px; min-width: 0; }

/* ------------------------------------------------------------------ stage */

.stage {
  position: relative; width: 100%;
  border-radius: var(--r-md); overflow: hidden;
  background: #dceeff; border: 1px solid var(--line);
  touch-action: none;
}
.stage canvas { display: block; width: 100%; height: 100%; }
.stage svg { display: block; width: 100%; height: 100%; }
.stage.pad  { padding: 10px; }
.stage-label {
  position: absolute; z-index: 3; pointer-events: none;
  font-size: .74rem; font-weight: 800; letter-spacing: .02em;
  padding: 4px 9px; border-radius: 999px;
  background: rgba(16, 36, 62, .82); color: #fff;
  transform: translate(-50%, -140%); white-space: nowrap;
}
.stage-note {
  position: absolute; z-index: 3; left: 10px; top: 10px;
  font-size: .76rem; font-weight: 700; padding: 5px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, .88); color: var(--ink);
  box-shadow: 0 2px 8px rgba(16, 36, 62, .14);
}
.stage-note.warn { background: var(--weight); color: #fff; }
.stage-note.good { background: var(--lift); color: #fff; }
.stage-ctl {
  position: absolute; z-index: 4; right: 10px; top: 10px;
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end;
}

/* ----------------------------------------------------------------- inputs */

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > label {
  font-size: .76rem; font-weight: 800; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em;
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
}
.field > label b {
  color: var(--ink); font-variant-numeric: tabular-nums;
  font-size: .92rem; letter-spacing: 0; text-transform: none;
}

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 26px; background: none; cursor: pointer; margin: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px; border-radius: 999px; background: var(--bg-2);
  border: 1px solid var(--line);
}
input[type="range"]::-moz-range-track {
  height: 8px; border-radius: 999px; background: var(--bg-2); border: 1px solid var(--line);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 22px; height: 22px; margin-top: -8px;
  border-radius: 50%; background: #1d4ed8; border: 3px solid #fff;
  box-shadow: 0 2px 6px rgba(16, 36, 62, .3);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: #1d4ed8; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(16, 36, 62, .3);
}
input[type="range"].red::-webkit-slider-thumb { background: var(--weight); }
input[type="range"].red::-moz-range-thumb   { background: var(--weight); }

select {
  font: inherit; font-size: .86rem; font-weight: 700; color: var(--ink);
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 7px 10px; cursor: pointer;
}

.btn {
  font: inherit; font-size: .84rem; font-weight: 800; color: var(--ink);
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 8px 13px; cursor: pointer;
  transition: transform .1s, box-shadow .1s, background .12s;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.btn:active { transform: none; }
.btn.on {
  color: #fff; border-color: transparent;
  background: linear-gradient(140deg, #0ea5e9, #1d4ed8);
  box-shadow: 0 5px 14px rgba(29, 78, 216, .3);
}
.btn.warn { color: #fff; background: var(--weight); border-color: transparent; }
.btn.good { color: #fff; background: var(--lift); border-color: transparent; }
.btn.sm { font-size: .76rem; padding: 5px 10px; }

.chip {
  font: inherit; font-size: .76rem; font-weight: 800;
  color: var(--muted); background: var(--bg-2); border: 1px solid transparent;
  border-radius: 999px; padding: 5px 11px; cursor: pointer; white-space: nowrap;
}
.chip[aria-pressed="true"], .chip.on {
  color: var(--ink); background: #dbeafe; border-color: #93c5fd;
}

/* ---------------------------------------------------------------- readouts */

.readout { display: flex; flex-direction: column; gap: 2px; }
.readout .val {
  font-family: var(--mono); font-size: 1.5rem; font-weight: 700;
  line-height: 1; font-variant-numeric: tabular-nums; letter-spacing: -.02em;
}
.readout .lbl {
  font-size: .68rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
}
.readouts { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); }

.bignote {
  font-weight: 800; font-size: .95rem; text-align: center;
  padding: 9px 12px; border-radius: var(--r-md);
  background: var(--bg-2); color: var(--ink);
}
.bignote.warn { background: #fee2e2; color: #991b1b; }
.bignote.good { background: #dcfce7; color: #14532d; }
.bignote.info { background: #dbeafe; color: #1e3a8a; }

.hint { font-size: .78rem; color: var(--muted); margin: 0; }
.hint b { color: var(--ink); }

.legend { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.legend i {
  display: inline-flex; align-items: center; gap: 6px;
  font-style: normal; font-size: .78rem; font-weight: 800;
}
.legend i::before {
  content: ""; width: 12px; height: 12px; border-radius: 3px;
  background: var(--c); box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .15);
}
.legend.lift i { --c: var(--lift); }
.legend.drag i { --c: var(--drag); }
.legend.thrust i { --c: var(--thrust); }
.legend.weight i { --c: var(--weight); }

/* --------------------------------------------------------------- 3D tab ui */

.stage.fly3d { background: linear-gradient(180deg, #4fa3e3 0%, #a8d4f5 52%, #d9ecfb 62%, #7dbf62 62%, #5ea348 100%); }
.fly-grid { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1040px) { .fly-grid { grid-template-columns: minmax(0, 1fr) 244px; } }

.padstack { display: flex; flex-direction: column; gap: 12px; }

.stick {
  width: 148px; height: 148px; margin: 0 auto; position: relative;
  border-radius: 50%; touch-action: none; cursor: grab;
  background: radial-gradient(circle at 50% 42%, #fff 0%, #e8f2fd 58%, #d3e6fa 100%);
  border: 2px solid #b9d4ef; box-shadow: inset 0 4px 12px rgba(16, 36, 62, .1);
}
.stick:active { cursor: grabbing; }
.stick::before, .stick::after {
  content: ""; position: absolute; background: #b9d4ef;
}
.stick::before { left: 12%; right: 12%; top: 50%; height: 1px; }
.stick::after  { top: 12%; bottom: 12%; left: 50%; width: 1px; }
.stick-knob {
  position: absolute; left: 50%; top: 50%; width: 60px; height: 60px;
  margin: -30px 0 0 -30px; border-radius: 50%;
  background: linear-gradient(160deg, #4b7bea, #1d4ed8);
  border: 3px solid #fff; box-shadow: 0 5px 14px rgba(16, 36, 62, .38);
  display: grid; place-items: center; color: #fff;
  font-size: .62rem; font-weight: 800; letter-spacing: .04em; text-align: center;
  pointer-events: none;
}
.stick-lbl {
  text-align: center; font-size: .74rem; font-weight: 800; color: var(--muted);
  margin-top: 6px;
}

.pedals { position: relative; height: 62px; display: flex; gap: 6px; }
.pedal {
  flex: 1; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--bg-2); display: grid; place-items: center;
  font-size: .72rem; font-weight: 800; color: var(--muted);
  transition: background .12s, color .12s;
}
.pedal.on { background: linear-gradient(140deg, #0ea5e9, #1d4ed8); color: #fff; border-color: transparent; }
.pedals-bar {
  position: absolute; left: 50%; top: 50%; width: 4px; height: 40px;
  margin: -20px 0 0 -2px; background: #b9d4ef; border-radius: 2px; pointer-events: none;
}

.hud { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(74px, 1fr)); }
.hud-cell {
  background: rgba(255, 255, 255, .16); border: 1px solid rgba(255, 255, 255, .3);
  border-radius: var(--r-sm); padding: 5px 8px; color: #fff;
  backdrop-filter: blur(3px); text-align: center;
}
.hud-cell .h-lbl { font-size: .58rem; font-weight: 800; letter-spacing: .07em; opacity: .85; text-transform: uppercase; }
.hud-cell .h-val { font-family: var(--mono); font-size: 1.02rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud-cell.stall { background: rgba(220, 38, 38, .85); border-color: #fff; }
.hud-adi { display: grid; place-items: center; }

.keyhelp { font-size: .74rem; color: var(--muted); line-height: 1.7; }
.keyhelp kbd {
  font-family: var(--mono); font-size: .7rem; font-weight: 700;
  background: var(--bg-2); border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 5px; color: var(--ink);
}

.surflist { display: flex; flex-direction: column; gap: 6px; }
.surflist button {
  font: inherit; font-size: .82rem; font-weight: 700; text-align: left;
  color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 7px 10px; cursor: pointer;
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.surflist button:hover { border-color: #93c5fd; background: #f0f7ff; }
.surflist button .arrowv { font-family: var(--mono); color: var(--muted); font-size: .78rem; }

/* ------------------------------------------------------------------- quiz */

.qcard { border: 1px solid var(--line); border-radius: var(--r-md); padding: 12px; background: #fbfdff; }
.qcard .q { font-weight: 800; font-size: .92rem; margin: 0 0 9px; }
.qopts { display: flex; gap: 8px; flex-wrap: wrap; }
.qopt {
  font: inherit; font-size: .82rem; font-weight: 700; cursor: pointer;
  background: var(--card); border: 2px solid var(--line); border-radius: var(--r-sm);
  padding: 7px 12px; color: var(--ink);
}
.qopt.right { border-color: var(--lift); background: #dcfce7; color: #14532d; }
.qopt.wrong { border-color: var(--weight); background: #fee2e2; color: #991b1b; }
.qcard .fb { margin: 9px 0 0; font-size: .82rem; font-weight: 700; }
.qcard .fb.right { color: #15803d; }
.qcard .fb.wrong { color: #b91c1c; }

/* ------------------------------------------------------------------ footer */

.sitefoot {
  flex: none; margin-top: 18px;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  padding: 16px clamp(12px, 3vw, 28px) 22px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .6);
  font-size: .84rem; color: var(--muted);
}
.foot-mark {
  width: 24px; height: 24px; border-radius: 8px; flex: none;
  background: linear-gradient(140deg, #38bdf8, #1d4ed8);
}
.foot-text { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: center; }
.foot-text strong { color: var(--ink); }
.foot-sep { opacity: .45; }
.sitefoot a { color: #1d4ed8; font-weight: 800; text-decoration: none; }
.sitefoot a:hover { text-decoration: underline; }

@media (max-width: 620px) {
  .brand-text em { display: none; }
  .tabstrip { top: 53px; }
  .tabbtn { padding: 7px 13px 7px 9px; font-size: .82rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}