/* Shared styles for the boot page (index.html) and the example gallery.
   The design language (tokens, top bar, buttons, chips, home layout, cards,
   terminal pane) comes from the Elixir Playground (run-elixir.dev), with
   its orange accent replaced by the Nerves blues: #3ba7c6 and the logo's
   darker #32657f. In the light scheme the accent is a deeper blue so that
   text and focus rings on white keep their contrast. */

:root {
  --bg: #f6f7f8;
  --panel: #ffffff;
  --panel-2: #eef1f3;
  --fg: #1f2429;
  --muted: #66707a;
  --line: #dde2e6;
  --accent: #19718f;
  --accent-strong: #32657f;
  --accent-soft: #e2f1f7;
  /* Text on the accent (a primary button). */
  --on-accent: #ffffff;
  --focus: #6e4a9e;
  --term: #fcfdfd;
  --ok: #2b8a50;
  --warn: #b7791f;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #101317;
    --panel: #161a1f;
    --panel-2: #1d2228;
    --fg: #e5e9ee;
    --muted: #8f99a3;
    --line: #2a3038;
    --accent: #3ba7c6;
    --accent-strong: #6cc0d9;
    --accent-soft: #142c36;
    --on-accent: #101317;
    --focus: #b79ae0;
    --term: #13171c;
    --ok: #4cc27a;
    --warn: #e0a73a;
    color-scheme: dark;
  }
}

:root[data-theme='dark'] {
  --bg: #101317;
  --panel: #161a1f;
  --panel-2: #1d2228;
  --fg: #e5e9ee;
  --muted: #8f99a3;
  --line: #2a3038;
  --accent: #3ba7c6;
  --accent-strong: #6cc0d9;
  --accent-soft: #142c36;
  --on-accent: #101317;
  --focus: #b79ae0;
  --term: #13171c;
  --ok: #4cc27a;
  --warn: #e0a73a;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--fg);
  font:
    13px/1.45 system-ui,
    -apple-system,
    'Segoe UI',
    sans-serif;
}

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

button {
  font: inherit;
  color: inherit;
}

code {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

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

[hidden] {
  display: none !important;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Top bar */

.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  min-width: 0;
}

.brand {
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
  color: inherit;
  text-decoration: none;
}

.brand span,
.home-title span {
  color: var(--accent);
}

.title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.chip.accent {
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 40%, transparent);
}

.status {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: inherit;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}

.button:hover:not(:disabled) {
  border-color: var(--accent);
}

.button:disabled {
  opacity: 0.45;
  cursor: default;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

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

/* Home (the gallery) */

.home {
  min-height: 100%;
  overflow: auto;
}

.home-main {
  max-width: 880px;
  margin: 0 auto;
  padding: 40px 16px 64px;
  font-size: 14px;
}

.home-title {
  margin: 0 0 6px;
  font-size: 26px;
  font-weight: 700;
}

.home-lead {
  margin: 0 0 28px;
  max-width: 640px;
}

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

.home-alert {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 12px 0 0;
  padding: 10px 14px;
  border: 1px solid var(--warn);
  border-radius: 10px;
  background: color-mix(in srgb, var(--warn) 12%, transparent);
}

.home-footer {
  margin-top: 40px;
  color: var(--muted);
  font-size: 13px;
}

.home-footer a {
  color: inherit;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 12px;
}

.card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: inherit;
  text-decoration: none;
}

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

.card-icon {
  grid-row: span 3;
  color: var(--accent);
  padding-top: 1px;
}

.card-icon .icon {
  width: 20px;
  height: 20px;
}

.card-title {
  font-weight: 600;
}

.card-text {
  color: var(--muted);
  font-size: 13px;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.card-meta a {
  color: var(--muted);
  font-size: 12px;
}

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

/* Boot page */

.app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.terminal-col {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Extra keys for on-screen keyboards (index.html setupKeyBar), after
   unkernel's key bar. */
.key-bar {
  display: flex;
  flex: none;
  gap: 4px;
  overflow-x: auto;
  padding: 6px max(8px, env(safe-area-inset-right)) 6px max(8px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: var(--panel-2);
  touch-action: pan-x;
  user-select: none;
  -webkit-user-select: none;
  scrollbar-width: none;
}

.key-bar::-webkit-scrollbar {
  display: none;
}

/* Narrow screens: fade the right edge, so the bar reads as scrollable. */
@media (max-width: 700px) {
  .key-bar {
    mask-image: linear-gradient(to right, #000 calc(100% - 20px), transparent);
  }
}

.key-bar button {
  flex: 1 0 auto;
  min-width: 36px;
  height: 38px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--fg);
  font: 500 12.5px/1 system-ui, -apple-system, "Segoe UI", sans-serif;
  touch-action: manipulation;
}

.key-bar button.sym {
  font: 16px/1 ui-monospace, SFMono-Regular, monospace;
}

.key-bar button:active {
  background: var(--panel-2);
}

.key-bar button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.key-gap {
  flex: none;
  width: 1px;
  margin: 8px 1px;
  background: var(--line);
}

/* While the on-screen keyboard is up, the terminal gets the room that is left. */
html.kb .top-bar,
html.kb #devices,
html.kb #devices-separator {
  display: none !important;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
}

.terminal-host {
  position: relative;
  flex: 1;
  min-width: 0;
  min-height: 0;
  background: var(--term);
}

/* The padding is the root's, and xterm opens in the container inside it:
   the fit addon sizes the terminal to its parent element's height, which
   (with border-box) would include the padding and fit one row too many. */
.terminal-root {
  position: absolute;
  inset: 0;
  overflow: hidden;
  padding: 6px 0 4px 8px;
}

.terminal-container {
  width: 100%;
  height: 100%;
}

.terminal-host .xterm,
.terminal-host .xterm-viewport {
  background: var(--term) !important;
}

.separator {
  flex: none;
  width: 1px;
  background: var(--line);
}

.side-panel {
  width: 340px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  overflow: auto;
}

.side-section {
  padding: 12px 14px 16px;
  border-bottom: 1px solid var(--line);
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: -6px 0 4px;
}

.side-head .side-title {
  margin: 0;
}

/* The large screen: a wider side panel, still leaving the console room. */
body.screen-large .side-panel {
  width: min(680px, 55vw);
}

.side-title {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

#screen {
  display: block;
  width: 100%;
  image-rendering: pixelated;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 6px;
  touch-action: none;
}

#screen:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.gpio-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
}

.gpio-row .name {
  width: 60px;
  font-weight: 600;
}

.gpio-row .meta {
  flex: 1;
  color: var(--muted);
}

.led {
  width: 16px;
  height: 16px;
  flex: none;
  border-radius: 50%;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.led.on {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 70%, transparent);
}

.led-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 2px 0 8px;
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
  font-weight: 600;
}

.led-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.led.green.on {
  background: var(--ok);
  border-color: var(--ok);
  box-shadow: 0 0 10px color-mix(in srgb, var(--ok) 70%, transparent);
}

.led.red.on {
  background: #e5534b;
  border-color: #e5534b;
  box-shadow: 0 0 10px color-mix(in srgb, #e5534b 70%, transparent);
}

.gpio-row .button {
  min-width: 64px;
  justify-content: center;
  user-select: none;
  touch-action: none;
}

.gpio-row .button.down {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

@media (max-width: 800px) {
  .workspace {
    flex-direction: column;
  }

  .separator {
    width: auto;
    height: 1px;
  }

  .side-panel {
    width: auto;
    max-height: 50%;
  }

  body.screen-large .side-panel {
    width: auto;
    max-height: 75%;
  }

  .top-bar .status {
    display: none;
  }
}

/* Phones: icon-only buttons (aria-label keeps their names), a shorter bar. */
@media (max-width: 640px) {
  .top-bar {
    gap: 8px;
    padding: 8px 10px;
  }

  .top-bar .button .label,
  .top-bar .brand span {
    display: none;
  }

  .top-bar .button {
    padding: 5px 7px;
  }

  .top-bar .title {
    flex: 1;
    min-width: 0;
  }

  .top-bar .chip {
    display: none;
  }

  .dialog-row {
    flex-wrap: wrap;
  }

  .dialog-row .button {
    flex: 1;
    justify-content: center;
  }

  .snapshot-item {
    flex-wrap: wrap;
  }

  .snapshot-meta {
    flex-basis: 100%;
  }
}

/* Dialogs (the boot page's Snapshots) */

.dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 16px 18px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--fg);
  box-shadow: 0 20px 50px rgb(0 0 0 / 25%);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 35%);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 6px;
}

.dialog-header h2 {
  margin: 0;
  font-size: 16px;
}

.dialog-lead {
  margin: 0 0 14px;
}

.dialog-row {
  display: flex;
  gap: 8px;
}

.dialog-message {
  min-height: 1.45em;
  margin: 8px 0;
  color: var(--muted);
}

.dialog-message.error {
  color: var(--warn);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--accent);
}

.input {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: inherit;
  font: inherit;
}

.input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 0;
}

.button.danger {
  border-color: var(--warn);
  color: var(--warn);
}

.snapshot-list {
  margin: 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.snapshot-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.snapshot-meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.snapshot-meta b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.snapshot-meta .muted {
  font-size: 12px;
}

.snapshot-empty {
  padding: 12px 0;
}

/* Web preview (index.html setupPreview) */

.preview-pane {
  flex: 1.2;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.preview-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

.preview-port {
  flex: none;
  width: auto;
}

.preview-path {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 12px;
}

.preview-frame {
  flex: 1;
  width: 100%;
  min-height: 0;
  border: 0;
  background: #fff;
}

.preview-empty {
  margin: 0;
  padding: 24px 16px;
  color: var(--muted);
}

.top-bar .button .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
}

/* Phones and narrow windows: the preview covers the workspace. */
@media (max-width: 800px) {
  .workspace {
    position: relative;
  }

  .preview-pane {
    position: absolute;
    inset: 0;
    z-index: 5;
    border-left: 0;
  }
}
