:root {
  --bg: #12151b;
  --panel: #1b2029;
  --panel-hover: #232a36;
  --border: #2c3442;
  --text: #e6e9ef;
  --muted: #8b95a7;
  --accent: #4f8cff;
  --ok: #2fb67c;
  --error: #e5534b;
  --topbar-height: 48px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
code { font-size: 0.9em; color: var(--muted); }
.muted { color: var(--muted); }
.error { color: var(--error); }
.banner {
  padding: 12px 16px;
  margin: 0 0 20px;
  border-radius: 8px;
  border: 1px solid var(--error);
  background: rgba(229, 83, 75, 0.1);
}

.topbar {
  height: var(--topbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; color: var(--text); }
.topbar nav { display: flex; align-items: center; gap: 4px; }
.topbar nav a, .topbar nav button.link {
  padding: 6px 12px;
  border-radius: 6px;
  color: var(--muted);
}
.topbar nav a:hover, .topbar nav a.active, .topbar nav button.link:hover {
  color: var(--text);
  background: var(--panel-hover);
}
.topbar form { margin: 0; }

.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }
h1 { font-size: 24px; margin: 0 0 20px; }
h2 { font-size: 18px; margin: 36px 0 12px; }

button, .button {
  font: inherit;
  cursor: pointer;
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-hover);
  color: var(--text);
  display: inline-block;
}
button:hover, .button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger:hover { border-color: var(--error); color: var(--error); }
button.link { background: none; border: none; }

input {
  font: inherit;
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
input:focus { outline: none; border-color: var(--accent); }
label { display: block; color: var(--muted); font-size: 13px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}
.grid form { margin: 0; }
.tile {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 18px;
  text-align: left;
  background: var(--panel);
  border-radius: 10px;
  transition: background 0.15s, transform 0.15s;
}
.tile:hover { background: var(--panel-hover); transform: translateY(-2px); }
.tile-icon {
  position: relative;
  width: 40px;
  height: 40px;
  margin-bottom: 8px;
}
.tile-icon .fallback, .tile-icon img {
  position: absolute;
  inset: 0;
  width: 40px;
  height: 40px;
  border-radius: 8px;
}
.tile-icon .fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  font-weight: 700;
  font-size: 20px;
}
.tile-icon img { object-fit: contain; background: #fff; padding: 4px; }
.tile-name { font-weight: 600; font-size: 16px; }
.tile-desc { color: var(--muted); font-size: 13px; }
.tile-host { color: var(--accent); font-size: 12px; margin-top: auto; padding-top: 6px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: 10px; overflow: hidden; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
tr:last-child td { border-bottom: none; }
td.actions { display: flex; gap: 8px; justify-content: flex-end; }
td.actions form { margin: 0; }
.status-running { color: var(--accent); }
.status-done { color: var(--ok); }
.status-error { color: var(--error); }

.site-form {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
  background: var(--panel);
  padding: 20px;
  border-radius: 10px;
}
.form-actions { display: flex; gap: 8px; align-items: end; }

body.centered { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box { width: 320px; padding: 28px; background: var(--panel); border-radius: 12px; }
.login-box h1 { text-align: center; }
.stack { display: flex; flex-direction: column; gap: 14px; }

body.viewer-page {
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}
#viewer {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #000;
}
#screen { flex: 1; min-height: 0; position: relative; touch-action: none; }
#screen canvas { touch-action: none; }
.viewer-status {
  position: absolute;
  top: 40%;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 8px;
  background: rgba(27, 32, 41, 0.9);
  pointer-events: none;
  white-space: nowrap;
}
.viewer-bar {
  display: flex;
  gap: 2px;
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.bar-btn {
  flex: 1;
  min-width: 0;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 26px;
  line-height: 1;
}
.bar-btn.bar-text { font-size: 15px; font-weight: 600; }
.bar-btn:active, .bar-btn:hover { background: var(--panel-hover); border: none; }
.sheet {
  position: absolute;
  left: 8px;
  right: 8px;
  top: calc(8px + env(safe-area-inset-top));
  z-index: 10;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}
.sheet input { margin: 0 0 10px; -webkit-user-select: text; user-select: text; }
.sheet-row { display: flex; gap: 8px; }
.sheet-row button { flex: 1; min-height: 48px; padding: 0 6px; font-size: 18px; }
.sheet-row button.primary { flex: 2; font-size: 15px; }
.sheet-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sheet-grid button { min-height: 52px; padding: 4px; font-size: 14px; }
.sheet .hint { margin: 12px 0 0; color: var(--muted); font-size: 12px; }
body.viewer-page #toasts { top: calc(12px + env(safe-area-inset-top)); bottom: auto; }

@media (max-width: 600px) {
  input { font-size: 16px; }
  .topbar { padding: 0 10px; }
  .brand { font-size: 16px; }
  .topbar nav a, .topbar nav button.link { padding: 6px 8px; font-size: 14px; }
  .topbar nav .nav-home { display: none; }
  .container { padding: 16px 12px 40px; }
  h1 { font-size: 20px; margin-bottom: 14px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tile { padding: 14px; }
  .tile-name { font-size: 15px; }
  th, td { padding: 10px; }
  table.downloads th:nth-child(3), table.downloads td:nth-child(3),
  table.sites th:nth-child(2), table.sites td:nth-child(2),
  table.sites th:nth-child(3), table.sites td:nth-child(3) { display: none; }
  td { word-break: break-word; }
  td.actions { flex-direction: column; align-items: stretch; }
  td.actions .button, td.actions button { width: 100%; text-align: center; min-height: 40px; }
  .site-form { grid-template-columns: 1fr; padding: 14px; }
  .form-actions button, .form-actions .button { flex: 1; min-height: 44px; text-align: center; }
}

#toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  max-width: min(420px, calc(100vw - 32px));
}
.toast {
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--panel);
  border-left: 4px solid var(--accent);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
  word-break: break-word;
  animation: slide-in 0.2s ease-out;
}
.toast.done { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--error); }
@keyframes slide-in { from { opacity: 0; transform: translateY(10px); } }
