/* Copyright © 2025 Skinsurf (SURFNET)
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
https://creativecommons.org/licenses/by-nc-sa/4.0/ */

/* ---------- SurfOS 2.0 theme colors (the `theme` command changes these) ---------- */
:root {
  --fg: #00FAB3;
  --fg-rgb: 0, 250, 179;
  --fg-bright: #6effd5;
  --fg-hi: #d0fff0;
  --fg-dim: rgba(var(--fg-rgb), 0.62);
  --bg: #000000;
  --panel: #00341a;
  --panel-2: #002b1a;
  --bar-bg: rgba(0, 10, 5, 0.92);
  --err: #ff6b81;
  --glow: 0 0 3px var(--fg);
  --term-font: 16px;
  --tabbar-h: 34px;
  --keys-h: 0px;
  --taskbar-h: 0px;
  --app-h: 100%;
}

[hidden] { display: none !important; }

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: 'Courier New', monospace;
  overflow: hidden;
  font-size: 3.5vw;
}

@media (min-width: 768px) {
  html, body {
    font-size: 16px;
  }
}

body::before {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: repeating-linear-gradient(
    to bottom,
    rgba(var(--fg-rgb), 0.08) 0px,
    rgba(var(--fg-rgb), 0.08) 1px,
    transparent 1px,
    transparent 2px
  );
  pointer-events: none;
  z-index: 9998;
}

body::after {
  content: "";
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: radial-gradient(circle at center, transparent 40%, rgba(0,0,0,0.4) 100%);
  pointer-events: none;
  z-index: 9998;
}

/* `crt off` */
body.no-crt::before, body.no-crt::after { display: none; }
body.no-crt { --glow: none; }

/* #terminal now holds the tabs and split panes; each pane scrolls on its own (.term below) */
#terminal {
  position: absolute;
  top: var(--tabbar-h);
  left: 0;
  width: 100%;
  height: calc(var(--app-h) - var(--tabbar-h) - var(--keys-h) - var(--taskbar-h)); /* leaves room for the minimized bar */
  box-sizing: border-box;
  overflow: hidden;
  z-index: 2;
  text-shadow: var(--glow);
}

#terminal.drop-target::after {
  content: "drop files to add them to /mnt/uploads · drop a folder to mount it";
  position: absolute;
  inset: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--fg);
  background: rgba(0, 0, 0, 0.75);
  z-index: 6;
  pointer-events: none;
}

.blinking-cursor {
  display: inline-block;
  width: 0.6em;
  background-color: var(--fg);
  animation: blink 1s step-end infinite;
  margin-left: 2px;
}

@keyframes blink {
  0%, 100% { background-color: var(--fg); }
  50% { background-color: transparent; }
}

#hiddenInput {
  position: absolute;
  top: -9999px;
  left: -9999px;
  opacity: 0;
  pointer-events: none;
  font-size: 16px; /* stops iOS from zooming in when the keyboard opens */
}

::selection {
  background: rgba(var(--fg-rgb), 0.25);
  color: #000;
}

a {
  color: var(--fg);
  text-decoration: underline;
  transition: opacity 0.1s ease;
}

a:hover, a:focus {
  color: var(--fg-bright);
  text-decoration: none;
}

#minimizedWindows {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  background: var(--bar-bg);
  backdrop-filter: blur(4px);
  padding: 8px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  z-index: 10000;
  border-top: 1px solid var(--fg);
  box-shadow: 0 -2px 6px rgba(var(--fg-rgb), 0.2);
}

#minimizedWindows:empty { display: none; }

.minimized-window-btn {
  background: #000000;
  color: var(--fg);
  border: 1px solid var(--fg);
  font-family: 'Courier New', monospace;
  font-size: 0.85rem;
  font-weight: bold;
  padding: 8px 14px;
  cursor: pointer;
  transition: all 0.1s ease;
  border-radius: 0;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.minimized-window-btn:hover,
.minimized-window-btn:focus {
  background: var(--panel-2);
  color: var(--fg-hi);
  border-color: var(--fg-bright);
  outline: none;
}

@media (max-width: 768px) {
  .minimized-window-btn {
    padding: 10px 16px;
    font-size: 0.9rem;
    min-height: 44px;
  }
  #minimizedWindows {
    padding: 8px;
    gap: 8px;
  }
}

[id^="browserWindow"], [id$="Window"] {
  box-shadow: 0 0 18px rgba(var(--fg-rgb), 0.4);
  background: black;
  border-radius: 0;
}

@media (max-width: 768px) {
  div[id^="browserWindow"], div[id$="Window"] {
    top: 2vh !important;
    left: 2vw !important;
    width: 96vw !important;
    height: 88vh !important;
  }
}

/* ==========================================================================
   SurfOS 2.0 — tab bar
   ========================================================================== */

#tabbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: var(--tabbar-h);
  display: flex;
  align-items: stretch;
  background: var(--bar-bg);
  border-bottom: 1px solid rgba(var(--fg-rgb), 0.5);
  font-size: 13px;
  text-shadow: var(--glow);
  user-select: none;
  z-index: 3;
}

#tabs {
  display: flex;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
#tabs::-webkit-scrollbar { display: none; }

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 96px;
  max-width: 230px;
  padding: 0 4px 0 10px;
  border-right: 1px solid rgba(var(--fg-rgb), 0.25);
  color: var(--fg-dim);
  white-space: nowrap;
  cursor: pointer;
}
.tab:hover { color: var(--fg); background: var(--panel-2); }
.tab.active { color: var(--bg); background: var(--fg); text-shadow: none; }
.tab-index { font-size: 11px; opacity: 0.7; }
.tab-title { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.tab-close {
  background: none;
  border: 0;
  color: inherit;
  font: inherit;
  font-size: 16px;
  line-height: 1;
  padding: 0 5px;
  opacity: 0.55;
  cursor: pointer;
}
.tab-close:hover, .tab-close:focus-visible { opacity: 1; outline: none; }
.tab-rename {
  width: 130px;
  padding: 1px 4px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--fg);
  font: inherit;
}

.tabbar-btn {
  min-width: 36px;
  background: none;
  border: 0;
  border-right: 1px solid rgba(var(--fg-rgb), 0.25);
  color: var(--fg);
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
}
.tabbar-btn:hover, .tabbar-btn:focus-visible { background: var(--panel-2); color: var(--fg-hi); outline: none; }
.tabbar-spacer { flex: 1; }
.tabbar-right { display: flex; border-left: 1px solid rgba(var(--fg-rgb), 0.25); }
.tabbar-right .tabbar-btn:last-child { border-right: 0; }

/* ==========================================================================
   panes & splits
   ========================================================================== */

.tab-view { position: absolute; inset: 0; }

.pane { position: absolute; overflow: hidden; background: var(--bg); }
.tab-view.multi .pane { box-shadow: inset 0 0 0 1px rgba(var(--fg-rgb), 0.15); }
.tab-view.multi .pane.active { box-shadow: inset 0 0 0 1px rgba(var(--fg-rgb), 0.55); }

/* one terminal (was #terminal) */
.term {
  position: absolute;
  inset: 0;
  padding: 12px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: var(--term-font);
}
.tab-view.multi .term { padding: 8px 10px; }

.out:empty::before { content: "\200b"; }
.out.err { color: var(--err); text-shadow: 0 0 3px rgba(255, 107, 129, 0.45); }
.dim { color: var(--fg-dim); }
.inv { background: var(--fg); color: var(--bg); text-shadow: none; }
.hl { background: rgba(var(--fg-rgb), 0.3); color: var(--fg-hi); }

/* cursor inside a line of text: show the character under it */
.term .blinking-cursor {
  width: auto;
  min-width: 0.6em;
  margin-left: 0;
  animation-name: blink-char;
}
@keyframes blink-char {
  0%, 100% { background-color: var(--fg); color: var(--bg); text-shadow: none; }
  50% { background-color: transparent; color: inherit; }
}
.pane:not(.active) .blinking-cursor,
body:not(.focused) .blinking-cursor {
  animation: none;
  background: transparent;
  color: inherit;
  outline: 1px solid rgba(var(--fg-rgb), 0.7);
  outline-offset: -1px;
}

.cmd-link {
  cursor: pointer;
  text-decoration: underline dotted rgba(var(--fg-rgb), 0.45);
  text-underline-offset: 3px;
}
.cmd-link:hover { color: var(--fg-hi); text-decoration: underline solid; }
.ls-dir, .ls-mount, .ls-file, .ls-media { text-decoration: none; }
.ls-dir { color: var(--fg-bright); font-weight: bold; }
.ls-mount { color: var(--fg-hi); font-weight: bold; }
.ls-media { color: var(--fg); font-style: italic; }

/* command lists (help, net, files …): two columns, stacked in narrow panes */
.term { container-type: inline-size; }
.cat-head { padding-left: 2ch; color: var(--fg-dim); }
.cat-head.gap { margin-top: 1.2em; }
.cat-row {
  display: grid;
  grid-template-columns: var(--w, 24ch) minmax(0, 1fr);
  column-gap: 1ch;
  padding-left: var(--indent, 2ch);
}
@container (max-width: 560px) {
  .cat-row { grid-template-columns: minmax(0, 1fr); }
  .cat-row > .dim { padding-left: 2ch; margin-bottom: 0.25em; }
}

.divider { position: absolute; z-index: 5; touch-action: none; }
.divider-row { width: 9px; margin-left: -4px; cursor: col-resize; }
.divider-col { height: 9px; margin-top: -4px; cursor: row-resize; }
.divider::after { content: ""; position: absolute; background: rgba(var(--fg-rgb), 0.45); }
.divider-row::after { left: 4px; top: 0; bottom: 0; width: 1px; }
.divider-col::after { top: 4px; left: 0; right: 0; height: 1px; }
.divider:hover::after { background: var(--fg); box-shadow: 0 0 6px var(--fg); }

body.wm-dragging { user-select: none; }
body.wm-dragging iframe { pointer-events: none; }
body.resizing-x, body.resizing-x * { cursor: col-resize !important; }
body.resizing-y, body.resizing-y * { cursor: row-resize !important; }

/* a web page inside a pane (ssh/sftp gateways, open -t) */
.web-pane { display: flex; flex-direction: column; }
.web-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 6px 3px 10px;
  background: var(--panel);
  font-size: 13px;
  white-space: nowrap;
}
.web-title { font-weight: bold; }
.web-url { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--fg-dim); }
.web-btn {
  padding: 0 7px;
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--fg);
  font-family: inherit;
  cursor: pointer;
}
.web-btn:hover { background: var(--panel-2); color: var(--fg-hi); }
.web-frame { flex: 1; width: 100%; border: 0; }
iframe.light { background: #fff; }

.cmatrix { position: absolute; inset: 0; z-index: 4; background: #000; cursor: pointer; }

/* ==========================================================================
   windows
   ========================================================================== */

#windowLayer { position: fixed; inset: 0; z-index: 9999; pointer-events: none; }

.sos-window {
  position: fixed;
  display: flex;
  flex-direction: column;
  min-width: 260px;
  min-height: 160px;
  background: black;
  border: 2px solid var(--fg);
  box-shadow: 0 0 10px var(--fg);
  pointer-events: auto;
  resize: both;
  overflow: hidden;
}
.sos-window.focused { box-shadow: 0 0 18px rgba(var(--fg-rgb), 0.6); }
.sos-window.maximized {
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: calc(var(--app-h) - var(--taskbar-h)) !important;
  resize: none;
}
.sos-window-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 5px;
  background: var(--panel);
  text-shadow: var(--glow);
  cursor: move;
  user-select: none;
  touch-action: none;
}
.sos-window.maximized .sos-window-bar { cursor: default; }
.sos-window-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sos-window-actions { display: flex; flex-shrink: 0; gap: 5px; }
.sos-window-btn {
  background: black;
  color: var(--fg);
  border: 1px solid var(--fg);
  font-family: monospace;
  cursor: pointer;
}
.sos-window-btn:hover, .sos-window-btn:focus-visible { background: var(--panel-2); color: var(--fg-hi); outline: none; }
.sos-window-body { position: relative; flex: 1; min-height: 0; }
.sos-window-frame { display: block; width: 100%; height: 100%; border: none; }

/* editor (edit / nano) */
.sos-editor-wrap { position: absolute; inset: 0; display: flex; flex-direction: column; }
.sos-editor-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px;
  border-bottom: 1px solid rgba(var(--fg-rgb), 0.3);
  font-size: 13px;
}
.sos-editor-status { flex: 1; color: var(--fg-dim); }
.sos-editor {
  flex: 1;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  outline: none;
  resize: none;
  background: var(--bg);
  color: var(--fg);
  caret-color: var(--fg-hi);
  font-family: 'Courier New', monospace;
  font-size: var(--term-font);
  line-height: 1.35;
  text-shadow: var(--glow);
  white-space: pre;
  overflow: auto;
  tab-size: 2;
}

/* ==========================================================================
   phones & tablets
   ========================================================================== */

#mobileKeys { display: none; }

@media (max-width: 768px) {
  :root { --term-font: 14px; --tabbar-h: 40px; }
  .term {
    padding: 8px;
    line-height: 1.4;
  }
  .tab { min-width: 76px; }
  .tabbar-btn { min-width: 40px; }
  .sos-window-btn { padding: 4px 6px; }
}

@media (pointer: coarse) {
  :root { --keys-h: 44px; }
  #mobileKeys {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(var(--app-h) - var(--keys-h) - var(--taskbar-h));
    height: var(--keys-h);
    display: flex;
    gap: 4px;
    padding: 4px;
    overflow-x: auto;
    background: var(--bar-bg);
    border-top: 1px solid rgba(var(--fg-rgb), 0.5);
    z-index: 3;
  }
  #mobileKeys button {
    flex: 1 0 auto;
    min-width: 44px;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid rgba(var(--fg-rgb), 0.6);
    font-family: inherit;
    font-size: 14px;
  }
  #mobileKeys button:active { background: var(--panel); }
}

@media (prefers-reduced-motion: reduce) {
  .blinking-cursor, .term .blinking-cursor { animation: none; }
}
