/* styles.css — 迷你試算表樣式（自 index.html 抽出） */

:root { --accent: #1a73e8; --err: #c5221f; --line: #c0c4cc; --line-strong: #8e8e8e; }
* { box-sizing: border-box; }
body { font-family: system-ui, "Microsoft JhengHei", sans-serif; margin: 24px; color: #202124; }
h1 { font-size: 18px; margin: 0 0 4px; }
#hint { font-size: 12px; color: #5f6368; margin: 0 0 12px; }
.vh { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
      overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }   /* 視覺隱藏（報讀器可讀） */
#toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
#addr-box { font-size: 13px; color: #5f6368; }
#addr { font-family: monospace; font-weight: bold; min-width: 3.5em; display: inline-block; text-align: center;
        background: #f1f3f4; border: 1px solid var(--line-strong); border-radius: 4px; padding: 4px 8px; }
#formula-bar { flex: 1 1 320px; max-width: 640px; min-width: 200px; padding: 5px 8px;
        font-family: monospace; font-size: 14px; border: 1px solid var(--line-strong); border-radius: 4px; }
#formula-bar:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
#err-msg { font-size: 12px; color: var(--err); }
/* U04：動作按鈕列（觸控目標 ≥44px；aria-disabled 維持可點擊以保留報讀） */
#toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
#toolbar button { min-height: 44px; min-width: 44px; padding: 6px 14px; font-size: 13px;
  font-family: inherit; color: #202124; background: #fff; border: 1px solid var(--line-strong);
  border-radius: 6px; cursor: pointer; }
#toolbar button:hover { background: #f1f3f4; }
#toolbar button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
#toolbar button[aria-disabled="true"] { color: #9aa0a6; border-color: var(--line); }
#btn-clear.armed { background: #fce8e6; border-color: var(--err); color: var(--err); font-weight: bold; }
/* U07：Name Box 位址跳轉輸入框（#addr 維持唯讀顯示不動；此框 tabindex="-1"
   不進 Tab 順序，保住既有測試的 Tab 契約） */
#addr-input { width: 5.5em; padding: 4px 8px; font-family: monospace; font-size: 13px;
  color: #202124; background: #fff; border: 1px solid var(--line-strong); border-radius: 4px; }
#addr-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
/* U12：載入範例的頁內確認面板（禁原生 confirm；預設 hidden） */
#example-panel { max-width: 520px; margin: 0 0 10px; padding: 10px 12px; background: #f8f9fa;
  border: 1px solid var(--line-strong); border-radius: 6px; }
#example-panel p { margin: 0 0 8px; font-size: 13px; color: #202124; }
#example-panel button { min-height: 44px; min-width: 44px; margin: 2px 6px 2px 0; padding: 6px 14px;
  font-size: 13px; font-family: inherit; background: #fff; color: #202124;
  border: 1px solid var(--line-strong); border-radius: 6px; cursor: pointer; }
#example-panel button:hover { background: #f1f3f4; }
/* U11：重算醒目提示——顯示值變了的格短暫變色，1 秒後由 JS 移除 class */
td[data-cell].flash { animation: cell-flash 1s ease-out; }
@keyframes cell-flash { 0% { background: #fff3b0; } 100% { background: #fff; } }
/* U01：自動保存不可用時的頁內橫幅（預設 hidden，由 main.js 顯示） */
#persist-warn { font-size: 13px; color: #5f4b00; background: #fef7e0; border: 1px solid #e6c200;
  border-radius: 4px; padding: 8px 12px; margin: 0 0 12px; max-width: 720px; }
/* 卷軸容器：限高讓欄字母（sticky top）與列號（sticky left）真正固定 */
#grid-wrap { overflow: auto; max-height: 68vh; max-width: 100%; border: 1px solid var(--line); }
/* separate 模型：避免 border-collapse 下 sticky 儲存格捲動時邊框消失的瀏覽器缺陷 */
table { border-collapse: separate; border-spacing: 0; }
th { background: #f1f3f4; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
     padding: 3px 10px; font-family: monospace; font-size: 13px; font-weight: normal;
     position: sticky; top: 0; z-index: 2; }
th.rowhead { top: auto; left: 0; z-index: 3; }
th.corner { top: 0; z-index: 4; }
td[data-cell] { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line);
     min-width: 78px; max-width: 220px; height: 24px; padding: 1px 6px;
     font-family: monospace; font-size: 13px; white-space: pre; overflow: hidden; text-overflow: ellipsis;
     cursor: cell; background: #fff; }
td[data-cell]:hover { background: #f1f3f4; }
td[data-cell].num { text-align: right; }        /* 數字、布林靠右：型別一眼分清 */
/* U15 範圍選取：範圍底色（較淺），錨點格另疊 .sel 的框線——
   兩條規則分別定義 background 與 box-shadow，錨點同時掛兩個 class 時視覺正確疊加 */
td[data-cell].sel-range { background: #f1f6fe; }
/* 選取用 inset box-shadow 而非 outline：不會穿透 sticky 欄標題繪製 */
td[data-cell].sel { box-shadow: inset 0 0 0 2px var(--accent); background: #e8f0fe; }
td[data-cell].err { color: var(--err); font-weight: bold; }
td[data-cell].err::after { content: " ⚠"; font-weight: normal; }   /* 錯誤不只靠顏色辨識 */
td[data-cell]:focus-visible { outline: 2px dashed var(--accent); outline-offset: -2px; }
@media (pointer: coarse) {                      /* 觸控裝置：加大觸控目標 */
  td[data-cell] { height: 40px; padding: 6px; }
}
#help { margin-top: 14px; font-size: 13px; color: #202124; max-width: 720px; }
#help summary { cursor: pointer; color: var(--accent); }
#help table { border-collapse: collapse; margin: 6px 0; }
#help th, #help td { border: 1px solid var(--line); padding: 2px 8px; text-align: left; font-size: 12px; }
#help code { font-family: monospace; background: #f1f3f4; padding: 0 4px; border-radius: 3px; }

/* U06＋U09：行動版動線（窄視窗，斷點 700px）
   ——公式列（連同整個工具列）固定於視窗底部貼鍵盤動線；
   bottom 吃 mobile.js 用 visualViewport 算出的 --kbd-offset（鍵盤彈出時上移）；
   hint 收合精簡首屏；觸控目標 ≥44px。 */
@media (max-width: 700px) {
  #hint { display: none; }                    /* U09：首屏動線精簡（收合） */
  body { padding-bottom: 150px; }             /* 避免固定工具列遮住最後幾列 */
  #toolbar { position: fixed; left: 0; right: 0; bottom: var(--kbd-offset, 0px); z-index: 10;
    margin: 0; padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
    background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08); }
  #formula-bar { max-width: none; }
  #addr-input { min-height: 44px; }           /* U07：觸控目標 ≥44px */
  #toolbar button, #toolbar-actions button, #example-panel button { min-height: 44px; min-width: 44px; }
  td[data-cell] { height: 44px; }             /* 觸控目標 ≥44px（pointer:coarse 的 40px 不適用此情境） */
}
/* U10：教學模式（body.teach-mode，由 #btn-teach 切換）——大字體＋寬網格，
   僅在 class 存在時生效；一般模式版面與現行完全一致。 */
body.teach-mode h1 { font-size: 26px; }
body.teach-mode #hint { font-size: 18px; }
body.teach-mode #addr-box { font-size: 18px; }
body.teach-mode #addr { font-size: 18px; }
body.teach-mode #addr-input { font-size: 18px; }
body.teach-mode #formula-bar { font-size: 18px; }
body.teach-mode #err-msg { font-size: 18px; }
body.teach-mode #toolbar button, body.teach-mode #toolbar-actions button,
body.teach-mode #example-panel button { font-size: 18px; min-height: 48px; }
body.teach-mode #persist-warn { font-size: 18px; }
body.teach-mode th { font-size: 18px; }
body.teach-mode td[data-cell] { font-size: 18px; height: 30px; }
body.teach-mode #help { font-size: 18px; }
body.teach-mode #help th, body.teach-mode #help td { font-size: 18px; }
body.teach-mode #grid { width: 85vw; }        /* 1920×1080 下網格佔寬 ≥80%（驗收標準） */
body.teach-mode #example-panel p { font-size: 18px; }

/* U05：列印友善版面——只印網格本體，20 列全展開、黑白可讀 */
@media print {
  /* 工具列（含公式列）、提示、說明、橫幅一律不進紙 */
  #toolbar, #hint, #help, #persist-warn { display: none !important; }
  body { margin: 8mm; }
  /* 取消捲動裁剪與限高：20 列全展開 */
  #grid-wrap { overflow: visible; max-height: none; max-width: none; border: none; }
  th { position: static; background: #fff; }
  /* 黑白可讀：去底色、框邊改實黑、錯誤格維持符號辨識不靠顏色 */
  th, td[data-cell] { border-color: #000; color: #000; background: #fff; }
  td[data-cell] { overflow: visible; text-overflow: clip; white-space: pre-wrap; }
  td[data-cell].err { color: #000; }
  td[data-cell].sel { box-shadow: none; background: #fff; }
  td[data-cell].sel-range { background: #fff; }
}