/*
 * TC Simulation 共用外殼（品牌規格：ronald-workspace 202609-tc-interactive-teaching-library
 * _work/SIMULATION-KIT-draft.md）。每個 simulation 都 link 呢份，再加自己少量樣式。
 * 規則：面板一律實色 navy、唔用毛玻璃；orange 只代表「重點／成功」；已揀中狀態用 cream。
 */
@font-face {
  font-family: "Noto Sans HK";
  src: url("./fonts/NotoSansHK-latin.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --orange: #F28900;
  --orange-soft: #FDE4D3;
  --navy: #0E1F3D;
  --navy-2: #172C52;
  --navy-3: #22396A;
  --cream: #FBEEDA;
  --cream-2: #F6E3C6;
  --muted: #A9B4C6;
  --muted-2: #6F7E98;
  --grey: #9AA6BA;
  --radius: 14px;
  --gap: 24px;
  --shadow: 0 1px 0 rgba(255, 255, 255, .06) inset, 0 2px 4px rgba(14, 31, 61, .18), 0 12px 32px rgba(14, 31, 61, .22);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Noto Sans HK", system-ui, -apple-system, sans-serif;
  color: var(--navy);
  overflow: hidden;
  background: radial-gradient(120% 90% at 50% 40%, #FDF4E6 0%, var(--cream) 55%, var(--cream-2) 100%);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
sub, sup { font-size: .6em; line-height: 0; position: relative; }
sub { vertical-align: -0.16em; }
sup { vertical-align: 0.4em; }

.sim-stage { position: fixed; inset: 0; display: block; width: 100%; height: 100%; outline: none; }
.sim-ui { position: fixed; z-index: 2; }

/* 左上：logo、標題、即時數字 */
.sim-head { top: 22px; left: var(--gap); }
.sim-head .logo { height: 26px; display: block; margin-bottom: 14px; }
.sim-head h1 { font-weight: 900; font-size: 34px; line-height: 1; letter-spacing: .01em; white-space: nowrap; }
.sim-stats { display: inline-flex; margin-top: 14px; background: var(--navy); border-radius: 12px; box-shadow: var(--shadow); padding: 2px 0; }
.sim-stat { color: var(--cream); padding: 7px 14px 8px; min-width: 96px; }
.sim-stat + .sim-stat { border-left: 1px solid rgba(255, 255, 255, .09); }
.sim-stat b { display: block; font-size: 10px; letter-spacing: .12em; font-weight: 700; color: var(--muted); white-space: nowrap; }
.sim-stat span { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.sim-stat.hot span { color: var(--orange); }

/* 右上：控制板 */
.sim-panel { top: 22px; right: var(--gap); width: 300px; background: var(--navy); color: var(--cream); border-radius: var(--radius); padding: 16px 16px 14px; box-shadow: var(--shadow); }
.sim-lbl { display: flex; justify-content: space-between; font-size: 10.5px; letter-spacing: .14em; font-weight: 700; color: var(--muted); margin: 0 0 7px; }
.sim-lbl kbd { font-family: inherit; color: var(--muted-2); letter-spacing: .2em; }
.sim-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--navy-2); border-radius: 9px; padding: 3px; margin-bottom: 15px; gap: 2px; }
.sim-seg button { all: unset; cursor: pointer; text-align: center; font-size: 13.5px; font-weight: 700; padding: 7px 4px; border-radius: 7px; color: var(--muted); white-space: nowrap; }
.sim-seg button:hover { color: var(--cream); }
.sim-seg button[aria-pressed="true"] { background: var(--cream); color: var(--navy); }
.sim-seg.small button { font-size: 12px; padding: 7px 2px; }
.sim-seg.grid2 { grid-auto-flow: row; grid-template-columns: 1fr 1fr; }
.sim-row { margin-bottom: 13px; }
.sim-row .top { display: flex; justify-content: space-between; font-size: 13.5px; font-weight: 600; margin-bottom: 8px; }
.sim-row .top em { font-style: normal; font-variant-numeric: tabular-nums; font-weight: 800; }

input[type="range"].sim-range { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; cursor: pointer; display: block; }
input[type="range"].sim-range::-webkit-slider-runnable-track { height: 6px; border-radius: 3px; background: linear-gradient(to right, var(--cream) 0 var(--fill, 50%), var(--navy-2) var(--fill, 50%) 100%); }
input[type="range"].sim-range::-moz-range-track { height: 6px; border-radius: 3px; background: var(--navy-2); }
input[type="range"].sim-range::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--cream); }
input[type="range"].sim-range::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%; background: var(--cream); box-shadow: 0 2px 6px rgba(0, 0, 0, .35); border: 0; }
input[type="range"].sim-range::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: var(--cream); box-shadow: 0 2px 6px rgba(0, 0, 0, .35); border: 0; }
.sim-row.has-tick { position: relative; }
.sim-tick { position: absolute; bottom: -3px; width: 2px; height: 5px; margin-left: -1px; border-radius: 1px; background: var(--muted-2); pointer-events: none; }
input[type="range"].sim-range:focus-visible { outline: 2px solid var(--cream); outline-offset: 4px; border-radius: 4px; }

.sim-toggle { all: unset; cursor: pointer; box-sizing: border-box; width: 100%; display: flex; justify-content: space-between; align-items: center; font-size: 13.5px; font-weight: 600; padding: 9px 0; border-top: 1px solid rgba(255, 255, 255, .07); }
.sim-toggle .sw { width: 36px; height: 20px; border-radius: 10px; background: var(--navy-2); position: relative; flex: none; transition: background .15s; }
.sim-toggle .sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: left .15s, background .15s; }
.sim-toggle[aria-checked="true"] .sw { background: var(--cream); }
.sim-toggle[aria-checked="true"] .sw::after { left: 19px; background: var(--navy); }
.sim-toggle kbd { font-family: inherit; font-size: 10.5px; color: var(--muted-2); margin-left: 8px; letter-spacing: .1em; }
.sim-toggle:focus-visible, .sim-seg button:focus-visible, .sim-actions button:focus-visible { outline: 2px solid var(--cream); outline-offset: 2px; }

.sim-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.sim-actions button { all: unset; cursor: pointer; text-align: center; font-size: 13.5px; font-weight: 700; padding: 9px 0; border-radius: 9px; background: var(--navy-2); color: var(--cream); }
.sim-actions button:hover { background: var(--navy-3); }
.sim-actions button.primary { background: var(--cream); color: var(--navy); }
.sim-actions button.primary:hover { background: #fff6e8; }

/* 右下：圖表圖層 */
.sim-chart { right: var(--gap); bottom: 24px; width: 300px; background: var(--navy); color: var(--cream); border-radius: var(--radius); padding: 13px 14px 10px; box-shadow: var(--shadow); transition: opacity .2s, transform .2s; }
.sim-chart[hidden] { display: block; opacity: 0; transform: translateY(8px); pointer-events: none; }
.sim-chart svg { display: block; width: 100%; height: auto; }
.sim-chart .foot { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.sim-chart .foot b { color: var(--orange); font-variant-numeric: tabular-nums; }

/* 中下：圖例 */
.sim-legend { left: 50%; transform: translateX(-50%); bottom: 26px; display: flex; gap: 14px; align-items: center; background: rgba(251, 238, 218, .94); border: 1px solid rgba(14, 31, 61, .10); border-radius: 999px; padding: 8px 18px; font-size: 13px; font-weight: 700; box-shadow: 0 2px 10px rgba(14, 31, 61, .10); white-space: nowrap; }
.sim-legend .it { display: flex; gap: 6px; align-items: center; }
.sim-legend .op { color: var(--muted-2); font-weight: 600; }
.sim-legend .grp { font-size: 10.5px; letter-spacing: .14em; color: var(--muted-2); }

/* 3D 標籤 */
.sim-tag { position: fixed; z-index: 3; left: 0; top: 0; transform: translate(-50%, -100%); font-size: 13px; font-weight: 800; padding: 6px 12px; border-radius: 999px; white-space: nowrap; box-shadow: 0 2px 8px rgba(14, 31, 61, .25); pointer-events: none; transition: opacity .15s; }
.sim-tag[hidden] { display: block; opacity: 0; }
.sim-tag.hot { background: var(--orange); color: var(--navy); }
.sim-tag.cold { background: var(--navy); color: var(--cream); }

.sim-foot { left: var(--gap); bottom: 14px; font-size: 10.5px; letter-spacing: .12em; font-weight: 700; color: var(--muted-2); }
.sim-fallback { position: fixed; inset: 0; display: grid; place-items: center; font-size: 16px; font-weight: 700; padding: 24px; text-align: center; }

@media (max-width: 1100px) {
  :root { --gap: 16px; }
  .sim-head h1 { font-size: 28px; }
  .sim-stat { min-width: 84px; padding: 6px 11px 7px; }
  .sim-stat span { font-size: 18px; }
  .sim-panel, .sim-chart { width: 270px; }
}
@media (max-width: 1260px) {
  /* 細 mon：圖例靠左，避開右下圖表 */
  .sim-legend { left: var(--gap); transform: none; bottom: 34px; gap: 10px; padding: 7px 14px; font-size: 12px; }
  .sim-foot { bottom: 12px; }
}
@media (max-height: 760px) {
  /* iPad Safari 橫放：收窄控制板，唔好掂到右下圖表 */
  .sim-panel { padding: 13px 14px 12px; }
  .sim-seg { margin-bottom: 10px; }
  .sim-row { margin-bottom: 9px; }
  .sim-row .top { margin-bottom: 6px; }
  .sim-toggle { padding: 6px 0; }
  .sim-actions { margin-top: 7px; }
  .sim-actions button { padding: 8px 0; }
  .sim-chart { padding: 10px 12px 8px; }
}
@media (max-height: 600px) {
  .sim-chart { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .sim-chart, .sim-tag, .sim-toggle .sw, .sim-toggle .sw::after { transition: none; }
}
