:root {
  color-scheme: dark;
  --bg: #14231f;
  --panel: #21352f;
  --text: #f1f5f2;
  --muted: #a9bbb4;
  --accent: #ffc857;
  --bad: #ff9a8a;
}

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

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, sans-serif;
  overscroll-behavior: none;
}

button, a, input { font: inherit; }
button {
  min-height: 48px;
  min-width: 48px;
  border: 0;
  color: inherit;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Home */
#home {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
header { position: sticky; top: 0; z-index: 2; background: var(--bg); }
nav { display: flex; }
nav button { flex: 1; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 600; }
nav button[aria-current] { color: var(--text); border-color: var(--accent); }
main { flex: 1; padding: 6px; }
#banner { margin: 0; padding: 8px 12px; background: #5b2c25; }
#hint { margin: 8px 6px 14px; color: var(--muted); }

#grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
#grid[data-count="1"], #grid[data-count="2"] { grid-template-columns: minmax(0, 1fr); }
.tile { position: relative; overflow: hidden; border-radius: 8px; background: var(--panel); }
.open { display: block; width: 100%; padding: 0; text-align: left; }
.media { display: block; position: relative; aspect-ratio: 16 / 9; background: #000; }
.media::before {
  content: '\25B6';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 26px;
}
#grid[data-tab="all"] .tile:not(.seen) .media { display: none; }
#grid[data-tab="all"] .tile:not(.seen) .open { min-height: 72px; }
.media img, #zoom img, #zoom video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
video:not(.playing) { opacity: 0; }
.caption { display: block; padding: 5px 46px 6px 8px; }
.name, .status { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.name { font-size: 14px; font-weight: 600; }
.status { min-height: 1.4em; color: var(--muted); font-size: 12px; }
.status[data-state="delayed"], .status[data-state="tap"] { color: var(--accent); }
.status[data-state="down"] { color: var(--bad); }
.tile .status[data-state="down"] { white-space: normal; }
.tile .star { position: absolute; right: 0; bottom: 0; }
.star { color: #81968e; font-size: 23px; }
.star[aria-pressed="true"] { color: var(--accent); }

footer { display: flex; flex-wrap: wrap; justify-content: space-around; align-items: center; padding: 4px; }
footer button, footer a { padding: 12px 8px; color: var(--muted); font-size: 14px; }

/* Viewer */
body.viewing { overflow: hidden; }
#viewer { position: fixed; inset: 0; z-index: 5; background: #000; overflow: hidden; }
#stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; user-select: none; }
#zoom { position: absolute; inset: 0; transform-origin: center; }
.bar { position: absolute; left: 0; right: 0; display: flex; align-items: center; gap: 6px; background: #0009; }
.bar.top { top: 0; padding: env(safe-area-inset-top) 4px 0; }
.bar.bottom { bottom: 0; padding: 0 4px env(safe-area-inset-bottom); }
.bar h1 { flex: 1; margin: 0; font-size: 17px; }
.bar > button { font-size: 25px; }
.bar .info { flex: 1; min-width: 0; text-align: center; }
.bar .info a { display: block; padding: 4px 0 8px; color: var(--muted); font-size: 12px; }
#close, #prev, #next { color: var(--text); }

/* Landscape: let the picture use the whole height once zoomed */
@media (orientation: landscape) and (max-height: 500px) {
  #stage[data-zoomed="true"] ~ .bar.bottom { display: none; }
  #grid, #grid[data-count="2"] { grid-template-columns: repeat(2, minmax(0, 42vw)); justify-content: center; }
}
@media (min-width: 900px) {
  main { width: 100%; max-width: 1100px; margin: 0 auto; }
}

/* Dialogs */
dialog { width: min(92vw, 360px); border: 0; border-radius: 12px; background: var(--panel); color: var(--text); }
dialog::backdrop { background: #000a; }
dialog h2 { margin: 0 0 8px; font-size: 18px; }
dialog input { width: 100%; min-height: 48px; padding: 8px; }
#link-error { color: var(--bad); }
.actions { display: flex; justify-content: flex-end; gap: 8px; }
.actions button { padding: 0 14px; }
.actions .primary { border-radius: 8px; background: var(--accent); color: #14231f; font-weight: 600; }

#toast {
  position: fixed;
  z-index: 9;
  left: 12px;
  right: 12px;
  bottom: 80px;
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  text-align: center;
}
