/* Kiosk display for air-raid alerts.
   Designed to be read across a waiting room: two states, one glance. */

:root {
  --bg: #0b1220;
  --bg-soft: #131c2e;
  --fg: #eef2f9;
  --fg-dim: #93a0b8;
  --line: #223049;
  --accent: #4f8cff;
  --ok: #17c964;
  --alarm: #ff2d2d;
  --warn: #ffb020;

  --pad: clamp(14px, 2.5vmin, 34px);
  --status-size: clamp(38px, 11vmin, 190px);
  --icon-size: clamp(70px, 20vmin, 300px);
  --bar-size: clamp(15px, 2.4vmin, 40px);
  --foot-size: clamp(12px, 1.8vmin, 30px);

  color-scheme: dark;
}

/* Television mode: everything a step larger, meant for 3–8 m viewing. */
body.tv {
  --status-size: clamp(52px, 14vmin, 260px);
  --icon-size: clamp(90px, 26vmin, 400px);
  --bar-size: clamp(18px, 3vmin, 52px);
  --foot-size: clamp(14px, 2.2vmin, 38px);
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--fg);
  font-family: "Inter", "Segoe UI", "Roboto", system-ui, -apple-system, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .5s ease;
}

/* ---------- state colours ---------- */

body[data-state="ok"]      { background: #07120c; }
body[data-state="alert"]   { background: #2a0505; animation: alarmPulse 2.2s ease-in-out infinite; }
body[data-state="offline"] { background: #191308; }

@keyframes alarmPulse {
  0%, 100% { background-color: #2a0505; }
  50%      { background-color: #5c0a0a; }
}

@media (prefers-reduced-motion: reduce) {
  body[data-state="alert"] { animation: none; background: #3d0707; }
}

/* ---------- layout ---------- */

.screen {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: var(--pad);
  gap: var(--pad);
}

/* Keep the footer and the liveness pill clear of the "enable sound" banner. */
body.locked .screen { padding-bottom: clamp(110px, 18vmin, 210px); }
body.locked .mini { bottom: clamp(96px, 16vmin, 190px); }

/* ---------- background modes ----------
   The device screen is doing something else; the app only needs to be alive
   and audible. `mini` leaves a small liveness pill, `none` a single dot. */

body.ui-mini, body.ui-none { background: #000; }
body.ui-mini .screen, body.ui-none .screen { display: none; }
body.ui-mini[data-state="alert"], body.ui-none[data-state="alert"] { animation: none; }

/* Wrapper mode: the embedded site owns the whole viewport, everything of
   ours floats above it. */
.content {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  z-index: 1;
  background: #000;
}
.content[hidden] { display: none; }

/* Taps inside a cross-origin iframe never reach us, so the pill itself has to
   be the way back into settings — a 44 px target even when it looks like a
   speck of dust. */
body.has-content.ui-none .mini {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mini {
  position: fixed;
  right: clamp(8px, 1.5vmin, 20px);
  bottom: clamp(8px, 1.5vmin, 20px);
  z-index: 45;
  display: flex;
  align-items: center;
  gap: .6em;
  padding: .5em .8em;
  border-radius: 999px;
  background: rgba(19, 28, 46, .85);
  border: 1px solid var(--line);
  font-size: clamp(12px, 1.6vmin, 18px);
  color: var(--fg-dim);
  opacity: .55;
  transition: opacity .3s;
  max-width: 90vw;
}
.mini[hidden] { display: none; }
.mini:hover { opacity: 1; }

.mini__text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* An active alert makes even the pill unmistakable. */
body[data-state="alert"] .mini {
  opacity: 1;
  background: rgba(90, 8, 8, .92);
  border-color: #ff3b3b;
  color: #ffd9d9;
}

/* `none`: nothing but a faint dot, so a technician can still confirm it runs
   and triple-tap into settings. */
body.ui-none .mini {
  padding: 0;
  border: 0;
  background: transparent;
  opacity: .18;
}
body.ui-none .mini__text,
body.ui-none #miniGear { display: none; }
body.ui-none[data-state="alert"] .mini { opacity: .5; background: transparent; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1em;
  font-size: var(--bar-size);
  color: var(--fg-dim);
  min-width: 0;
}

.bar__left, .bar__right {
  display: flex;
  align-items: center;
  gap: .7em;
  min-width: 0;
}

.bar__device {
  font-weight: 700;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar__device:empty { display: none; }

.bar__region {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar__clock { font-weight: 600; color: var(--fg); }

.dot {
  width: .7em;
  height: .7em;
  border-radius: 50%;
  background: var(--fg-dim);
  flex: none;
  transition: background-color .3s;
}
.dot[data-link="up"]   { background: var(--ok); }
.dot[data-link="down"] { background: var(--alarm); animation: blink 1s steps(2) infinite; }
.dot[data-link="stale"]{ background: var(--warn); }

@keyframes blink { 50% { opacity: .2; } }

/* ---------- centre status ---------- */

.status {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: clamp(6px, 1.5vmin, 26px);
  min-height: 0;
}

.status__icon {
  width: var(--icon-size);
  height: var(--icon-size);
  flex: none;
  background: no-repeat center / contain;
}

body[data-state="ok"] .status__icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' fill='none' stroke='%2317c964' stroke-width='7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M50 8 84 22v27c0 22-14 35-34 43C30 84 16 71 16 49V22z'/%3E%3Cpath d='M35 50l11 11 20-22'/%3E%3C/svg%3E");
}
body[data-state="alert"] .status__icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' fill='none' stroke='%23ff5555' stroke-width='7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M50 12 92 84H8z'/%3E%3Cpath d='M50 38v22'/%3E%3Cpath d='M50 72h.01'/%3E%3C/svg%3E");
}
body[data-state="offline"] .status__icon,
body[data-state="loading"] .status__icon {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' fill='none' stroke='%2393a0b8' stroke-width='7' stroke-linecap='round'%3E%3Ccircle cx='50' cy='50' r='38'/%3E%3Cpath d='M50 28v24l16 10'/%3E%3C/svg%3E");
}

.status__text {
  margin: 0;
  font-size: var(--status-size);
  line-height: .96;
  font-weight: 900;
  letter-spacing: -.02em;
  text-wrap: balance;
}
body[data-state="ok"]    .status__text { color: #7ef0ad; }
body[data-state="alert"] .status__text { color: #ff6b6b; text-shadow: 0 0 clamp(10px, 3vmin, 60px) rgba(255,45,45,.5); }

.status__since {
  margin: 0;
  font-size: var(--bar-size);
  color: var(--fg-dim);
}

.foot {
  display: flex;
  justify-content: space-between;
  gap: 1em;
  font-size: var(--foot-size);
  color: var(--fg-dim);
  opacity: .75;
}

/* ---------- unlock overlay ---------- */

/* A banner, not a blocker: the alert state must stay readable even if
   nobody ever taps to grant audio. */
.unlock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding: clamp(12px, 2vmin, 26px);
  background: rgba(10, 16, 28, .96);
  border-top: 2px solid var(--accent);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, .5);
  animation: unlockIn .35s ease-out;
}
.unlock[hidden] { display: none; }

@keyframes unlockIn { from { transform: translateY(100%); } }

.unlock__box {
  display: flex;
  align-items: center;
  gap: clamp(10px, 2vmin, 24px);
  max-width: 1400px;
  margin: 0 auto;
  text-align: left;
  flex-wrap: wrap;
}
.unlock__icon { font-size: clamp(26px, 4vmin, 54px); line-height: 1; flex: none; }
.unlock__title { font-size: clamp(17px, 2.6vmin, 36px); margin: 0; flex: none; }
.unlock__text {
  font-size: clamp(13px, 1.8vmin, 24px);
  color: var(--fg-dim);
  margin: 0;
  flex: 1 1 14ch;
  min-width: 0;
}
.unlock .btn { flex: none; }

/* ---------- controls ---------- */

.btn {
  font: inherit;
  font-size: clamp(14px, 2vmin, 26px);
  font-weight: 600;
  color: var(--fg);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .7em 1.2em;
  cursor: pointer;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #051022; }
.btn--xl { font-size: clamp(20px, 3.4vmin, 40px); padding: .8em 2em; border-radius: 14px; }
.btn--small { font-size: clamp(12px, 1.6vmin, 18px); padding: .5em .9em; }

.iconbtn {
  font: inherit;
  font-size: 1.1em;
  line-height: 1;
  color: var(--fg-dim);
  background: transparent;
  border: 0;
  padding: .3em .4em;
  cursor: pointer;
  opacity: .6;
}
.iconbtn:hover, .iconbtn:focus-visible { opacity: 1; color: var(--fg); }

/* ---------- settings panel ---------- */

.panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(4, 8, 16, .72);
  display: grid;
  justify-items: end;
  overflow: auto;
}
.panel[hidden] { display: none; }

.panel__inner {
  width: min(560px, 100%);
  min-height: 100%;
  background: var(--bg-soft);
  border-left: 1px solid var(--line);
  padding: clamp(18px, 3vmin, 34px);
  display: flex;
  flex-direction: column;
  gap: clamp(14px, 2vmin, 22px);
  font-size: clamp(14px, 1.9vmin, 19px);
}

.panel__head { display: flex; align-items: center; justify-content: space-between; }
.panel__head h2 { margin: 0; font-size: 1.4em; }

.field { display: flex; flex-direction: column; gap: .45em; }
.field--row { flex-direction: row; gap: 1em; }
.field--half { flex: 1; }
.field--check { flex-direction: row; align-items: center; gap: .7em; }
.field--check input { width: 1.3em; height: 1.3em; accent-color: var(--accent); }

.field__label { color: var(--fg-dim); font-weight: 600; display: flex; justify-content: space-between; gap: 1em; }
.field__label em { font-style: normal; font-weight: 400; opacity: .7; }
.field__out { color: var(--fg); font-weight: 700; }
.field__hint { color: var(--fg-dim); opacity: .75; font-size: .85em; line-height: 1.4; }

.field__control {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: .65em .8em;
  width: 100%;
}
.field__control--range { padding: 0; accent-color: var(--accent); height: 2.4em; }

.panel__actions { display: flex; gap: .7em; flex-wrap: wrap; }
.panel__actions .btn { flex: 1; }

.panel__url {
  display: flex;
  flex-direction: column;
  gap: .5em;
  padding: .9em;
  border: 1px dashed var(--line);
  border-radius: 10px;
}
.panel__url code {
  font-size: .85em;
  color: var(--accent);
  word-break: break-all;
  line-height: 1.5;
}
.panel__url .btn { align-self: flex-start; }

.panel__note {
  margin: 0;
  color: var(--fg-dim);
  font-size: .82em;
  line-height: 1.6;
  white-space: pre-line;
  opacity: .8;
}

/* Landscape phones / short tablets: reclaim vertical space. */
@media (max-height: 430px) {
  .status__icon { display: none; }
  .foot { display: none; }
}
