* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font: 16px/1.45 system-ui, -apple-system, sans-serif;
    color: var(--tg-theme-text-color, #111);
    background: var(--tg-theme-bg-color, #fff);
    padding: 12px 14px 20px;
}

.row,
.chrome-row {
    display: flex;
}

.row {
    gap: 8px;
    margin-bottom: 12px;
}

.chrome-row {
    gap: 4px;
}

body:has(#chrome:not([hidden])) {
    --chrome-h: calc(43px + 1lh + env(safe-area-inset-bottom));
    padding-bottom: var(--chrome-h);
}

body:has(#live:not([hidden])) {
    overflow: hidden;
}

select {
    flex: 1;
    padding: 8px 10px;
    font: inherit;
    font-size: .95em;
    background: var(--tg-theme-secondary-bg-color, #f1f1f1);
    border: 1px solid var(--tg-theme-hint-color, #aaa);
    border-radius: 8px;
    appearance: none;
    -webkit-appearance: none;
}

article {
    padding: 8px 10px;
    margin-bottom: 10px;
}

h2 {
    font-weight: 600;
    line-height: 1.3;
    font-size: 1.1em;
}

.sources,
#status,
#diag dt,
#feed p,
#live > p {
    color: var(--tg-theme-hint-color, #888);
}

.sources {
    font-size: .78em;
    margin-top: 3px;
    opacity: .65;
}

#status,
#diag dl,
#feed p,
#live > p {
    font-size: .82em;
}

#status {
    text-align: center;
    padding: 36px 0;
}

article.high {
    border: 2px solid #ff3b30;
}

article.ok {
    border: 2px solid #34c759;
}

article.medium,
article.running {
    border: 2px solid #f1c40f;
}

article.low {
    border: 2px solid #888;
}

article.quake-high {
    border: 2px dashed #ff3b30;
}

article.spike h2 {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

article.spike h2 > span:first-child {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

article.spike h2 > span:last-child {
    flex-shrink: 0;
    color: var(--tg-theme-hint-color, #888);
    font-size: .78em;
    font-weight: 400;
    white-space: nowrap;
}

article.weather-l4 {
    border-color: #af52de;
}

article.weather-l5 {
    border-color: #000;
    animation: blink-l5 0.8s step-end infinite;
}

article.quake-recent,
article.running,
article.weather-l4 {
    animation: blink-border 0.8s step-end infinite;
}

@media (prefers-reduced-motion: reduce) {
    article.quake-recent,
    article.running,
    article.weather-l4,
    article.weather-l5 {
        animation: none;
    }
}

article[onclick] {
    cursor: pointer;
}

@keyframes blink-border {
    50% { border-color: transparent; }
}

@keyframes blink-l5 {
    25% { border-color: transparent; }
    50% { border-color: #af52de; }
    75% { border-color: transparent; }
}

#chrome {
    position: fixed;
    inset: auto 0 0;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    background: var(--tg-theme-bg-color, #fff);
}

#chrome[hidden] {
    display: none;
}

.chrome-row:not(:has(button:not([hidden]))) {
    display: none;
}

#chrome button,
#diag button {
    flex: 1;
    padding: 12px 14px;
    font: inherit;
    font-weight: 600;
    border: 0;
    border-radius: 10px;
    cursor: pointer;
}

#MainButton {
    background: var(--tg-theme-button-color, #2474c1);
    color: var(--tg-theme-button-text-color, #fff);
}

#chrome #MainButton,
#chrome #BackButton,
#chrome #SecondaryButton {
    flex: 1 1 auto;
    padding: 8.5px 6px;
    border: 3.5px solid transparent;
    white-space: nowrap;
    min-width: 0;
}

#chrome #MainButton.ring {
    border-color: #ff3b30;
    box-shadow: inset 0 0 0 2px var(--tg-theme-bg-color, #fff);
}

#BackButton,
#SecondaryButton,
#diag button {
    background: var(--tg-theme-secondary-bg-color, #f1f1f1);
}

#live {
    position: fixed;
    inset: 0;
    padding-bottom: var(--chrome-h, 0px);
    grid-template-rows: repeat(2, minmax(0, 1fr));
    gap: 2px;
    background: #000;
    z-index: 9999;
}

#live:not([hidden]) {
    display: grid;
}

.live-player {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #000;
}

.live-player > iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    pointer-events: none;
}
#live > p:not([hidden]) {
    position: absolute;
    inset: 0;
    z-index: 1;
    margin: 0;
    display: grid;
    place-items: center;
    background: #000;
    cursor: pointer;
    color: #888;
}

#diag hr,
#feed p::before,
#feed p::after {
    border: 0;
    border-top: 1px solid var(--tg-theme-hint-color, #ddd);
    margin: 10px 0;
}

#feed p {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
}

#feed p::before,
#feed p::after {
    content: "";
    flex: 1;
    margin: 0;
}

#diag button,
#diag select {
    width: 100%;
    margin-bottom: 8px;
}

#diag dl {
    display: grid;
    grid-template-columns: 7.5em 1fr;
    gap: 8px 12px;
    padding: 8px 10px;
}

#diag-ip {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#diag .ok,
h2 .ok,
.sources .ok {
    color: #34c759;
}

#diag .medium {
    color: #f1c40f;
}

#diag .high,
h2 .high,
.sources .high {
    color: #ff3b30;
}
