:root {
  --sky: #8FDCF2; --sea: #006C99; --sea-light: #0B8AB8; --lagoon: #17BFD0; --foam: #E8F8FA;
  --pale: #D3F4F7; --card: #FFFFFF; --ink: #07354A; --muted: #35596B; --alert: #B3261E;
  --coral: #F0503C; --field: #F4FCFD; --field-edge: #9ADCE5; --tint: #006C99; --tank-edge: #07354A;
  --bar: #FFFFFF; --save: #006C99; --save-ink: #FFFFFF; --sun: #FFC83D; --on-sun: #07354A;
  --plate: #06324A; --on-sea-soft: #CFF3F7;
}
:root[data-theme="dark"] {
  --sky: #12375A; --sea: #0A4F73; --sea-light: #10324A; --lagoon: #0F8FA6; --foam: #071B2B;
  --pale: #1B4F6B; --card: #10324A; --ink: #EAF7FA; --muted: #A9C6D3; --alert: #FF8A75;
  --coral: #FF7A66; --field: #0B2638; --field-edge: #2B6C8A; --tint: #8FDCF2; --tank-edge: #CFEAF2;
  --bar: #0B2638; --save: #17BFD0; --save-ink: #07354A;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--foam); color: var(--ink); overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { height: 100dvh; display: flex; flex-direction: column; }
.page { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* Header and logo */
.header { position: relative; height: calc(250px + env(safe-area-inset-top)); background: var(--sky); overflow: hidden; flex: none; }
.ship { position: absolute; left: 30px; right: 10px; bottom: 4px; height: 156px; width: calc(100% - 40px); object-fit: contain; object-position: right bottom; }
.wave { position: absolute; left: 0; bottom: 0; width: 100%; height: 36px; display: block; }
.logo { display: inline-flex; flex-direction: column; border: 2px solid #fff; border-radius: 11px; overflow: hidden; }
.logo .top { background: var(--plate); color: #fff; padding: 6px 14px; display: flex; flex-direction: column; }
.logo .name { font-size: 30px; font-weight: 800; line-height: 1.1; letter-spacing: .03em; font-stretch: condensed; }
.logo .sub { font-size: 11.5px; font-weight: 800; letter-spacing: .2em; }
.logo .by { background: var(--sun); color: var(--on-sun); font-size: 10.5px; font-weight: 800; letter-spacing: .15em; text-align: right; padding: 1px 14px 2px; }
.header .logo { position: absolute; left: 16px; top: calc(12px + env(safe-area-inset-top)); }
.gear { position: absolute; right: 16px; top: calc(12px + env(safe-area-inset-top)); width: 48px; height: 48px; border: 0; border-radius: 24px; background: var(--sea); color: #fff; font-size: 24px; display: flex; align-items: center; justify-content: center; padding: 0; }

/* Trim */
.band { position: sticky; top: 0; z-index: 3; background: var(--sea); padding: 6px 16px 10px; }
.band.pinned { padding-top: calc(6px + env(safe-area-inset-top)); }
.trim { width: 100%; height: 48px; border: 0; border-radius: 16px; background: var(--sun); color: var(--on-sun); display: flex; justify-content: space-between; align-items: center; padding: 0 16px; }
.trim .t { font-size: 18px; font-weight: 800; }
.trim .v { font-size: 32px; font-weight: 800; font-stretch: condensed; }

/* Tank cards */
.status { display: flex; align-items: center; padding: 12px 16px 2px; gap: 8px; }
.status .l { flex: 1; font-size: 14px; font-weight: 700; }
.status .r { font-size: 13px; font-weight: 700; color: var(--muted); }
.stale { padding: 2px 16px; color: var(--alert); font-size: 14px; font-weight: 700; }
.list { padding: 2px 16px 14px; }
.group { font-size: 16px; font-weight: 800; margin: 12px 2px 0; }
.card { background: var(--card); border-radius: 18px; padding: 12px; display: flex; gap: 12px; align-items: center; margin-top: 8px; }
.tank { flex: none; display: block; border: 0; background: none; padding: 0; }
.cardbody { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 8px; }
.tname { flex: 1; font-size: 14px; font-weight: 800; border: 0; background: none; padding: 0; text-align: left; }
.badge { font-size: 12px; font-weight: 800; border-radius: 9px; padding: 2px 8px; background: var(--pale); color: var(--ink); }
.badge.y { background: var(--sun); color: var(--on-sun); }
.badge.r { background: var(--alert); color: #fff; }
:root[data-theme="dark"] .badge.r { background: var(--coral); color: var(--on-sun); }
.modes { display: flex; align-items: center; gap: 8px; margin-top: 4px; font-size: 13px; font-weight: 800; }
.modes .off { color: var(--muted); font-weight: 700; }
.switch { position: relative; width: 46px; height: 26px; border-radius: 13px; border: 0; padding: 0; background: var(--pale); }
.switch i { position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 10px; background: var(--sun); box-shadow: 0 1px 2px #0005; transition: left .12s; }
.switch[aria-checked="true"] i { left: 23px; }
.num { width: 78px; height: 44px; border: 2px solid var(--field-edge); border-radius: 11px; background: var(--field); text-align: center; font-size: 19px; font-weight: 700; padding: 0 4px; }
.num::placeholder { color: #6F8A97; }
.unit { font-size: 13px; font-weight: 700; color: var(--muted); }
.result { flex: 1; text-align: right; font-size: 25px; font-weight: 800; font-stretch: condensed; white-space: nowrap; overflow: hidden; }
.result.small { font-size: 18px; }
.result.alert, .note.alert { color: var(--alert); }
.note { font-size: 12.5px; font-weight: 600; color: var(--muted); margin-top: 6px; }

/* Buttons */
.bottom { flex: none; background: var(--bar); padding: 10px 16px calc(8px + env(safe-area-inset-bottom)); }
.primary { width: 100%; min-height: 50px; border: 0; border-radius: 15px; background: var(--save); color: var(--save-ink); font-size: 17px; font-weight: 800; padding: 10px; }
.primary.sun { background: var(--sun); color: var(--on-sun); }
.outline { width: 100%; min-height: 44px; border: 2px solid var(--tint); border-radius: 14px; background: var(--card); color: var(--tint); font-size: 15px; font-weight: 800; padding: 8px 12px; }
.outline.fit { width: auto; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.tab { height: 44px; border: 0; border-radius: 12px; background: var(--foam); color: var(--ink); font-size: 14px; font-weight: 800; }
.tab.on { background: var(--sun); color: var(--on-sun); }
body.typing .tabs { display: none; }

/* Secondary screens */
.topbar { flex: none; background: var(--sea); color: #fff; display: flex; align-items: center; gap: 12px; padding: calc(14px + env(safe-area-inset-top)) 16px 6px; }
.back { height: 44px; border: 0; border-radius: 14px; background: var(--sea-light); color: #fff; font-size: 15px; font-weight: 800; padding: 0 14px; flex: none; }
.topbar h1 { margin: 0; font-size: 24px; font-weight: 800; }
.topbar p { margin: 0; font-size: 13px; font-weight: 700; color: var(--on-sea-soft); }
.wavebar { flex: none; height: 26px; width: 100%; display: block; background: var(--sea); }
.pad { padding: 6px 16px calc(16px + env(safe-area-inset-bottom)); }
.box { background: var(--card); border-radius: 18px; padding: 16px; margin-bottom: 12px; }
.box h2 { margin: 0; font-size: 16px; font-weight: 800; }
.box .hint { font-size: 13px; font-weight: 700; color: var(--muted); margin: 2px 0 6px; }
.opt { display: flex; align-items: center; gap: 12px; min-height: 44px; font-size: 14.5px; padding: 4px 0; }
.opt input { width: 22px; height: 22px; margin: 0; accent-color: var(--tint); flex: none; }
.opt small { display: block; color: var(--muted); font-size: 12.5px; }
.big { font-size: 40px; font-weight: 800; line-height: 1.1; font-stretch: condensed; }
.fc { background: var(--sea); color: #fff; border-radius: 18px; padding: 16px; margin-bottom: 12px; }
.fc .h { color: var(--on-sea-soft); font-size: 14px; font-weight: 800; }
.fc .rate { font-size: 30px; font-weight: 800; margin: 6px 0 10px; }
.fc .cells { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fc .cell { background: var(--sea-light); border-radius: 12px; padding: 10px; font-size: 13px; font-weight: 700; }
.fc .cell b { display: block; font-size: 17px; }
.hrow { display: grid; grid-template-columns: 2.1fr 1fr 1.1fr 1.1fr 1.1fr; gap: 4px; padding: 9px 0; font-size: 13.5px; border-top: 1px solid var(--pale); }
.hrow > *:not(:first-child) { text-align: right; }
.hrow.head { color: var(--muted); font-weight: 800; border-top: 0; }
.hrow b { font-weight: 800; }
.hrow button { all: unset; color: var(--alert); font-size: 18px; text-align: right; cursor: pointer; }
.rline { padding: 9px 0; border-bottom: 1px solid var(--pale); }
.rline .a { display: flex; justify-content: space-between; font-size: 14px; font-weight: 800; }
.rline .b { font-size: 13px; font-weight: 700; color: var(--muted); }

/* Access and lock */
.gate { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--sky); overflow-y: auto; }
.gate .logo { align-self: center; margin-top: calc(32px + env(safe-area-inset-top)); flex: none; }
.gate img { width: calc(100% - 40px); margin: 20px 20px 0; display: block; flex: none; }
.gate .wave { position: static; flex: none; margin-top: -18px; }
.gatebody { flex: 1 0 auto; background: var(--sea); color: #fff; padding: 16px 24px calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.gatebody h2 { margin: 0; font-size: 22px; }
.gatebody p { margin: 0; font-size: 15px; font-weight: 700; color: var(--on-sea-soft); }
.text { width: 100%; height: 48px; border: 0; border-radius: 12px; background: var(--field); color: var(--ink); font-size: 18px; padding: 0 12px; }
.linkbtn { border: 0; background: none; color: var(--on-sea-soft); font-size: 14px; font-weight: 700; text-decoration: underline; padding: 8px; }

/* Dialogs and toast */
#modal:empty { display: none; }
#modal { position: fixed; inset: 0; z-index: 10; background: #0008; display: flex; align-items: flex-end; justify-content: center; padding: 16px; }
.dialog { background: var(--card); border-radius: 22px; padding: 20px; width: 100%; max-width: 460px; max-height: 85dvh; overflow-y: auto; margin-bottom: env(safe-area-inset-bottom); }
.dialog h2 { margin: 0 0 10px; font-size: 19px; }
.dialog p { font-size: 15px; margin: 0 0 10px; white-space: pre-line; }
.chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.chip { height: 48px; border: 0; border-radius: 10px; background: var(--pale); color: var(--ink); font-size: 20px; font-weight: 800; }
.chip.on { background: var(--sun); color: var(--on-sun); }
.dialog label.lbl { display: block; font-size: 14px; font-weight: 700; color: var(--muted); margin: 12px 4px 4px; }
.customrow { display: flex; gap: 8px; }
.sign { width: 56px; height: 44px; border: 0; border-radius: 10px; background: var(--sun); color: var(--on-sun); font-size: 24px; font-weight: 800; flex: none; }
.dialog .text { background: var(--field); border: 2px solid var(--field-edge); height: 44px; text-align: center; }
.actions { display: flex; gap: 8px; margin-top: 16px; }
.actions button { flex: 1; min-height: 44px; border: 0; background: none; color: var(--tint); font-size: 16px; font-weight: 800; }
#toast { position: fixed; left: 50%; bottom: calc(130px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #000C; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; }
