/* Navigator Calculator - Style 1 Gold (Standards 2.4). Light is the default; dark is a remembered choice via data-theme. */
@font-face { font-family: 'JetBrains Mono'; src: url('fonts/jetbrains-mono-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Cormorant Garamond'; src: url('fonts/cormorant-garamond-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Plus Jakarta Sans'; src: url('fonts/plus-jakarta-sans-latin-400-normal.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Plus Jakarta Sans'; src: url('fonts/plus-jakarta-sans-latin-600-normal.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Plus Jakarta Sans'; src: url('fonts/plus-jakarta-sans-latin-700-normal.woff2') format('woff2'); font-weight: 700 800; font-style: normal; font-display: swap; }

:root {
  --f-display: 'Cormorant Garamond', Georgia, 'Times New Roman', serif;
  --f-body: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --f-mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
  --halo-size: 70px; --petal-size: 56px; --radius-inner: 112px;
  --splash-bg: #09443B;
  --r: 14px;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F4EEDF; --surface: #F9F4E8; --alt: #EBE1CE; --ink: #1D1917; --muted: #675F54;
  --primary: #C9973A; --primary-ink: #765619; --on-primary: #1A140C;
  --teal: #2A7A6E; --teal-ink: #1A524A; --danger: #B03A2E; --danger-ink: #A5352A;
  --line: #D9CDB3; --edge: #857862; --shadow: 0 6px 22px rgba(60,40,10,.10);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0F1010; --surface: #171919; --alt: #202323; --ink: #F2EDE2; --muted: #A7A299;
  --primary: #C9973A; --primary-ink: #F0CF78; --on-primary: #1A140C;
  --teal: #2A7A6E; --teal-ink: #7FD0C1; --danger: #E5604F; --danger-ink: #F29184;
  --line: #2C3030; --edge: #7A7468; --shadow: 0 6px 22px rgba(0,0,0,.5);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.5 var(--f-body); min-height: 100dvh; }
.mono { font-family: var(--f-mono); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
:focus-visible { outline: 3px solid var(--primary-ink); outline-offset: 2px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }
h1, h2 { font-family: var(--f-display); font-weight: 600; margin: 0; }

/* Buttons: one style family */
.btn { min-height: 44px; min-width: 44px; padding: 8px 14px; border: 1px solid var(--edge); border-radius: 12px; background: var(--surface); color: var(--ink); font-weight: 600; }
.btn:active { transform: scale(.97); }
.btn.ghost { background: transparent; }
.btn.icon { padding: 8px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn[aria-pressed="true"] { background: var(--alt); border-color: var(--primary-ink); color: var(--primary-ink); }

/* Island reference layout (Standards C.2) */
:root { --safe-top: env(safe-area-inset-top, 0px); --island-h: 40px; --island-gap: 8px; --island-top: max(10px, var(--safe-top)); --island-strip: calc(var(--island-top) + var(--island-h) + var(--island-gap)); --island-bg: #1A1208; --island-ink: #FBF5EA; --island-ok: #4ADE80; --island-warn: #FBBF24; --island-off: #F87171; }
html.has-island body { padding-top: var(--island-strip); }
html.has-island::before { content: ''; position: fixed; top: 0; left: 0; right: 0; height: var(--island-strip); background: var(--bg); z-index: 199; pointer-events: none; }
.topbar { position: sticky; top: 0; padding-top: var(--safe-top); z-index: 80; background: var(--bg); }
html.has-island .topbar { top: var(--island-strip); padding-top: 0; }
.island { box-sizing: border-box; position: fixed; top: var(--island-top); left: 50%; transform: translateX(-50%); z-index: 200; width: max-content; max-width: min(440px, calc(100vw - 2rem)); min-height: var(--island-h); background: var(--island-bg); color: var(--island-ink); border: 0; border-radius: 999px; box-shadow: 0 8px 32px rgba(0,0,0,.28), inset 0 0 0 1px rgba(255,255,255,.14), inset 0 1px 0 rgba(255,255,255,.08); transition: border-radius .35s cubic-bezier(.175,.885,.32,1.275), padding .35s ease; }
.island[hidden] { display: none; }
.island.expanded { border-radius: 22px; }
.island-toggle { position: relative; display: flex; align-items: center; gap: 10px; width: 100%; min-height: var(--island-h); padding: 8px 18px; background: none; border: 0; color: inherit; font-family: inherit; font-size: 13px; font-weight: 600; line-height: 1.3; text-align: left; cursor: pointer; }
.island-toggle::after { content: ''; position: absolute; inset: -2px 0; }
.island-toggle[aria-disabled="true"] { cursor: default; }
.island-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 2px; border-radius: 999px; }
.island-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.island.expanded .island-text { white-space: normal; }
.island-dot { width: 9px; height: 9px; flex: none; border-radius: 50%; animation: island-pulse 2s ease-in-out infinite; }
.island-dot[data-state="ok"] { background: var(--island-ok); box-shadow: 0 0 0 3px rgba(74,222,128,.25); }
.island-dot[data-state="warn"] { background: var(--island-warn); box-shadow: 0 0 0 3px rgba(251,191,36,.25); }
.island-dot[data-state="off"] { background: var(--island-off); box-shadow: 0 0 0 3px rgba(248,113,113,.25); animation: none; }
.island-detail { padding: 0 18px 12px 37px; font-size: 12px; font-weight: 500; color: #C3BCB2; }
@keyframes island-pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(1.15); opacity: .85; } }
html.has-island .modal { max-height: calc(100dvh - var(--island-strip) - 16px); }

/* Header */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-left: 14px; padding-right: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 4px 8px 4px 0; background: none; border: 0; text-align: left; }
.crest { width: 40px; height: 40px; border-radius: 50%; display: block; }
.wordmark { font-family: var(--f-display); font-weight: 600; font-size: 1.35rem; letter-spacing: .01em; }
.badges { display: flex; gap: 6px; }
.badge { padding: 5px 10px; border-radius: 999px; background: var(--alt); color: var(--ink); font-size: .75rem; font-weight: 700; }
.badge.mono { color: var(--teal-ink); }

/* Menu */
.menu { position: fixed; z-index: 150; left: 10px; top: calc(var(--safe-top) + 64px); width: min(360px, calc(100vw - 20px)); max-height: calc(100dvh - 90px); overflow: auto; background: var(--surface); border: 1px solid var(--edge); border-radius: var(--r); box-shadow: var(--shadow); padding: 6px; }
html.has-island .menu { top: calc(var(--island-strip) + 64px); }
.menu-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px; flex-wrap: wrap; }
.menu-label { color: var(--muted); font-size: .85rem; font-weight: 600; }
.menu-item { width: 100%; min-height: 44px; text-align: left; background: none; border: 0; padding: 8px 8px; border-radius: 10px; font-weight: 600; display: flex; justify-content: space-between; align-items: center; }
.menu-item:hover { background: var(--alt); }
.menu-jumps, .stepper { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
kbd { font-family: var(--f-mono); font-size: .75rem; color: var(--muted); border: 1px solid var(--edge); border-radius: 6px; padding: 1px 6px; }

/* Layout */
.app { max-width: 1100px; margin: 0 auto; padding: 14px 14px calc(var(--halo-size) + 60px + env(safe-area-inset-bottom, 0px)); }
.ws-switch { display: flex; flex-wrap: wrap; gap: 8px; padding-bottom: 4px; margin-bottom: 12px; }
.ws-switch .btn { white-space: nowrap; flex: 0 0 auto; }
.card, .panel { background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); min-width: 0; }
.display { position: relative; padding: 18px 16px 12px; margin-bottom: 14px; overflow: hidden; }
.accent-bar { position: absolute; top: 0; left: 0; right: 0; height: 4px; background: linear-gradient(90deg, var(--primary), var(--teal)); }
.display-meta { min-height: 48px; margin-bottom: 4px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: .75rem; font-weight: 700; letter-spacing: .06em; }
.display-actions { display: flex; gap: 8px; align-items: center; }
.mem { color: var(--teal-ink); }
.expr { width: 100%; min-height: 52px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--ink); font-size: clamp(1.25rem, 4vw, 1.9rem); padding: 8px 0; outline: none; }
.expr:focus-visible { outline: 3px solid var(--primary-ink); outline-offset: 2px; }
.answer { min-height: 44px; text-align: right; font-size: clamp(1.4rem, 4.2vw, 2.1rem); font-weight: 700; overflow-wrap: anywhere; padding-top: 6px; }
.answer.error { font-family: var(--f-body); font-size: 1rem; color: var(--danger-ink); font-weight: 600; text-align: left; }
.answer-label { text-align: right; color: var(--muted); font-size: .78rem; min-height: 20px; }
.workarea { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); gap: 14px; align-items: start; }
.panel { padding: 14px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel-title { font-size: 1.25rem; margin-bottom: 10px; }
.subrow { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.subrow .btn { min-width: 48px; padding: 6px 10px; }
.keypad { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 7px; }
.key { min-height: 48px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink); font-weight: 600; padding: 6px 2px; overflow-wrap: anywhere; }
.key:active { transform: scale(.96); }
.key.fn { background: var(--alt); color: var(--primary-ink); }
.key.danger { color: var(--danger-ink); }
.key.eq { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 800; }
.key.wide { grid-column: span 2; }
.tools { display: grid; gap: 10px; }
.tool-card { border: 1px solid var(--line); border-radius: 13px; padding: 12px; background: var(--bg); }
.tool-card h3 { margin: 0 0 4px; font-family: var(--f-display); font-size: 1.1rem; }
.tool-card p { margin: 0 0 8px; color: var(--muted); font-size: .85rem; }
.row { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.field { min-height: 44px; min-width: 0; width: 100%; border: 1px solid var(--edge); border-radius: 10px; padding: 8px 10px; background: var(--surface); color: var(--ink); }
.field.sm { flex: 1; width: auto; min-width: 72px; }
.lbl { font-size: .8rem; color: var(--muted); }
.output { font-family: var(--f-mono); font-size: .85rem; white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 8px; }
.output.error { color: var(--danger-ink); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { font-family: var(--f-mono); font-size: .75rem; background: var(--alt); padding: 5px 9px; border-radius: 999px; }
.notice { border: 1px solid var(--line); border-left: 4px solid var(--teal); border-radius: 10px; padding: 10px; font-size: .85rem; background: var(--surface); }
canvas { display: block; width: 100%; height: 210px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table { border-collapse: collapse; width: 100%; font-size: .85rem; font-family: var(--f-mono); }
td, th { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; }
td:first-child, th:first-child { text-align: left; }
.table-scroll { overflow: auto; max-width: 100%; }
.history-panel { margin-top: 14px; }
.history-list { display: grid; gap: 7px; max-height: 320px; overflow: auto; }
.history-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; text-align: left; background: var(--bg); width: 100%; }
.history-item .expr-text { font-family: var(--f-mono); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item strong { font-family: var(--f-mono); font-size: .85rem; white-space: nowrap; }
.empty { color: var(--muted); font-size: .9rem; margin: 0; }
.footer { color: var(--muted); font-size: .8rem; text-align: center; margin: 18px 0 0; }

/* Halo (Standards 5): four layers, upward petals, size tokens */
.halo { position: fixed; left: 50%; right: auto; top: auto; bottom: calc(22px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); width: var(--halo-size); height: var(--halo-size); z-index: 120; border-radius: 50%; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; animation: breathe 3.6s ease-in-out infinite; }
.halo.dragging { cursor: grabbing; animation: none; }
.halo.open { animation: none; }
.halo-ring { position: absolute; inset: -2px; border-radius: 50%; background: conic-gradient(from 0deg, var(--primary), var(--teal), var(--primary), #E8C76F, var(--teal), var(--primary)); animation: spin 3.4s linear infinite; }
.halo.open .halo-ring { animation-duration: .7s; }
.halo-core { position: absolute; inset: 3px; width: calc(100% - 6px); height: calc(100% - 6px); border-radius: 50%; object-fit: cover; pointer-events: none; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes breathe { 0%,100% { filter: drop-shadow(0 4px 6px rgba(0,0,0,.28)) drop-shadow(0 0 4px rgba(201,151,58,.35)); } 50% { filter: drop-shadow(0 4px 6px rgba(0,0,0,.28)) drop-shadow(0 0 12px rgba(201,151,58,.7)); } }
.halo-backdrop { position: fixed; inset: 0; z-index: 110; background: rgba(15,16,16,.35); }
.halo-petals { position: fixed; inset: 0; z-index: 130; pointer-events: none; }
.petal { position: absolute; width: var(--petal-size); height: var(--petal-size); margin: calc(var(--petal-size) / -2) 0 0 calc(var(--petal-size) / -2); border-radius: 50%; border: 1px solid var(--edge); background: var(--surface); color: var(--primary-ink); display: grid; place-items: center; padding: 0; pointer-events: none; opacity: 0; transform: translate(var(--from-x, 0), var(--from-y, 0)) scale(.5); transition: transform .38s cubic-bezier(0.34, 1.56, 0.64, 1), opacity .25s ease; }
.petal.out { opacity: 1; transform: translate(0, 0) scale(1); }
.petal.live { pointer-events: auto; }
.petal svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.petal[aria-current="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.petal-label { position: absolute; top: 100%; margin-top: 3px; left: 50%; transform: translateX(-50%); font-size: .7rem; font-weight: 700; background: #1A1208; color: #FBF5EA; padding: 2px 7px; border-radius: 8px; white-space: nowrap; }
.petal.col .petal-label { top: 50%; left: 100%; margin: 0 0 0 6px; transform: translateY(-50%); }

/* Modals, tour, update bar */
.modal-wrap { position: fixed; inset: 0; z-index: 300; background: rgba(15,16,16,.55); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); border-radius: 20px 20px 0 0; border: 1px solid var(--edge); padding: 18px; width: min(100%, 680px); max-height: 85dvh; overflow: auto; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.modal-head h2 { font-size: 1.6rem; }
.modal-body p { margin: 6px 0; }
.modal-body ul { padding-left: 20px; }
.modal-body li { margin: 4px 0; }
.about-lines p { margin: 2px 0; }
.palette-list { display: grid; gap: 4px; margin-top: 8px; max-height: 50dvh; overflow: auto; }
.palette-list button { text-align: left; min-height: 44px; padding: 8px 10px; background: none; border: 1px solid transparent; border-radius: 10px; }
.palette-list button:hover, .palette-list button:focus-visible { background: var(--alt); }
.tour { position: fixed; inset: 0; z-index: 400; background: rgba(15,16,16,.6); display: flex; align-items: center; justify-content: center; padding: 16px; pointer-events: auto; }
.tour-card { background: var(--surface); border: 1px solid var(--edge); border-radius: 18px; padding: 18px; max-width: 420px; width: 100%; }
.tour-card h2 { font-size: 1.6rem; margin: 4px 0; }
.tour-step { color: var(--muted); font-size: .75rem; margin: 0; }
.tour-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.tour-target { outline: 4px solid var(--primary); outline-offset: 4px; border-radius: 14px; position: relative; z-index: 401; }
.update-bar { position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom, 0px)); z-index: 350; display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--edge); border-radius: 14px; padding: 8px 12px; box-shadow: var(--shadow); }
.update-bar span { flex: 1; font-weight: 600; }

/* Splash (Standards 17.1): plate colour = manifest colour; no credit line */
.splash { position: fixed; inset: 0; z-index: 1000; background: var(--splash-bg); color: #F2EDE2; display: grid; place-items: center; transition: opacity .6s ease; }
.splash.done { opacity: 0; pointer-events: none; }
.splash-inner { width: min(90vw, 420px); text-align: center; }
@media (min-width: 480px) { .splash-inner { width: min(90vw, 520px); } }

.splash-logo { width: 100%; height: auto; display: block; opacity: 0; transform: scale(.85); animation: logo-in 1.8s ease forwards; }
.splash-title, .splash-tag, .splash-bar, .splash-status { opacity: 0; animation: fade-in .5s ease forwards; }
.splash-title { font-size: 2rem; margin-top: 6px; animation-delay: 1.3s; }
.splash-tag { margin: 4px 0 14px; color: #D9D2C3; animation-delay: 1.55s; }
.splash-bar { height: 6px; border-radius: 6px; background: rgba(255,255,255,.18); overflow: hidden; animation-delay: 1.7s; }
.splash-bar span { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #C9973A, #E8C76F); }
.splash-status { font-family: var(--f-mono); font-size: .8rem; color: #D9D2C3; margin: 8px 0 0; min-height: 1.4em; animation-delay: 1.7s; }
.splash-skip { position: absolute; top: calc(14px + var(--safe-top)); right: 14px; min-height: 44px; min-width: 64px; padding: 8px 16px; border-radius: 999px; border: 1px solid rgba(255,255,255,.5); background: rgba(0,0,0,.25); color: #F2EDE2; font-weight: 700; }
@keyframes logo-in { to { opacity: 1; transform: scale(1); } }
@keyframes fade-in { to { opacity: 1; } }

@media (max-width: 760px) { .workarea { grid-template-columns: 1fr; } .wordmark { font-size: 1.15rem; } .badges .badge:first-child { display: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
  .splash-logo, .splash-title, .splash-tag, .splash-bar, .splash-status { opacity: 1; transform: none; }
  .splash { transition: opacity .6s ease !important; }
}
