:root {
  --ink:        #0b2b3d;
  --ink-soft:   #3a5b6e;
  --ink-mute:   #7d9db0;
  --line:       #dde7ef;
  --line-soft:  #e8f0f7;
  --surface:    #ffffff;
  --surface-2:  #f9fcff;
  --page:       #eef3f8;
  --brand:      #2f7a9e;
  --brand-dk:   #1b4e69;
  --accent:     #b4531f;
  --accent-bg:  #fff6ef;
  --accent-ln:  #f0cfb4;
  --good:       #2f8a5b;
  --danger:     #a33b2f;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--page);
  display: flex;
  justify-content: center;
  padding: 2rem 1rem 3rem;
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', 'Noto Sans TC', 'Microsoft JhengHei', Roboto, sans-serif;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.55;
}
.container {
  max-width: 1440px;
  width: 100%;
  background: var(--surface);
  border-radius: 26px;
  box-shadow: 0 14px 38px rgba(11,43,61,0.10);
  padding: 26px 30px 34px;
}

h1 {
  font-size: 1.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 8px;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.sub {
  color: var(--ink-soft);
  font-size: 0.95rem;
  margin: 0 0 22px;
  border-left: 4px solid #9dbccc;
  padding: 2px 0 2px 14px;
}
.flex-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.badge {
  background: #e3edf5;
  border-radius: 30px;
  padding: 5px 15px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--brand-dk);
  white-space: nowrap;
}

.grid-2col { display: grid; grid-template-columns: 1fr 1.05fr; gap: 26px; margin-top: 4px; }
@media (max-width: 1080px) { .grid-2col { grid-template-columns: 1fr; gap: 24px; } }

.param-card {
  background: var(--surface-2);
  border-radius: 20px;
  border: 1px solid var(--line);
  padding: 18px 20px 24px;
}
.param-card h2 {
  font-size: 1.18rem;
  font-weight: 600;
  margin: 0 0 16px;
  color: #17384b;
  display: flex;
  align-items: baseline;
  gap: 8px;
  border-bottom: 1px solid #d6e3ed;
  padding-bottom: 12px;
  flex-wrap: wrap;
}
.h2-sub { font-weight: 400; font-size: 0.78rem; color: #6e93a8; }

/* ---------- 主要輸入：放大好點好看 ---------- */
.main-input {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 16px;
}
@media (max-width: 480px) { .main-input { grid-template-columns: 1fr; } }
.input-field { display: flex; flex-direction: column; gap: 6px; }
.input-field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.03em;
}
.input-field input, .input-field select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #c4d8e6;
  border-radius: 12px;
  background: var(--surface);
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
  transition: border-color .15s, box-shadow .15s;
}
.input-field input::placeholder { font-weight: 400; letter-spacing: 0; color: #a9c2d1; font-size: 1.05rem; }
.input-field input:focus, .input-field select:focus {
  border-color: var(--brand);
  outline: none;
  box-shadow: 0 0 0 4px rgba(47,122,158,0.14);
}

.flute-filter {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 12px 0 0; font-size: 0.82rem;
}
#fluteFilterHint {
  background: #eaf3fa; border: 1px solid #cfe0ec; border-radius: 20px;
  padding: 3px 13px; color: #35617c;
}
#fluteFilterHint.active { background: #e9f7ef; border-color: #b3ddc4; color: #1e6a41; }
#fluteFilterHint.warn   { background: #fff6e8; border-color: #ecd3a6; color: #8a5b12; }
.flute-filter label { display: flex; align-items: center; gap: 5px; color: #5c7d90; cursor: pointer; }
.flute-filter input[type=checkbox] { width: auto; margin: 0; cursor: pointer; }

/* ---------- 主角：H值 / D值 ---------- */
.hero-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-top: 18px;
}
@media (max-width: 420px) { .hero-grid { grid-template-columns: 1fr; } }

.hero-card {
  background: linear-gradient(160deg, #ffffff 0%, #f2f8fd 100%);
  border: 1.5px solid #c2d9e8;
  border-radius: 20px;
  padding: 16px 18px 14px;
  text-align: center;
  cursor: pointer;
  position: relative;
  transition: transform .12s, box-shadow .18s, border-color .18s;
  box-shadow: 0 3px 12px rgba(23,56,75,0.05);
  user-select: none;
}
.hero-card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(23,56,75,0.12); border-color: var(--brand); }
.hero-card:active { transform: translateY(0); }
.hero-card.accent {
  background: linear-gradient(160deg, #fffdfb 0%, var(--accent-bg) 100%);
  border-color: var(--accent-ln);
}
.hero-card.accent:hover { border-color: var(--accent); }

.hero-label {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--ink-soft);
  letter-spacing: 0.06em;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  flex-wrap: wrap;
}
.hero-card.accent .hero-label { color: #8d5432; }
.hero-tag {
  font-size: 0.68rem; font-weight: 500; letter-spacing: 0;
  background: #e5eef5; color: #517a92;
  border-radius: 20px; padding: 1px 8px;
}
.hero-card.accent .hero-tag { background: #f6e4d6; color: #96562c; }

.hero-value {
  font-size: clamp(2.9rem, 7vw, 4.1rem);
  font-weight: 700;
  line-height: 1.05;
  color: #06344c;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  margin: 6px 0 0;
}
.hero-card.accent .hero-value { color: var(--accent); }
.hero-value.empty { color: #b9cfdc; font-weight: 500; }
.hero-card.accent .hero-value.empty { color: #dcc3b0; }
.hero-unit { font-size: 0.85rem; color: var(--ink-mute); font-weight: 500; margin-top: -2px; }

.hero-card::after {
  content: '⧉ 點一下複製';
  position: absolute; right: 10px; top: 9px;
  font-size: 0.62rem; color: #a8c2d2;
  opacity: 0; transition: opacity .18s;
}
.hero-card:hover::after { opacity: 1; }
.hero-card.copied { border-color: var(--good); box-shadow: 0 0 0 4px rgba(47,138,91,0.14); }

/* ---------- 輔助數字 ---------- */
.sub-results {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin-top: 14px;
}
.sub-item {
  flex: 1 1 150px;
  background: var(--surface);
  border: 1px solid #d9e6f0;
  border-radius: 14px;
  padding: 9px 14px;
  display: flex; align-items: baseline; gap: 8px;
}
.sub-label { font-size: 0.8rem; color: var(--ink-soft); font-weight: 500; }
.sub-label em { font-style: normal; font-size: 0.68rem; color: var(--ink-mute); display: block; }
.sub-value {
  margin-left: auto;
  font-size: 1.32rem; font-weight: 600; color: #12496a;
  font-variant-numeric: tabular-nums;
}
.sub-unit { font-size: 0.72rem; color: var(--ink-mute); }

.breakdown-wrap { margin-top: 12px; }
.breakdown-wrap summary {
  cursor: pointer; font-size: 0.82rem; color: #4d7591;
  padding: 5px 0; list-style: none; display: flex; align-items: center; gap: 6px;
}
.breakdown-wrap summary::before { content: '▸'; transition: transform .15s; }
.breakdown-wrap[open] summary::before { transform: rotate(90deg); }
.breakdown-wrap summary::-webkit-details-marker { display: none; }
.breakdown { font-size: 0.8rem; color: #35617c; line-height: 2; padding: 4px 0 2px; }
.breakdown .chip {
  display: inline-block; background: var(--surface);
  border: 1px solid #cfe0ec; border-radius: 20px;
  padding: 2px 11px; margin: 2px 5px 2px 0;
  font-variant-numeric: tabular-nums;
}
.breakdown .chip.miss { background: #fff3f2; border-color: #f0c4c0; color: #a3453c; }

.save-bar { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.save-bar input {
  flex: 1; min-width: 170px; padding: 11px 14px;
  border: 1px solid #c7d9e6; border-radius: 12px; font-size: 0.92rem;
  font-family: inherit;
}
.save-bar input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgba(47,122,158,0.12); }

.note {
  color: #4b6f88; font-size: 0.83rem; margin-top: 18px;
  border-top: 1px dashed #c3d7e3; padding-top: 13px;
}
.note-line { display: block; margin-top: 4px; font-size: 0.76rem; color: #6a8ca2; }

/* ---------- 參數表 ---------- */
.param-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.param-table th {
  text-align: left; font-weight: 600; color: #2d5068;
  background: #e9f1f8; padding: 9px 7px; font-size: 0.8rem;
  position: sticky; top: 0;
}
.param-table td { padding: 5px 4px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.param-table tr:last-child td { border-bottom: none; }
.param-table tbody tr:hover { background: #f1f7fc; }
.param-table input, .param-table select {
  width: 100%; padding: 7px 6px;
  border: 1px solid #c7d9e6; border-radius: 8px;
  background: var(--surface); font-size: 0.88rem; font-family: inherit;
  font-variant-numeric: tabular-nums; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.param-table input:focus, .param-table select:focus {
  border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgba(47,122,158,0.15);
}
.param-table input[type=number] { -moz-appearance: textfield; }
.group-select { font-size: 0.78rem !important; }
.table-wrap { overflow-x: auto; }
.section-gap { margin-top: 22px; }
.section-title { font-weight: 600; color: #17384b; margin-bottom: 8px; font-size: 0.95rem; }

.add-row {
  display: flex; gap: 7px; align-items: center; flex-wrap: wrap;
  margin-top: 12px; padding-top: 12px; border-top: 1px dashed #cfe0ec;
}
.add-row input, .add-row select {
  padding: 7px 9px; border: 1px solid #c7d9e6; border-radius: 9px;
  font-size: 0.82rem; font-family: inherit; background: var(--surface);
}
.settings-row {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
  margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line);
}
.settings-label { font-size: 0.83rem; color: #2b5f7a; font-weight: 500; }
.settings-row input {
  width: 88px; padding: 7px 9px; border: 1px solid #c3d6e5;
  border-radius: 9px; font-size: 0.9rem; font-family: inherit;
  font-variant-numeric: tabular-nums;
}
.settings-row input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgba(47,122,158,0.12); }
.settings-unit { font-size: 0.76rem; color: #5c8299; margin-left: -4px; }
.push-right { margin-left: auto; }
.reset-row { margin-top: 12px; text-align: right; }

/* ---------- 按鈕 ---------- */
button { cursor: pointer; font-family: inherit; font-size: 0.88rem; }
.btn-primary {
  background: var(--brand); border: 1px solid #266686; color: #fff;
  border-radius: 30px; padding: 11px 26px; font-weight: 600;
  transition: background .15s, transform .1s;
}
.btn-primary:hover { background: #26688a; }
.btn-primary:active { transform: scale(0.98); }
.btn-ghost {
  background: #e2edf6; border: 1px solid #b9d0e0; border-radius: 30px;
  padding: 7px 17px; font-weight: 500; color: var(--brand-dk); transition: background .15s;
}
.btn-ghost:hover { background: #d0e0ee; }
.btn-danger {
  background: #fdeeec; border: 1px solid #e9bcb6; border-radius: 30px;
  padding: 7px 17px; font-weight: 500; color: var(--danger); transition: background .15s;
}
.btn-danger:hover { background: #f9ddd9; }
.btn-mini { background: transparent; border: none; color: #b0736b; font-size: 1rem; padding: 0 4px; }
.btn-mini:hover { color: #d13b2b; }

/* ---------- 計算紀錄 ---------- */
.search-bar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.search-bar input {
  flex: 1; min-width: 150px; padding: 8px 13px;
  border: 1px solid #c7d9e6; border-radius: 10px; font-size: 0.88rem; font-family: inherit;
}
.search-bar input:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgba(47,122,158,0.12); }
.data-table { font-size: 0.83rem; }
.data-table td { white-space: nowrap; font-variant-numeric: tabular-nums; }
.data-table td.note-cell { white-space: normal; color: #40657d; font-variant-numeric: normal; }
.data-table .empty { text-align: center; color: var(--ink-mute); padding: 20px 0; }
.material-code {
  font-family: 'Consolas', 'Courier New', monospace; font-weight: 600;
  background: #e8f0f8; padding: 1px 9px; border-radius: 12px; color: #044b6b;
  letter-spacing: 0.05em;
}

.footer-hint {
  margin-top: 16px; font-size: 0.78rem; color: #4a7089;
  background: #f2f8fd; border: 1px solid #e0ecf5;
  border-radius: 14px; padding: 9px 18px; line-height: 1.8;
}
.footer-hint .dot { color: #a9c4d4; margin: 0 8px; }

.saved-flash { border-color: var(--good) !important; box-shadow: 0 0 0 3px rgba(47,138,91,0.16) !important; }

.toast {
  position: fixed; left: 50%; bottom: 30px;
  transform: translateX(-50%) translateY(20px);
  background: #0e3548; color: #eaf4fa;
  padding: 12px 24px; border-radius: 30px;
  font-size: 0.9rem; font-weight: 500;
  opacity: 0; pointer-events: none; transition: .25s;
  z-index: 999; max-width: 90vw;
  box-shadow: 0 8px 26px rgba(0,0,0,0.22);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: #7d2b23; }
.toast.good  { background: #1e6a41; }

/* ================= 可摺疊面板 ================= */
.panel { }
.panel-head {
  cursor: pointer; list-style: none;
  display: flex; align-items: center; gap: 8px;
}
.panel-head::-webkit-details-marker { display: none; }
.panel-head h2 { margin: 0; flex: 1; border-bottom: none; padding-bottom: 0; }
.panel-head::after {
  content: '▾'; color: #7ba0b6; font-size: 1.1rem;
  transition: transform .18s; flex-shrink: 0;
}
.panel[open] > .panel-head::after { transform: rotate(180deg); }
.panel > .panel-head { border-bottom: 1px solid #d6e3ed; padding-bottom: 12px; margin-bottom: 0; }
.panel[open] > .panel-head { margin-bottom: 16px; }
.panel-body { }

/* ================= 平板 / 手機 ================= */
@media (max-width: 900px) {
  body { padding: 0.75rem 0.5rem 2rem; font-size: 15px; }
  .container { border-radius: 18px; padding: 18px 16px 24px; }

  h1 { font-size: 1.4rem; }
  .sub { font-size: 0.85rem; margin-bottom: 16px; padding-left: 11px; }
  .badge { font-size: 0.74rem; padding: 4px 12px; margin-top: 4px; }
  .flex-between { gap: 8px; }

  .param-card { padding: 14px 13px 18px; border-radius: 16px; }
  .param-card h2 { font-size: 1.05rem; margin-bottom: 12px; padding-bottom: 10px; }
  .h2-sub { font-size: 0.7rem; }

  /* 主要輸入：拉大好按，字級 >=16px 避免 iOS 自動縮放 */
  .main-input { grid-template-columns: 1fr; gap: 12px; }
  .input-field input, .input-field select {
    font-size: 1.3rem; padding: 13px 14px; border-radius: 11px;
  }
  .input-field select { height: 52px; }

  /* H值 / D值 維持並排，兩個數字要同時看得到 */
  .hero-grid { grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
  .hero-card { padding: 12px 8px 10px; border-radius: 16px; }
  .hero-value { font-size: clamp(2.4rem, 13vw, 3.4rem); }
  .hero-label { font-size: 0.82rem; gap: 4px; }
  .hero-tag { font-size: 0.6rem; padding: 1px 6px; }
  .hero-unit { font-size: 0.75rem; }
  .hero-card::after { display: none; }          /* 觸控裝置不顯示 hover 提示 */

  .sub-results { gap: 7px; }
  .sub-item { flex: 1 1 100%; padding: 8px 12px; border-radius: 11px; }
  .sub-value { font-size: 1.18rem; }

  .save-bar { gap: 8px; }
  .save-bar input { font-size: 16px; padding: 12px 13px; }
  .btn-primary { width: 100%; padding: 13px 20px; }

  .flute-filter { font-size: 0.76rem; gap: 8px; }
  #fluteFilterHint { padding: 3px 10px; }

  /* 參數表：橫向捲動，不要壓扁 */
  .table-wrap { -webkit-overflow-scrolling: touch; margin: 0 -13px; padding: 0 13px; }
  #paramTable { min-width: 520px; }
  #materialTable { min-width: 340px; }
  .param-table th { font-size: 0.75rem; padding: 8px 6px; }
  .param-table input, .param-table select { font-size: 16px; padding: 8px 6px; }
  .btn-mini { font-size: 1.25rem; padding: 6px 8px; }   /* 刪除鈕加大好點 */

  .add-row { gap: 6px; }
  .add-row input, .add-row select { font-size: 16px; padding: 9px 10px; flex: 1 1 auto; min-width: 0; }
  .add-row button { flex: 1 1 100%; padding: 10px; }

  .settings-row { gap: 8px; }
  .settings-row input { font-size: 16px; padding: 9px; width: 100px; }
  .push-right { margin-left: 0; flex: 1 1 100%; padding: 10px; }
  .search-bar input { font-size: 16px; padding: 10px 13px; }
  .search-bar button { flex: 1; }

  .footer-hint { font-size: 0.73rem; padding: 9px 14px; line-height: 1.7; }
  .footer-hint .dot { display: block; height: 0; overflow: hidden; margin: 0; }

  /* 計算紀錄：表格改成一筆一張卡 */
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr {
    background: #fff; border: 1px solid #dde8f1; border-radius: 13px;
    padding: 10px 13px; margin-bottom: 9px; position: relative;
  }
  .data-table tr:hover { background: #fff; }
  .data-table td {
    border: none; padding: 3px 0; white-space: normal;
    display: flex; align-items: baseline; gap: 8px;
  }
  .data-table td::before {
    content: attr(data-label);
    font-size: 0.74rem; color: #6e93a8; font-weight: 500;
    min-width: 62px; flex-shrink: 0;
  }
  .data-table td.cell-hero { font-size: 1.1rem; font-weight: 700; color: #06344c; }
  .data-table td.cell-del {
    position: absolute; top: 6px; right: 8px; width: auto; padding: 0;
  }
  .data-table td.cell-del::before { content: ''; min-width: 0; }
  .data-table td.cell-time { font-size: 0.74rem; color: #7d9db0; }
  .data-table td.cell-time::before { content: ''; min-width: 0; }
  .data-table .empty { display: block; text-align: center; }
  .data-table tr:has(.empty) { border: none; background: transparent; }
}

@media (max-width: 380px) {
  .hero-value { font-size: clamp(2.1rem, 14vw, 2.9rem); }
  .hero-label { font-size: 0.76rem; }
  .container { padding: 14px 11px 20px; }
}
