:root {
  color-scheme: dark;
  --bg: #1a1a1a;
  --panel: #2c2c2c;
  --panel-accent: #3a3a3a;
  --text: #f0f0f0;
  --muted: #a7b2c6;
  --accent: #888;
  --accent-strong: #aaa;
  --border: #444;
  --border-strong: #666;
  --radius: 4px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  font-size: 13px;
}

.no-webgl body,
body.no-webgl {
  background:
    radial-gradient(1200px 800px at 10% 10%, rgba(79, 94, 142, 0.35), transparent 60%),
    radial-gradient(900px 700px at 90% 20%, rgba(52, 122, 108, 0.25), transparent 55%),
    radial-gradient(800px 600px at 70% 90%, rgba(120, 70, 130, 0.2), transparent 60%),
    linear-gradient(140deg, #151922 0%, #1c202b 45%, #141922 100%);
  background-attachment: fixed;
}

#bg-webgl {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  z-index: 0;
  pointer-events: none;
  display: block;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 4px;
  position: relative;
  z-index: 10;
}

.app__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2px 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.app__header h1 {
  margin: 0 0 2px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.app__header p {
  margin: 0;
  font-size: 11px;
  color: var(--muted);
}

.app__controls {
  display: flex;
  gap: 4px;
}


button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 10px;
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  border-radius: var(--radius);
  transition: all 0.15s ease;
}

button:hover {
  background: var(--panel-accent);
  border-color: var(--border-strong);
}

button:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Desktop (Windows container) */
.desktop {
  position: relative;
  flex: 1;
  background: transparent;
  overflow: auto; /* Allow scrolling if windows go beyond viewport */
  min-height: 600px;
  min-width: 1280px; /* Ensure minimum width for window layout */
}

/* Window (free-floating) */
.window {
  position: absolute;
  touch-action: none;
  user-select: none;
}

/* Widget */
.widget {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}

/* Active window (Windows-like) */
.window.active-window .widget {
  border-color: var(--border-strong);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.window.active-window .widget__title {
  background: var(--border-strong);
}

.widget__title {
  background: var(--panel-accent);
  border-bottom: 1px solid var(--border);
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  user-select: none;
  touch-action: none;
  transition: background 0.15s;
}

.widget__body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
}

/* Text Widget */
.text-widget p {
  margin: 0 0 8px;
  line-height: 1.5;
}

.text-widget strong {
  font-weight: 600;
}

.text-widget em {
  font-style: italic;
}

/* Video Widget */
.window[data-id="video"] .widget__body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 0 !important;
  background: #0f1115;
  overflow: hidden;
}

.video-widget {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  background: #0f1115;
  padding: 0 !important;
  overflow: hidden;
  flex: 1;
}

.video-widget iframe,
.video-widget .video-player {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: var(--radius);
  display: block;
  background: transparent;
}

/* Links Widget */
.links-widget ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.links-widget li {
  margin-bottom: 8px;
}

.links-widget a {
  color: var(--accent);
  text-decoration: none;
  transition: color 0.15s;
}

.links-widget a:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

/* Repo Widget */
.repo-widget__description {
  margin: 0 0 12px;
  line-height: 1.5;
}

.repo-widget__media {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
}

.window[data-id="smallsr"] .repo-widget__media {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-items: stretch;
}

.repo-widget__media iframe {
  display: block;
  background: #000;
  border: 0;
  border-radius: var(--radius);
}

.repo-widget__thumb {
  background: transparent;
  border: 1px solid var(--border);
  padding: 2px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.repo-widget__thumb:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.repo-widget__thumb img {
  display: block;
  width: 100px;
  height: auto;
  border-radius: calc(var(--radius) - 1px);
}

.window[data-id="smallsr"] .repo-widget__thumb img {
  width: 100%;
  height: auto;
}

.repo-widget__media-hint {
  font-size: 11px;
  color: var(--muted);
}

.repo-widget__section {
  margin-bottom: 12px;
}

.repo-widget__section h4 {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.repo-widget__section ul {
  list-style: disc;
  margin: 0;
  padding-left: 20px;
}

.repo-widget__section li {
  margin-bottom: 4px;
  line-height: 1.4;
}

.repo-widget__tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-block;
  background: var(--panel-accent);
  border: 1px solid var(--border);
  padding: 2px 8px;
  font-size: 11px;
  border-radius: var(--radius);
}

.repo-widget__actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.repo-widget__actions a {
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
  transition: color 0.15s;
}

.repo-widget__actions a:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

/* Image overlay */
.image-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 9999;
}

.image-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.image-overlay img {
  max-width: min(92vw, 1400px);
  max-height: 90vh;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
}

/* Chat Widget */
.chat-widget form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
}

.chat-widget__grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.chat-widget label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  color: var(--muted);
}

.chat-widget input,
.chat-widget textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
  border-radius: var(--radius);
  transition: border-color 0.15s;
}

.chat-widget input:focus,
.chat-widget textarea:focus {
  outline: none;
  border-color: var(--border-strong);
}

.chat-widget__message {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-widget__message textarea {
  flex: 1;
  min-height: 80px;
  resize: vertical;
}

.chat-widget__footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.chat-widget__status {
  font-size: 11px;
  flex: 1;
}

.chat-widget__status--idle {
  color: var(--muted);
}

.chat-widget__status--sending {
  color: var(--accent);
}

.chat-widget__status--sent {
  color: #4ade80;
}

.chat-widget__status--error {
  color: #ef4444;
}

/* Scrollbar */
.widget__body::-webkit-scrollbar {
  width: 8px;
}

.widget__body::-webkit-scrollbar-track {
  background: var(--bg);
}

.widget__body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius);
}

.widget__body::-webkit-scrollbar-thumb:hover {
  background: var(--border-strong);
}

/* Interact.js handles */
.window {
  box-sizing: border-box;
}

/* Dragging cursor */
.widget__title {
  cursor: move;
  cursor: grab;
}

.widget__title:active,
.window.dragging .widget__title {
  cursor: grabbing !important;
}

/* Resizing visuals */
.window.resizing {
  opacity: 0.9;
}

@media (max-width: 900px) {
  .desktop {
    min-width: 0 !important;
    min-height: auto;
    width: 100%;
    overflow: visible;
  }

  .window {
    position: static !important;
    width: 100% !important;
    height: auto !important;
    margin-bottom: 14px;
    touch-action: auto;
    user-select: auto;
  }

  .widget {
    height: auto;
  }

  .video-widget {
    height: auto;
  }

  .video-widget iframe {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
  }

  .repo-widget__media {
    flex-direction: column;
    align-items: stretch;
  }

  .repo-widget__media iframe {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
  }

  .repo-widget__thumb img {
    width: 100%;
    height: auto;
  }
}

/* Jetson YOLO dual video layout */
.window[data-id="jetson-yolo"] .repo-widget__media {
  align-items: stretch;
}

.window[data-id="jetson-yolo"] .jetson-yolo__video-pair {
  display: flex;
  gap: 8px;
  width: 100%;
}

.window[data-id="jetson-yolo"] .jetson-yolo__video-item {
  flex: 1 1 0;
  min-width: 0;
}

.window[data-id="jetson-yolo"] .jetson-yolo__video-item .video-player {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius);
}

.window[data-id="jetson-yolo"] .jetson-yolo__label {
  display: block;
  margin: 0 0 4px;
  font-size: 11px;
  color: var(--muted);
}

@media (max-width: 1024px) {
  .window[data-id="jetson-yolo"] .jetson-yolo__video-pair {
    flex-direction: column;
  }
}