/* ============================================================================
 * 16OC styles (light, high-contrast field theme)
 * ==========================================================================*/
:root {
  --bg: #eceff3;
  --panel: #ffffff;
  --panel-2: #e4e9ef;
  --line: #d3dae2;
  --key: #ffffff;
  --key-2: #f1f4f8;
  --text: #10151b;
  --muted: #57616e;
  --accent: #d9641a;          /* construction orange, AA on white */
  --accent-ink: #ffffff;
  --op-bg: #f0f3f7;
  --op-ink: #b04c0d;
  --eq-bg: #d9641a;
  --eq-ink: #ffffff;
  --green: #1f8a54;
  --danger: #c62828;
  --radius: 13px;
  --shadow: 0 1px 2px rgba(16,21,27,.08), 0 1px 3px rgba(16,21,27,.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* Sunlight mode: maximum contrast for direct outdoor light */
body.hc {
  --bg: #000000;
  --panel: #0a0a0a;
  --panel-2: #161616;
  --line: #333333;
  --key: #111111;
  --key-2: #1c1c1c;
  --text: #ffe000;
  --muted: #c9b100;
  --accent: #ffe000;
  --accent-ink: #000000;
  --op-bg: #1c1c1c;
  --op-ink: #ffe000;
  --eq-bg: #ffe000;
  --eq-ink: #000000;
  --danger: #ff5a5a;
  --shadow: none;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  overscroll-behavior: none;
}
body { display: flex; flex-direction: column; user-select: none; }
svg { display: block; }

/* ---------- App shell ---------- */
#app { flex: 1; display: flex; flex-direction: column; overflow: hidden; max-width: 560px; width: 100%; margin: 0 auto; }
.screen { flex: 1; overflow-y: auto; display: none; -webkit-overflow-scrolling: touch; }
.screen.active { display: flex; flex-direction: column; }

/* ---------- Header ---------- */
header {
  padding: 12px 16px; display: flex; align-items: center; gap: 11px;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
header .logo { width: 34px; height: 34px; color: var(--accent); }
header h1 { font-size: 18px; margin: 0; font-weight: 800; letter-spacing: .5px; }
header .sub { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* ---------- Bottom nav ---------- */
nav.tabs {
  display: flex; background: var(--panel);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
nav.tabs button {
  flex: 1; background: none; border: 0; color: var(--muted);
  padding: 9px 4px 7px; font-size: 10.5px; font-weight: 600; display: flex; flex-direction: column; align-items: center; gap: 3px;
  cursor: pointer; font-family: inherit;
}
nav.tabs button .ic { width: 23px; height: 23px; }
nav.tabs button.active { color: var(--accent); }

/* ---------- Calculator ---------- */
.calc-wrap { display: flex; flex-direction: column; height: 100%; }
.display {
  padding: 14px 18px 12px; background: var(--panel);
  display: flex; flex-direction: column; gap: 3px; min-height: 118px;
  justify-content: flex-end; border-bottom: 1px solid var(--line);
}
.display .entry { font-size: 20px; font-weight: 600; color: var(--text); min-height: 26px; text-align: right; word-break: break-word; font-variant-numeric: tabular-nums; }
.display .result { font-size: clamp(32px, 9.5vw, 46px); font-weight: 800; text-align: right; line-height: 1.05; word-break: break-word; font-variant-numeric: tabular-nums; }
.display .result.err { color: var(--danger); font-size: 21px; font-weight: 700; }
.display .subres { font-size: 12.5px; color: var(--muted); text-align: right; min-height: 16px; }
.badges { display: flex; gap: 6px; justify-content: flex-end; min-height: 17px; flex-wrap: wrap; }
.badge { font-size: 10px; font-weight: 700; background: var(--panel-2); color: var(--accent); padding: 1px 8px; border-radius: 20px; }

.keys { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 9px; align-content: stretch; }
.keys.fn { flex: 0 0 auto; padding-bottom: 0; }
button.key {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--key); color: var(--text);
  font-size: 21px; font-weight: 700; font-family: inherit; cursor: pointer;
  display: grid; place-items: center; min-height: 56px; transition: filter .06s, transform .04s;
  position: relative; box-shadow: var(--shadow);
}
button.key:active { transform: translateY(1px); filter: brightness(.94); }
body.hc button.key:active { filter: brightness(1.4); }
button.key small { position: absolute; top: 5px; right: 8px; font-size: 9px; color: var(--muted); font-weight: 600; }
button.key.unit { background: var(--key-2); color: var(--accent); font-size: 15px; }
button.key.op { background: var(--op-bg); color: var(--op-ink); font-size: 25px; }
button.key.eq { background: var(--eq-bg); color: var(--eq-ink); font-size: 27px; border-color: transparent; }
button.key.fnk { background: var(--key-2); color: var(--muted); font-size: 13px; min-height: 42px; box-shadow: none; }
button.key.fnk.amber { color: var(--accent); }

/* ---------- Tools grid ---------- */
.tools-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 11px; padding: 12px 14px; }
.tool-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 13px; cursor: pointer; display: flex; flex-direction: column; gap: 7px; box-shadow: var(--shadow);
}
.tool-card:active { filter: brightness(.97); }
.tool-card .tic { width: 26px; height: 26px; color: var(--accent); }
.tool-card .tname { font-weight: 800; font-size: 14px; }
.tool-card .tdesc { font-size: 11.5px; color: var(--muted); line-height: 1.35; }
.section-label { padding: 15px 16px 2px; font-size: 11.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 800; }

/* ---------- Tool detail ---------- */
.tool-detail { padding: 6px 16px 90px; }
.tool-detail h2 { font-size: 20px; margin: 8px 0 2px; display: flex; align-items: center; gap: 9px; }
.tool-detail h2 .th { width: 24px; height: 24px; color: var(--accent); }
.tool-detail .desc { color: var(--muted); font-size: 13px; margin-bottom: 16px; line-height: 1.4; }
.back-bar { display: flex; align-items: center; gap: 8px; padding: 12px 12px 2px; }
.back-bar button { background: var(--panel-2); border: 0; color: var(--accent); font-size: 14px; font-weight: 700; padding: 8px 15px; border-radius: 10px; font-family: inherit; cursor: pointer; }
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; font-weight: 700; }
.field .hint { font-size: 11px; color: var(--muted); margin-top: 3px; opacity: .85; }
.field input, .field select {
  width: 100%; background: var(--panel); border: 1px solid var(--line); color: var(--text);
  padding: 12px; border-radius: 10px; font-size: 16px; font-family: inherit; outline: none;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
/* compound feet-inch input */
.len-row { display: flex; gap: 7px; align-items: stretch; }
.len-row .seg { flex: 1; position: relative; }
.len-row .seg.frac { flex: 1.3; }
.len-row input { text-align: center; padding-right: 20px; }
.len-row .seg .u { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); font-size: 13px; color: var(--muted); font-weight: 700; pointer-events: none; }
.len-row select { padding: 12px 8px; }

.results { background: var(--panel); border-radius: var(--radius); padding: 2px 16px; margin-top: 8px; border: 1px solid var(--line); box-shadow: var(--shadow); }
.results .row { display: flex; justify-content: space-between; align-items: baseline; padding: 11px 0; border-bottom: 1px solid var(--line); gap: 12px; }
.results .row:last-child { border-bottom: 0; }
.results .row .rl { font-size: 13px; color: var(--muted); }
.results .row .rv { font-size: 16px; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.results .row.big .rv { color: var(--accent); font-size: 19px; }
.results-empty { color: var(--muted); font-size: 13px; padding: 14px 0; text-align: center; }

/* ---------- Tape ---------- */
.tape-list { padding: 8px 16px 90px; }
.tape-item { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; box-shadow: var(--shadow); }
.tape-item .tl { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.tape-item .tr { font-size: 17px; font-weight: 800; color: var(--accent); text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Settings ---------- */
.settings { padding: 10px 16px 90px; }
.settings .field { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.settings h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); margin: 16px 4px 8px; font-weight: 800; }
.about { color: var(--muted); font-size: 12.5px; line-height: 1.6; padding: 4px; }
.about strong { color: var(--text); }

/* ---------- Bottom sheets ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(16,21,27,.45); display: none; z-index: 40; align-items: flex-end; }
.sheet-backdrop.show { display: flex; }
.sheet { background: var(--panel); width: 100%; max-width: 560px; margin: 0 auto; border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + var(--safe-b)); max-height: 82%; overflow-y: auto; }
.sheet h3 { margin: 0 0 12px; font-size: 16px; }
.mem-slot { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.mem-slot .mlabel { font-weight: 800; width: 34px; }
.mem-slot .mval { flex: 1; font-size: 14px; color: var(--accent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.mem-slot button { background: var(--key-2); border: 1px solid var(--line); color: var(--text); padding: 8px 11px; border-radius: 8px; font-size: 11px; font-weight: 700; font-family: inherit; cursor: pointer; }
.sheet .close { width: 100%; margin-top: 14px; background: var(--panel-2); color: var(--text); border: 0; padding: 12px; border-radius: 10px; font-family: inherit; font-size: 14px; font-weight: 700; }

/* ---------- voice mic button ---------- */
.display { position: relative; }
.mic { position: absolute; top: 12px; left: 14px; width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--key-2); color: var(--accent); display: grid; place-items: center; cursor: pointer; padding: 9px; }
.mic svg { width: 100%; height: 100%; }
.mic:active { filter: brightness(.94); }
.mic.listening { background: var(--accent); color: var(--accent-ink); animation: micpulse 1s ease-in-out infinite; }
@keyframes micpulse { 0%,100% { box-shadow: 0 0 0 0 rgba(217,100,26,.5); } 50% { box-shadow: 0 0 0 8px rgba(217,100,26,0); } }
.mic.hidden { display: none; }

/* ---------- QR decal ---------- */
.qr-holder { width: 100%; max-width: 280px; margin: 4px auto 10px; background: #fff; padding: 12px; border-radius: 12px; border: 1px solid var(--line); }
.qr-holder svg { width: 100%; height: auto; display: block; }
.qr-cap { font-size: 12.5px; color: var(--muted); text-align: center; line-height: 1.45; margin: 0 0 14px; }

/* fraction chips */
.frac-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.frac-grid button {
  background: var(--key-2); border: 1px solid var(--line); color: var(--text);
  padding: 15px 4px; border-radius: 11px; font-size: 17px; font-weight: 800; font-family: inherit; cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.frac-grid button:active { filter: brightness(.95); }

/* ---------- tape action bar ---------- */
.tape-actions { display: flex; gap: 8px; }
.tape-actions button { background: var(--panel-2); border: 0; color: var(--accent); padding: 6px 12px; border-radius: 8px; font-family: inherit; font-weight: 700; font-size: 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 5px; }
.tape-actions button svg { width: 14px; height: 14px; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 22px; font-size: 13px; font-weight: 700; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; max-width: 88%; text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- shared-view banner ---------- */
.shared-banner { display: none; background: var(--accent); color: var(--accent-ink); padding: 9px 16px; align-items: center; gap: 10px; font-size: 12.5px; font-weight: 600; }
.shared-banner.show { display: flex; }
.shared-banner button { margin-left: auto; background: rgba(255,255,255,.25); color: var(--accent-ink); border: 0; padding: 6px 12px; border-radius: 8px; font-weight: 700; font-family: inherit; cursor: pointer; }

/* ---------- print / PDF export ---------- */
#printArea { display: none; }
@media print {
  #app, .sheet-backdrop, #toast { display: none !important; }
  #printArea { display: block !important; color: #000; background: #fff; padding: 28px 30px; font-family: -apple-system, Roboto, sans-serif; }
  #printArea .p-head { display: flex; align-items: center; gap: 10px; border-bottom: 2px solid #d9641a; padding-bottom: 10px; margin-bottom: 6px; }
  #printArea .p-head .sq { width: 30px; height: 30px; color: #d9641a; }
  #printArea .p-title { font-size: 22px; font-weight: 800; }
  #printArea .p-meta { font-size: 12px; color: #555; margin: 8px 0 16px; display: flex; justify-content: space-between; }
  #printArea .p-meta .line { border-bottom: 1px solid #999; min-width: 180px; display: inline-block; }
  #printArea table { width: 100%; border-collapse: collapse; font-size: 13px; }
  #printArea th { text-align: left; color: #555; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; border-bottom: 1px solid #ccc; padding: 6px 4px; }
  #printArea td { padding: 7px 4px; border-bottom: 1px solid #eee; }
  #printArea td.r { text-align: right; font-weight: 700; }
  #printArea .p-foot { margin-top: 24px; font-size: 10px; color: #888; }
  #printArea .qr-decal { text-align: center; padding-top: 30px; }
  #printArea .qr-decal svg { width: 60%; max-width: 380px; height: auto; }
  #printArea .qr-decal .dt { font-size: 30px; font-weight: 800; margin: 18px 0 4px; }
  #printArea .qr-decal .ds { font-size: 17px; color: #333; }
  #printArea .qr-decal .du { font-size: 15px; color: #d9641a; font-weight: 700; margin-top: 10px; }
}

/* ---------- install gate (PWA-only) ---------- */
.install-gate { position: fixed; inset: 0; z-index: 1000; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 28px 24px; overflow-y: auto; }
.install-gate[hidden] { display: none; }
.gate-card { max-width: 400px; width: 100%; text-align: center; }
.gate-logo { width: 60px; height: 60px; color: var(--accent); margin: 0 auto 14px; }
.gate-card h1 { font-size: 30px; font-weight: 800; letter-spacing: 1px; margin: 0; }
.gate-card .tag { color: var(--muted); font-size: 12.5px; margin: 3px 0 24px; }
.gate-card h2 { font-size: 19px; margin: 0 0 8px; }
.gate-card p { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 22px; }
.gate-btn { max-width: 260px; margin: 0 auto 18px; }
.gate-steps { text-align: left; display: flex; flex-direction: column; gap: 15px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 18px; box-shadow: var(--shadow); }
.gate-step { display: flex; align-items: center; gap: 12px; font-size: 14px; color: var(--text); }
.gate-step .gs-ic { width: 26px; height: 26px; color: var(--accent); flex: 0 0 26px; }
.gate-step b { font-weight: 700; }
.gate-note { font-size: 12px; color: var(--muted); margin-top: 16px; }

.install-banner { display: none; background: var(--panel-2); padding: 10px 16px; align-items: center; gap: 10px; font-size: 12.5px; border-bottom: 1px solid var(--line); }
.install-banner.show { display: flex; }
.install-banner button { margin-left: auto; background: var(--accent); color: var(--accent-ink); border: 0; padding: 8px 14px; border-radius: 8px; font-weight: 700; font-family: inherit; }
.install-banner .x { margin-left: 0; background: none; color: var(--muted); padding: 4px 8px; }
