:root {
  color-scheme: dark;
  --page: #071218;
  --text: #f7fbfd;
  --muted: rgba(247, 251, 253, .72);
  --good: #087a4b;
  --warn: #a96608;
  --bad: #a72432;
  --stale: #33434c;
  --gap: clamp(6px, 1.4vw, 12px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }

body {
  background: var(--page);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

.locked-screen {
  width: 100%;
  height: 100%;
  height: 100dvh;
  padding-top: max(var(--tg-content-safe-area-inset-top, 0px), env(safe-area-inset-top));
  padding-right: max(var(--tg-safe-area-inset-right, 0px), env(safe-area-inset-right));
  padding-bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom));
  padding-left: max(var(--tg-safe-area-inset-left, 0px), env(safe-area-inset-left));
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 35%, #142b36 0, var(--page) 58%);
}

.locked-panel {
  width: min(84vw, 420px);
  padding: clamp(28px, 8vw, 48px);
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(15, 32, 40, .9);
  box-shadow: 0 24px 80px rgba(0,0,0,.38), inset 0 1px 0 rgba(255,255,255,.08);
  display: grid;
  justify-items: center;
  gap: 18px;
  text-align: center;
}

.locked-mark {
  width: 68px;
  height: 68px;
  border: 2px solid rgba(255,255,255,.78);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
}

.locked-panel strong { font-size: clamp(22px, 6vw, 32px); letter-spacing: .08em; }
.locked-panel > span:last-child { max-width: 28ch; color: var(--muted); font-size: 15px; line-height: 1.45; }

.app-shell {
  width: 100%;
  height: 100%;
  height: 100dvh;
  padding-top: max(var(--tg-content-safe-area-inset-top, 0px), env(safe-area-inset-top));
  padding-right: max(var(--tg-safe-area-inset-right, 0px), env(safe-area-inset-right));
  padding-bottom: max(var(--tg-safe-area-inset-bottom, 0px), env(safe-area-inset-bottom));
  padding-left: max(var(--tg-safe-area-inset-left, 0px), env(safe-area-inset-left));
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(50px, .085fr);
  gap: var(--gap);
  background: var(--page);
}

.page { min-width: 0; min-height: 0; }

.choice-grid {
  display: grid;
  grid-template-rows: 1fr 1fr 1fr;
  gap: var(--gap);
}

.choice-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); min-height: 0; }

.choice {
  min-width: 0;
  min-height: 0;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 0;
  padding: clamp(18px, 5vmin, 40px);
  background: #17313d;
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  gap: 10px;
  text-align: left;
  font: inherit;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.choice--abcs { background: #0a6845; }
.choice--camera { background: #24465a; }
.choice strong { font-size: clamp(28px, 9vmin, 64px); line-height: .92; letter-spacing: -.035em; }
.choice span { color: var(--muted); font-size: clamp(10px, 2.8vmin, 16px); font-weight: 760; letter-spacing: .09em; }
.choice:active { filter: brightness(.82); }

.dashboard {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.24fr) minmax(0, .78fr);
  gap: var(--gap);
  background: var(--page);
}

.card {
  min-width: 0;
  min-height: 0;
  padding: clamp(10px, 2.6vmin, 22px);
  border: 1px solid rgba(255,255,255,.16);
  background: var(--stale);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  transition: background-color .28s ease;
}

.card--good { background: var(--good); }
.card--warn { background: var(--warn); }
.card--bad { background: var(--bad); }
.card--stale { background: var(--stale); }

.card__heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.eyebrow, .connection, small {
  font-size: clamp(9px, 2.25vmin, 14px);
  font-weight: 760;
  letter-spacing: .09em;
  line-height: 1;
  color: var(--muted);
}

.connection {
  padding: 5px 7px;
  border: 1px solid rgba(255,255,255,.32);
  border-radius: 99px;
  letter-spacing: .04em;
}

.connection--pulse { animation: live-pulse .7s ease-out; }

@keyframes live-pulse {
  0% { background: #24e98b; border-color: #91ffc4; color: #04160d; box-shadow: 0 0 0 0 rgba(36,233,139,.72); }
  45% { background: #0db96c; border-color: #66f4ac; color: #fff; box-shadow: 0 0 0 7px rgba(36,233,139,.16); }
  100% { background: transparent; border-color: rgba(255,255,255,.32); color: var(--muted); box-shadow: 0 0 0 12px rgba(36,233,139,0); }
}

.status { font-size: clamp(25px, 7.6vmin, 55px); font-weight: 850; line-height: .96; letter-spacing: -.045em; }

.metrics { display: grid; width: 100%; }
.metrics--two { grid-template-columns: 1fr 1fr; }
.metrics--three { grid-template-columns: repeat(3, 1fr); }
.metrics span { min-width: 0; display: flex; align-items: baseline; gap: .32em; }
.metrics span + span { border-left: 1px solid rgba(255,255,255,.25); padding-left: clamp(8px, 2.4vw, 22px); }
.metrics b { font-size: clamp(20px, 5.7vmin, 40px); line-height: 1; }
.metrics--three b { font-size: clamp(15px, 4.5vmin, 30px); }

.battery-row, .alarm-row { display: grid; gap: var(--gap); min-height: 0; }
.battery-row { grid-template-columns: 1fr 1fr; }
.alarm-row { grid-template-columns: repeat(3, 1fr); }

.soc { display: flex; align-items: baseline; gap: .38em; }
.soc b { font-size: clamp(30px, 9.5vmin, 68px); line-height: .9; letter-spacing: -.04em; }

.alarm { align-items: center; text-align: center; padding: clamp(8px, 2vmin, 16px); }
.alarm b { font-size: clamp(26px, 7.5vmin, 52px); line-height: .9; }

.placeholder-page {
  display: grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.15);
  background: radial-gradient(circle at 50% 35%, #183744 0, #0b1b22 66%);
}

.placeholder-panel { width: min(84vw, 540px); display: grid; gap: 18px; text-align: center; }
.placeholder-kicker { color: var(--muted); font-size: 13px; font-weight: 760; letter-spacing: .12em; }
.placeholder-panel strong { font-size: clamp(30px, 9vmin, 62px); line-height: .95; }
.placeholder-panel > span:last-child { color: var(--muted); font-size: clamp(14px, 3.6vmin, 19px); line-height: 1.45; }

.yacht-page { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: var(--gap); }
.yacht-heading { min-height: 44px; padding: 0 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.camera-frame { position: relative; min-height: 0; overflow: hidden; border: 1px solid rgba(255,255,255,.16); background: #101c22; display: grid; place-items: center; }
.camera-frame img { width: 100%; height: 100%; object-fit: contain; }
.camera-message { width: min(80%, 440px); display: grid; gap: 14px; text-align: center; }
.camera-message strong { font-size: clamp(24px, 7vmin, 44px); line-height: .98; }
.camera-message span { color: var(--muted); font-size: clamp(13px, 3.3vmin, 18px); line-height: 1.4; }
.camera-retry { min-height: 48px; border: 1px solid rgba(255,255,255,.22); border-radius: 0; background: #24465a; color: var(--text); font: inherit; font-weight: 800; letter-spacing: .06em; }
.camera-retry:disabled { opacity: .5; }

.app-footer { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); min-height: 50px; }
.app-footer--menu #exit-button { grid-column: 1 / -1; }

.nav-button {
  width: 100%; min-height: 50px; border: 0; border-radius: 0;
  background: var(--tg-theme-button-color, #2aabee);
  color: var(--tg-theme-button-text-color, #fff);
  font: inherit; font-size: clamp(14px, 3.4vmin, 20px); font-weight: 820; letter-spacing: .06em;
  cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.nav-button--secondary { border: 1px solid rgba(255,255,255,.22); background: #273943; }
.nav-button:active { filter: brightness(.84); }

@media (orientation: landscape) and (max-height: 520px) {
  .app-shell { grid-template-rows: minmax(0, 1fr) minmax(42px, .13fr); }
  .dashboard { grid-template-columns: 1.1fr 1.1fr 1fr; grid-template-rows: 1fr 1fr; }
  #shore-card { grid-column: 1; grid-row: 1; }
  #charging-card { grid-column: 1; grid-row: 2; }
  .battery-row { grid-column: 2; grid-row: 1 / 3; grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .alarm-row { grid-column: 3; grid-row: 1 / 3; }
  .alarm-row { grid-template-columns: 1fr; }
  .nav-button { min-height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .card { transition: none; }
  .connection--pulse { animation-duration: .01ms; }
}
