:root {
  --bg: #141312;
  --bg-raised: #1c1b19;
  --line: #2e2b28;
  --fg: #e8e4de;
  --muted: #8f8880;
  --accent: #d97757;
  --ok: #6fbf73;
  --warn: #e0a458;
  --bad: #d2585a;
  --bar-h: 38px;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 13px/1.5 ui-sans-serif, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

#app {
  display: grid;
  grid-template-rows: var(--bar-h) 1fr auto;
  height: 100dvh;
  /* The folded action menu is positioned against this. */
  position: relative;
}

#app[hidden] {
  display: none;
}

/* ---------- top bar ---------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 10px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
  user-select: none;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-size: 12px;
  letter-spacing: 0.02em;
}

.brand strong {
  font-weight: 600;
  color: var(--accent);
}

.sep {
  color: var(--line);
}

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

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
  transition: background 0.2s;
}

.dot.on {
  background: var(--ok);
  box-shadow: 0 0 8px color-mix(in srgb, var(--ok) 60%, transparent);
}

.dot.pending {
  background: var(--warn);
}

.dot.off {
  background: var(--bad);
}

.bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
}

.muted {
  color: var(--muted);
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid transparent;
  transition:
    background 0.15s,
    border-color 0.15s;
}

button.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--muted);
  padding: 4px 9px;
  font-size: 11px;
}

button.ghost:hover {
  color: var(--fg);
  border-color: var(--muted);
}

button.primary {
  background: var(--accent);
  color: #1a1512;
  font-weight: 600;
  padding: 9px 16px;
  border: none;
}

button.primary:hover {
  background: color-mix(in srgb, var(--accent) 88%, #fff);
}

/* ---------- terminal ---------- */

#terminal {
  min-height: 0;
  padding: 6px 4px 0 8px;
  background: var(--bg);
}

.xterm .xterm-viewport {
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

.xterm .xterm-viewport::-webkit-scrollbar {
  width: 9px;
}

.xterm .xterm-viewport::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 5px;
}

/* ---------- key bar ---------- */

#keybar {
  display: none;
  gap: 5px;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--bg-raised);
  border-top: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
}

#keybar.show {
  display: flex;
}

#keybar button {
  flex: none;
  min-width: 42px;
  padding: 8px 10px;
  background: #262320;
  border: 1px solid var(--line);
  color: var(--fg);
  font-size: 12px;
}

#keybar button:active,
#keybar button.active {
  background: var(--accent);
  color: #1a1512;
}

@media (hover: none) and (pointer: coarse) {
  #keybar {
    display: flex;
  }
}

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(6px);
  z-index: 20;
}

.overlay[hidden] {
  display: none;
}

.card {
  width: min(420px, 100%);
  max-height: 90dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 24px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.55);
}

.card h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.card p {
  margin: 0;
  font-size: 12.5px;
}

.card label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
}

.card label.row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.card small {
  font-size: 11px;
  line-height: 1.45;
}

.card code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--accent);
}

input[type="text"],
input[type="password"],
input[type="number"],
select {
  font: inherit;
  padding: 9px 10px;
  background: #100f0e;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--fg);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

.card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.error {
  color: var(--bad);
  font-size: 12px;
}

.error[hidden] {
  display: none;
}

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 420px) {
  .pair {
    grid-template-columns: 1fr;
  }
}

/* ---------- wallet sign-in and admin ---------- */

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.small {
  font-size: 11.5px;
  line-height: 1.5;
}

.card.wide {
  width: min(560px, 100%);
}

.card h2 {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.card a {
  color: var(--accent);
}

#admin-token-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px;
  background: #100f0e;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.stat-label {
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 200px;
  overflow-y: auto;
}

.user-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 10px;
  background: #100f0e;
  border: 1px solid var(--line);
  border-radius: 6px;
}

@media (max-width: 480px) {
  .stat-row {
    grid-template-columns: 1fr;
  }

  .user-row {
    flex-direction: column;
    gap: 2px;
  }
}

#admin-admins-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

button.ghost.linked {
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 45%, transparent);
}

/* ---------- embedded: one bar, and the rest of the height to the terminal ---------- */

body.embedded {
  --bar-h: 30px;
}

body.embedded .bar {
  padding: 0 6px;
  font-size: 11px;
}

body.embedded .brand strong {
  font-size: 11px;
}

body.embedded #terminal {
  padding: 4px 2px 0 6px;
}

/* The folded actions. Anchored to the bar rather than the button so a narrow
   frame cannot push it off the right edge. */
#more-menu {
  position: absolute;
  top: calc(var(--bar-h) + env(safe-area-inset-top));
  right: 6px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 6px;
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

#more-menu[hidden] {
  display: none;
}

#more-menu button {
  text-align: left;
  white-space: nowrap;
}

#btn-fullscreen {
  text-decoration: none;
  line-height: 1;
  padding: 4px 8px;
}
