/* Ludus visual system — see STYLE.md */

:root {
  color-scheme: light;
  --background: 40 25% 96%;
  --foreground: 30 10% 15%;
  --card: 40 30% 98%;
  --card-foreground: 30 10% 15%;
  --popover: 40 30% 98%;
  --popover-foreground: 30 10% 15%;
  --primary: 41 50% 50%;
  --primary-foreground: 0 0% 100%;
  --secondary: 40 15% 92%;
  --secondary-foreground: 30 10% 15%;
  --muted: 40 12% 90%;
  --muted-foreground: 30 8% 45%;
  --border: 35 12% 82%;
  --input: 35 12% 82%;
  --ring: 41 45% 45%;
  --destructive: 0 59% 49%;
  --success: 145 63% 42%;
  --warning: 43 96% 59%;
  --info: 220 70% 61%;
  --ribbon: 352 46% 40%;
  --ribbon-border: 352 16% 64%;
  --font-mono:
    "JetBrains Mono",
    ui-monospace,
    SFMono-Regular,
    Menlo,
    Monaco,
    Consolas,
    "Liberation Mono",
    "Courier New",
    monospace;
}

.dark {
  color-scheme: dark;
  --background: 220 15% 4%;
  --foreground: 60 10% 95%;
  --card: 220 12% 7%;
  --card-foreground: 60 10% 95%;
  --popover: 220 10% 12%;
  --popover-foreground: 60 10% 95%;
  --primary: 41 50% 55%;
  --primary-foreground: 0 0% 100%;
  --secondary: 220 10% 14%;
  --secondary-foreground: 60 8% 90%;
  --muted: 220 10% 10%;
  --muted-foreground: 220 5% 65%;
  --border: 220 10% 20%;
  --input: 220 10% 22%;
  --ring: 41 45% 50%;
  --destructive: 0 72% 51%;
  --success: 142 70% 50%;
  --warning: 46 95% 55%;
  --info: 214 90% 65%;
  --ribbon: 352 52% 58%;
  --ribbon-border: 352 14% 42%;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  border-radius: 0;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.5;
  letter-spacing: 0.02em;
  color: hsl(var(--foreground));
  background: hsl(var(--background));
  -webkit-font-smoothing: antialiased;
}

button,
input,
label {
  font: inherit;
  color: inherit;
}

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

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

.tabular {
  font-variant-numeric: tabular-nums;
}

/* —— Header (editor / console strip) —— */

.page-header {
  position: relative;
  background: hsl(var(--card));
  border-bottom: 1px solid hsl(var(--border) / 0.7);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.1);
  flex-shrink: 0;
}

.header-bg {
  pointer-events: none;
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image:
    linear-gradient(0deg, hsl(var(--primary) / 0.04) 1px, transparent 1px),
    linear-gradient(90deg, hsl(var(--primary) / 0.04) 1px, transparent 1px),
    linear-gradient(120deg, transparent, hsl(var(--primary) / 0.06), transparent);
  background-size: 24px 24px, 24px 24px, 200% 100%;
  animation: header-scan 6s linear infinite;
}

@keyframes header-scan {
  0% { background-position: 0 0, 0 0, 0% 0; }
  100% { background-position: 0 0, 0 0, 200% 0; }
}

.header-inner {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  flex-wrap: wrap;
}

.nav-plate {
  position: relative;
  background: hsl(var(--muted) / 0.55);
  border: 1px solid hsl(var(--border) / 0.7);
  padding: 6px 12px;
}

.nav-label {
  position: absolute;
  top: -7px;
  left: 8px;
  padding: 0 4px;
  background: hsl(var(--card));
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
  line-height: 1;
}

.page-title {
  margin: 0;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0.05em;
  line-height: 1.25;
  color: hsl(var(--foreground));
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.ribbon {
  height: 3px;
  background: linear-gradient(
    90deg,
    hsl(var(--primary)),
    hsl(var(--ribbon)),
    hsl(var(--primary))
  );
}

.ribbon[data-state="sending"] {
  background: linear-gradient(
    90deg,
    hsl(var(--primary)),
    hsl(var(--warning)),
    hsl(var(--primary))
  );
}

.ribbon[data-state="success"] {
  background: linear-gradient(
    90deg,
    hsl(var(--primary)),
    hsl(var(--success)),
    hsl(var(--primary))
  );
}

.ribbon[data-state="error"] {
  background: linear-gradient(
    90deg,
    hsl(var(--primary)),
    hsl(var(--destructive)),
    hsl(var(--primary))
  );
}

.ribbon[data-state="online"] {
  background: linear-gradient(
    90deg,
    hsl(var(--primary)),
    hsl(var(--success)),
    hsl(var(--primary))
  );
}

/* —— Workspace —— */

.workspace {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  min-height: 0;
  overflow: auto;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  justify-content: space-between;
}

.toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.toolbar-options {
  gap: 16px;
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
  gap: 16px;
  align-items: start;
  max-width: 960px;
}

/* —— Panels / cards —— */

.panel {
  background: hsl(var(--card));
  color: hsl(var(--card-foreground));
  padding: 16px;
  transition:
    box-shadow 200ms ease,
    background-color 200ms ease;
}

.panel:hover {
  background: hsl(var(--background));
  box-shadow: 0 2px 8px rgb(0 0 0 / 0.12);
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.section-label {
  margin: 0;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
}

.meta {
  font-size: 11px;
  letter-spacing: 0.05em;
  color: hsl(var(--muted-foreground));
  text-align: right;
}

.preview-stage {
  display: flex;
  justify-content: center;
  padding: 12px;
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border) / 0.65);
}

#preview {
  display: block;
  width: 256px;
  height: 256px;
  max-width: 100%;
  aspect-ratio: 1;
  image-rendering: pixelated;
  background: #000;
  border: 1px solid hsl(var(--border));
}

.status-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.status-line {
  margin: 0;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.02em;
  min-height: 1.5em;
}

.progress {
  height: 4px;
  background: hsl(var(--muted));
  border: 1px solid hsl(var(--border) / 0.6);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: hsl(var(--primary));
  transition: width 150ms ease;
}

.progress[data-state="sending"] .progress-fill {
  background: hsl(var(--warning));
}

.progress[data-state="success"] .progress-fill {
  background: hsl(var(--success));
}

.progress[data-state="error"] .progress-fill {
  background: hsl(var(--destructive));
}

.hint {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.02em;
  color: hsl(var(--muted-foreground));
  line-height: 1.5;
}

.sys-meta {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid hsl(var(--border) / 0.65);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
}

.sys-meta > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.sys-key {
  color: hsl(var(--muted-foreground));
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: 10px;
}

.sys-val {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* —— Corner brackets —— */

.tech-bracket {
  --bracket-size: 12px;
  --bracket-thickness: 1px;
  --bracket-color: hsl(var(--muted-foreground) / 0.5);
  --bracket-inset: 6px;
  position: relative;
}

.tech-bracket::before,
.tech-bracket::after {
  content: "";
  position: absolute;
  left: var(--bracket-inset);
  right: var(--bracket-inset);
  height: var(--bracket-size);
  pointer-events: none;
  transition:
    left 250ms cubic-bezier(0.34, 1.2, 0.64, 1),
    right 250ms cubic-bezier(0.34, 1.2, 0.64, 1),
    opacity 250ms ease;
  opacity: 0.5;
  background:
    linear-gradient(var(--bracket-color), var(--bracket-color)) 0 0 /
      var(--bracket-thickness) 100% no-repeat,
    linear-gradient(var(--bracket-color), var(--bracket-color)) 0 0 /
      var(--bracket-size) var(--bracket-thickness) no-repeat,
    linear-gradient(var(--bracket-color), var(--bracket-color)) 100% 0 /
      var(--bracket-thickness) 100% no-repeat,
    linear-gradient(var(--bracket-color), var(--bracket-color)) 100% 0 /
      var(--bracket-size) var(--bracket-thickness) no-repeat;
}

.tech-bracket::before {
  top: var(--bracket-inset);
}

.tech-bracket::after {
  bottom: var(--bracket-inset);
  transform: scaleY(-1);
}

.tech-bracket:hover {
  --bracket-inset: 0px;
  --bracket-color: hsl(var(--primary) / 0.85);
}

.tech-bracket:hover::before,
.tech-bracket:hover::after {
  opacity: 1;
}

/* —— Buttons —— */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  cursor: pointer;
  background: transparent;
  transition:
    background-color 150ms ease,
    border-color 150ms ease,
    color 150ms ease,
    opacity 150ms ease,
    transform 150ms ease,
    box-shadow 150ms ease;
}

.btn:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn-primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.1);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn-outline {
  background: hsl(var(--background));
  border-color: hsl(var(--input));
  color: hsl(var(--foreground));
}

.btn-outline:hover:not(:disabled) {
  background: hsl(var(--secondary));
}

.btn-secondary {
  background: hsl(var(--secondary));
  color: hsl(var(--secondary-foreground));
}

.btn-secondary:hover:not(:disabled) {
  background: hsl(var(--muted));
}

.btn-ghost {
  background: transparent;
  color: hsl(var(--foreground));
}

.btn-ghost:hover:not(:disabled) {
  background: hsl(var(--secondary));
}

.btn-destructive {
  background: hsl(var(--destructive));
  color: #fff;
}

.btn-destructive:hover:not(:disabled) {
  filter: brightness(1.05);
}

.btn-icon {
  width: 40px;
  padding: 0;
}

.file-btn {
  cursor: pointer;
}

/* —— Form controls —— */

.field-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  min-height: 32px;
}

.field-inline input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: hsl(var(--primary));
  cursor: pointer;
}

.field-inline input[type="checkbox"]:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
}

.field-label {
  color: hsl(var(--muted-foreground));
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 10px;
  font-weight: 500;
}

.input {
  height: 40px;
  padding: 0 12px;
  background: hsl(var(--background));
  border: 1px solid hsl(var(--input));
  color: hsl(var(--foreground));
}

.input-compact {
  height: 32px;
  width: 64px;
  padding: 0 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.input::placeholder {
  color: hsl(var(--muted-foreground));
}

.input:focus {
  outline: none;
  border-color: hsl(var(--primary));
  box-shadow: inset 0 0 0 2px hsl(var(--ring) / 0.45);
}

/* —— Status badge —— */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: auto;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid transparent;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  background: currentColor;
  flex-shrink: 0;
}

.badge[data-state="idle"] {
  color: hsl(var(--muted-foreground));
  background: hsl(var(--muted));
}

.badge[data-state="online"] {
  color: hsl(var(--success));
  background: hsl(var(--success) / 0.2);
}

.badge[data-state="sending"] {
  color: hsl(var(--warning));
  background: hsl(var(--warning) / 0.2);
}

.badge[data-state="success"] {
  color: hsl(var(--success));
  background: hsl(var(--success) / 0.2);
}

.badge[data-state="error"] {
  color: hsl(var(--destructive));
  background: hsl(var(--destructive) / 0.2);
}

/* —— Responsive —— */

@media (max-width: 640px) {
  .header-inner,
  .workspace {
    padding-left: 16px;
    padding-right: 16px;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  #preview {
    width: 200px;
    height: 200px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
