@import "https://cdn.jsdelivr.net/npm/tuicss@2.1.2/dist/tuicss.min.css";

/* =========================================================
   GLOBAL THEME APPLICATION
   Themes are driven by CSS variables on html[data-theme]
   ========================================================= */

html, body {
  background: var(--bg);
  color: var(--fg);
  margin: 0;
  padding: 0;
}

/* ---------------------------------------------------------
   Make TuiCss surfaces theme-aware
   --------------------------------------------------------- */

.tui-window,
.tui-panel,
.tui-fieldset,
.tui-input,
.tui-textarea,
.tui-select {
  background: var(--panel);
  color: var(--fg);
}

.tui-window,
.tui-panel,
.tui-fieldset,
.tui-input,
.tui-textarea,
.tui-select,
.tui-divider {
  border-color: var(--border) !important;
}

.tui-window-header,
.tui-window-footer {
  background: var(--panel2);
  color: var(--fg);
  border-color: var(--border) !important;
}

/* Inputs: make them visibly different from panels */
.tui-input,
.tui-textarea,
.tui-select {
  background: var(--panel2); /* lighter than panel */
  color: var(--fg);
  border-color: var(--border) !important;

  /* sunken bevel */
  box-shadow:
    inset 2px 2px 0 rgba(0, 0, 0, 0.75),
    inset -2px -2px 0 rgba(255, 255, 255, 0.18);
}

.tui-input,
.tui-textarea {
  caret-color: var(--fg);
}

/* Strong focus without modern glow */
.tui-input:focus,
.tui-textarea:focus,
.tui-select:focus {
  outline: none;
  border-color: var(--focus) !important;

  box-shadow:
    inset 2px 2px 0 rgba(0, 0, 0, 0.85),
    inset -2px -2px 0 rgba(255, 255, 255, 0.28),
    0 0 0 1px var(--focus);
}

/* Placeholder should be dimmer than real text */
.tui-input::placeholder,
.tui-textarea::placeholder {
  color: rgba(255, 255, 255, 0.55);
}


/* ---------------------------------------------------------
   Buttons (keep DOS depth, reduced shadow per your tweak)
   --------------------------------------------------------- */

.tui-button {
  color: var(--fg);
  background: var(--panel2);
  border-color: var(--border) !important;

  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.4),
    inset -1px -1px 0 rgba(0, 0, 0, 0.6),
    4px 4px 0 rgba(0, 0, 0, 0.8);
}

.tui-button:active {
  box-shadow:
    inset -1px -1px 0 rgba(255, 255, 255, 0.25),
    inset 1px 1px 0 rgba(0, 0, 0, 0.8);
}

.tui-button-primary {
  outline: 1px solid var(--focus);
}

.tui-button-danger {
  outline: 1px solid var(--danger);
}

/* ---------------------------------------------------------
   Text utilities mapped to theme
   --------------------------------------------------------- */

.tui-text-warning { color: var(--warn) !important; }
.tui-text-danger  { color: var(--danger) !important; }
.tui-text-success { color: var(--focus) !important; }
.tui-text-muted   { opacity: 0.75; }

/* =========================================================
   THEMES
   Explicit colors only (no color-mix for compatibility)
   ========================================================= */

/* ---- DOS BLUE (default) ---- */
html[data-theme="dos-blue"]{
  --bg: #000a2a;          /* deep navy */
  --fg: #ffffff;          /* white text */
  --panel: #00164a;       /* raised panel */
  --panel2: #002060;      /* header / alt panel */
  --border: rgba(255,255,255,0.35);
  --shadow-hi: rgba(255,255,255,0.14);
  --shadow-lo: rgba(0,0,0,0.75);
  --focus: rgba(120,170,255,0.7);
  --danger: #ff5555;
  --warn: #ffd27a;
}

/* ---- DOS CYAN ---- */
html[data-theme="dos-cyan"]{
  --bg: #00181a;          /* dark teal */
  --fg: #ffffff;
  --panel: #003033;
  --panel2: #004346;
  --border: rgba(191,252,255,0.38);
  --shadow-hi: rgba(191,252,255,0.14);
  --shadow-lo: rgba(0,0,0,0.75);
  --focus: rgba(0,255,255,0.7);
  --danger: #ff5555;
  --warn: #ffd27a;
}

/* ---- DOS AMBER ---- */
html[data-theme="dos-amber"]{
  --bg: #180c00;          /* dark brown */
  --fg: #ffffff;
  --panel: #2a1500;
  --panel2: #3a1d00;
  --border: rgba(255,210,122,0.4);
  --shadow-hi: rgba(255,210,122,0.14);
  --shadow-lo: rgba(0,0,0,0.78);
  --focus: rgba(255,210,122,0.7);
  --danger: #ff6b6b;
  --warn: #ffe6b0;
}

/* ---- DOS GREEN ---- */
html[data-theme="dos-green"]{
  --bg: #001100;          /* phosphor green */
  --fg: #ffffff;
  --panel: #002200;
  --panel2: #003300;
  --border: rgba(124,255,124,0.4);
  --shadow-hi: rgba(124,255,124,0.14);
  --shadow-lo: rgba(0,0,0,0.78);
  --focus: rgba(124,255,124,0.7);
  --danger: #ff6666;
  --warn: #b6ffb6;
}

/* ---- DOS MAGENTA ---- */
html[data-theme="dos-magenta"]{
  --bg: #140014;          /* deep purple */
  --fg: #ffffff;
  --panel: #2a002a;
  --panel2: #3a003a;
  --border: rgba(255,155,255,0.4);
  --shadow-hi: rgba(255,155,255,0.14);
  --shadow-lo: rgba(0,0,0,0.78);
  --focus: rgba(255,155,255,0.7);
  --danger: #ff6666;
  --warn: #ffd0ff;
}

/* ---- VGA GRAY ---- */
html[data-theme="vga-gray"]{
  --bg: #101010;
  --fg: #ffffff;
  --panel: #1a1a1a;
  --panel2: #232323;
  --border: rgba(230,230,230,0.3);
  --shadow-hi: rgba(255,255,255,0.1);
  --shadow-lo: rgba(0,0,0,0.8);
  --focus: rgba(230,230,230,0.6);
  --danger: #ff7777;
  --warn: #fff0a8;
}

/* ---- DOS BLUE BRIGHT + GREEN BUTTONS ---- */
html[data-theme="dos-blue95"]{
  /* brighter classic DOS blue */
  --bg: #001a66;
  --fg: #ffffff;

  --panel: #002a88;
  --panel2: #0039aa;

  --border: rgba(255,255,255,0.45);
  --shadow-hi: rgba(255,255,255,0.18);
  --shadow-lo: rgba(0,0,0,0.8);

  --focus: rgba(124,255,124,0.85);
  --danger: #ff5555;
  --warn: #ffd27a;

  /* green button palette */
  --btn-bg: #003d00;
  --btn-bg2: #005200;
  --btn-border: rgba(124,255,124,0.75);
  --btn-text: #ffffff;
}

/* =========================================================
   CRT FX (toggled via html[data-crt-glow="1"] and data-scanlines="1")
   ========================================================= */

/* make overlays sit above background but below UI */
body {
  position: relative;
}

/* Scanlines overlay (animated) */
html[data-scanlines="1"] body::before {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 2;

  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0.18) 0px,
    rgba(0,0,0,0.18) 1px,
    rgba(0,0,0,0.00) 2px,
    rgba(0,0,0,0.00) 4px
  );

  background-size: 100% 4px;
  animation: 
    scanline-drift 10s linear infinite,
    scanline-flicker 0.15s steps(2) infinite;

  mix-blend-mode: multiply;
  opacity: 0.55;
}

@keyframes scanline-drift {
  from {
    background-position: 0 0;
  }
  to {
    background-position: 0 4px;
  }
}

@keyframes scanline-flicker {
  0% { opacity: 0.52; }
  50% { opacity: 0.58; }
  100% { opacity: 0.52; }
}


/* CRT vignette + slight bloom */
html[data-crt-glow="1"] body::after {
  content: "";
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 3;

  background:
    radial-gradient(circle at center,
      rgba(255,255,255,0.05) 0%,
      rgba(0,0,0,0.15) 55%,
      rgba(0,0,0,0.35) 100%
    );

  mix-blend-mode: screen;
  opacity: 0.65;
}

/* Slight text phosphor glow (keep subtle) */
html[data-crt-glow="1"] .tui-window,
html[data-crt-glow="1"] .tui-panel,
html[data-crt-glow="1"] .tui-fieldset,
html[data-crt-glow="1"] .tui-window-title {
  text-shadow:
    0 0 6px rgba(255,255,255,0.12),
    0 0 12px rgba(255,255,255,0.06);
}

/* Optional: tiny bloom on borders */
html[data-crt-glow="1"] .tui-window,
html[data-crt-glow="1"] .tui-panel,
html[data-crt-glow="1"] .tui-fieldset {
  box-shadow:
    0 0 18px rgba(255,255,255,0.04);
}
/* =========================================================
   CRT FX
   ========================================================= */

/* Retrace bar overlay element (we render a div, CSS shows/hides it) */
.crt-retrace{
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 4;
  opacity: 0;
}

html[data-retrace] .crt-retrace{
  opacity: 0.9;
  background:
    linear-gradient(
      to bottom,
      rgba(255,255,255,0.00) 0%,
      rgba(255,255,255,0.00) 46%,
      rgba(255,255,255,0.10) 49%,
      rgba(255,255,255,0.22) 50%,
      rgba(255,255,255,0.10) 51%,
      rgba(255,255,255,0.00) 54%,
      rgba(255,255,255,0.00) 100%
    );
  mix-blend-mode: screen;
  transform: translateY(-60%);
  animation: retrace-sweep 6.5s linear infinite;
}

@keyframes retrace-sweep{
  from { transform: translateY(-60%); }
  to   { transform: translateY(60%); }
}

/* Warmup flash overlay (plays briefly on theme change) */
.crt-warmup{
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 5;
  opacity: 0;
}

.crt-warmup.is-on{
  animation: crt-warmup 650ms ease-out forwards;
  background:
    radial-gradient(circle at center,
      rgba(255,255,255,0.28) 0%,
      rgba(255,255,255,0.10) 35%,
      rgba(0,0,0,0.00) 65%
    );
  mix-blend-mode: screen;
}

@keyframes crt-warmup{
  0%   { opacity: 0; transform: scaleY(0.15); filter: blur(1px); }
  25%  { opacity: 1; transform: scaleY(0.40); filter: blur(0.5px); }
  60%  { opacity: 0.55; transform: scaleY(1.00); filter: blur(0px); }
  100% { opacity: 0; transform: scaleY(1.00); filter: blur(0px); }
}

/* =========================================================
   Barrel distortion (subtle curved glass, no SVG/WebGL)
   Enabled when: html[data-barrel]
   ========================================================= */

html[data-barrel] .tui-window {
  position: relative;
  border-radius: 10px;
  overflow: hidden;

  /* tiny perspective + micro scale so edges feel bowed */
  transform: perspective(1200px) scale(0.995);
  transform-origin: center;

  /* soft outer falloff */
  box-shadow:
    0 0 0 1px rgba(255,255,255,0.06),
    0 12px 28px rgba(0,0,0,0.35);
}

/* curved glass shading + vignette */
html[data-barrel] .tui-window::before {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: -3%;
  z-index: 10;

  background:
    /* center glow (very subtle) */
    radial-gradient(120% 90% at 50% 35%,
      rgba(255,255,255,0.045) 0%,
      rgba(0,0,0,0.00) 55%,
      rgba(0,0,0,0.18) 100%),

    /* edge darkening */
    radial-gradient(140% 120% at 50% 50%,
      rgba(0,0,0,0.00) 62%,
      rgba(0,0,0,0.28) 100%);

  mix-blend-mode: multiply;
  opacity: 0.95;
}

/* slight horizontal compression like curved CRT */
html[data-barrel] .tui-window-content {
  transform: scaleX(0.992);
  transform-origin: center;
}

/* optional: a tiny inner bevel to sell the glass */
html[data-barrel] .tui-window::after {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 11;

  box-shadow:
    inset 2px 2px 0 rgba(255,255,255,0.06),
    inset -2px -2px 0 rgba(0,0,0,0.35);

  opacity: 0.8;
}

/* Layout and component styles that *use* the theme vars. */

.app-shell {
  min-height: 100vh;
  padding: 12px;
  box-sizing: border-box;
}

.fill-window {
  width: 100%;
  max-width: 1400px;
  margin: 0 auto;
  min-height: calc(100vh - 24px);
  display: flex;
  flex-direction: column;
}

.fill-content {
  flex: 1;
  min-height: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.gear-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.gear-item {
  border: 1px solid var(--border);
  padding: 8px;
  background: var(--panel);
  box-shadow: inset 1px 1px 0 var(--shadow-hi), inset -1px -1px 0 var(--shadow-lo);
}

.gear-grid > .gear-item:nth-child(odd) {
  background: var(--panel2);
}

.gear-grid > .gear-item:nth-child(even) {
  background: var(--panel);
}

.gear-item .mini {
  padding: 0 8px;
  min-width: auto;
  height: 26px;
  line-height: 26px;
}

.role-box {
  border: 1px solid var(--border);
  padding: 8px;
  background: var(--panel);
  box-shadow: inset 1px 1px 0 var(--shadow-hi), inset -1px -1px 0 var(--shadow-lo);
  margin-bottom: 12px;
}

.role-box:focus-within {
  border-color: var(--focus);
  box-shadow: inset 1px 1px 0 var(--shadow-hi), 0 0 0 1px var(--focus);
}

.role-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 25px 25px;
  margin-bottom: 25px;
}

@media (max-width: 900px) {
  .role-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 650px) {
  .role-grid {
    grid-template-columns: 1fr;
  }
}

.gear-list-scroll {
  min-height: 360px;
  max-height: 55vh;
  overflow: auto;
  padding-right: 6px;
}

.picked-list {
  padding-left: 16px;
  margin: 6px 0 0;
}
.picked-list li {
  margin: 2px 0;
}

.label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.role-warning {
  min-width: 180px;
  text-align: right;
  font-size: 12px;
  color: var(--danger);
  visibility: hidden;
}
.role-warning.visible {
  visibility: visible;
}

.import-area {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.status-line {
  min-height: 1.2em;
  margin-top: 6px;
}
.spacer-below {
  margin-top: 12px;
  margin-bottom: 12px;
}
