/* ==========================================================================
 * KREBF Z-Machine Player — stylesheet v1.1.0
 *
 * All styles are scoped to .krebf-root and use --krebf-* custom properties
 * so we never collide with the host WordPress theme. Four visual themes
 * are selected via data-krebf-theme="…" on the root:
 *
 *    amber       — original retro amber-CRT look (default)
 *    green       — classic green phosphor, VT100 feel
 *    paperwhite  — light-mode reader theme, serif body, no CRT effects
 *    inherit     — borrows the WordPress theme's colors and font; no
 *                  scanlines or glow; suitable for minimalist sites
 *
 * Everything that used to be a hard-coded px dimension now scales from the
 * container width via clamp() and container queries, so the player remains
 * usable from a 320px mobile column up to a full 1200px desktop layout.
 * ========================================================================== */


/* ============ baseline variables (shared across all themes) ============== */
.krebf-root {
  /* Structural — always the same */
  --krebf-radius: 8px;
  --krebf-radius-sm: 3px;
  --krebf-padding: clamp(6px, 1.5cqw, 14px);
  --krebf-gap: clamp(6px, 1.2cqw, 12px);
  --krebf-border: 1px;

  /* Responsive typography — scales with container width */
  --krebf-screen-font-size: clamp(12px, 2.2cqw, 20px);
  --krebf-body-font-size:   clamp(12px, 1.4cqw, 14px);
  --krebf-btn-font-size:    clamp(10px, 1.2cqw, 13px);
  --krebf-mark-font-size:   clamp(16px, 2.6cqw, 26px);
  --krebf-sub-font-size:    clamp(10px, 1.1cqw, 13px);
  --krebf-led-size:         clamp(6px, 1cqw, 9px);

  /* Animations */
  --krebf-transition: 150ms ease;

  position: relative;
  display: block;
  width: 100%;
  max-width: 100%;
  min-height: 0;
  overflow: hidden;
  border-radius: var(--krebf-radius);
  box-sizing: border-box;

  /* Enable container queries so cqw units resolve against this element's width */
  container-type: inline-size;
  container-name: krebf;
}

.krebf-root *,
.krebf-root *::before,
.krebf-root *::after {
  box-sizing: border-box;
}
.krebf-root *:focus {
  outline: none;
}
.krebf-root *:focus-visible {
  outline: 2px solid var(--krebf-accent);
  outline-offset: 1px;
}


/* ============ THEME: amber (default retro look) ========================== */
.krebf-root,
.krebf-root[data-krebf-theme="amber"] {
  --krebf-bg-deep:      #0a0806;
  --krebf-bg-panel:     #141210;
  --krebf-bg-panel-2:   #1c1915;
  --krebf-screen-bg:    #0a0806;
  --krebf-accent:       #ffb547;
  --krebf-accent-bright:#ffd89a;
  --krebf-accent-dim:   #8a5a1f;
  --krebf-accent-glow:  rgba(255, 181, 71, 0.35);
  --krebf-brass:        #c08a3e;
  --krebf-brass-dark:   #6b4a20;
  --krebf-text:         #f4e4c1;
  --krebf-text-muted:   #a89572;
  --krebf-ink:          #2a1f14;
  --krebf-rule:         rgba(255, 181, 71, 0.15);
  --krebf-led-on:       #ffb547;
  --krebf-led-off:      #3a2b16;
  --krebf-led-green:    #5aff8c;
  --krebf-led-red:      #ff5a3c;
  --krebf-screen-family:'VT323', 'JetBrains Mono', ui-monospace, monospace;
  --krebf-ui-family:    'Cormorant Garamond', Georgia, serif;
  --krebf-mono-family:  'JetBrains Mono', ui-monospace, monospace;
  --krebf-brand-family: 'Major Mono Display', monospace;
  --krebf-text-shadow:  0 0 4px var(--krebf-accent-glow);
  --krebf-scanlines:    visible;
}

.krebf-root[data-krebf-theme="amber"] {
  background: var(--krebf-bg-deep);
  color: var(--krebf-text);
  font-family: var(--krebf-ui-family);
  box-shadow: 0 8px 32px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,181,71,0.1);
}


/* ============ THEME: green (VT100 phosphor) ============================== */
.krebf-root[data-krebf-theme="green"] {
  --krebf-bg-deep:      #040a04;
  --krebf-bg-panel:     #0a140a;
  --krebf-bg-panel-2:   #121c12;
  --krebf-screen-bg:    #040a04;
  --krebf-accent:       #5aff8c;
  --krebf-accent-bright:#aaffc8;
  --krebf-accent-dim:   #3a8a52;
  --krebf-accent-glow:  rgba(90, 255, 140, 0.30);
  --krebf-brass:        #4aa874;
  --krebf-brass-dark:   #2a6040;
  --krebf-text:         #c4e8c8;
  --krebf-text-muted:   #6ba078;
  --krebf-ink:          #0a1a0e;
  --krebf-rule:         rgba(90, 255, 140, 0.15);
  --krebf-led-on:       #5aff8c;
  --krebf-led-off:      #1a3322;
  --krebf-led-green:    #5aff8c;
  --krebf-led-red:      #ff8050;
  --krebf-screen-family:'VT323', 'JetBrains Mono', ui-monospace, monospace;
  --krebf-ui-family:    'Cormorant Garamond', Georgia, serif;
  --krebf-mono-family:  'JetBrains Mono', ui-monospace, monospace;
  --krebf-brand-family: 'Major Mono Display', monospace;
  --krebf-text-shadow:  0 0 4px var(--krebf-accent-glow);
  --krebf-scanlines:    visible;

  background: var(--krebf-bg-deep);
  color: var(--krebf-text);
  font-family: var(--krebf-ui-family);
  box-shadow: 0 8px 32px rgba(0,0,0,0.6), 0 0 0 1px rgba(90,255,140,0.08);
}


/* ============ THEME: paperwhite (light, serif, reader-friendly) ========== */
.krebf-root[data-krebf-theme="paperwhite"] {
  --krebf-bg-deep:      #f5f0e4;
  --krebf-bg-panel:     #ebe4d2;
  --krebf-bg-panel-2:   #e0d8c4;
  --krebf-screen-bg:    #faf5e8;
  --krebf-accent:       #7a4820;
  --krebf-accent-bright:#a16a32;
  --krebf-accent-dim:   #b8a484;
  --krebf-accent-glow:  rgba(122, 72, 32, 0.15);
  --krebf-brass:        #9a7040;
  --krebf-brass-dark:   #7a5830;
  --krebf-text:         #2a1f14;
  --krebf-text-muted:   #6a5a44;
  --krebf-ink:          #f5f0e4;
  --krebf-rule:         rgba(122, 72, 32, 0.18);
  --krebf-led-on:       #c08a3e;
  --krebf-led-off:      #c8b898;
  --krebf-led-green:    #4a7030;
  --krebf-led-red:      #a83030;
  --krebf-screen-family:'Cormorant Garamond', Georgia, serif;
  --krebf-ui-family:    'Cormorant Garamond', Georgia, serif;
  --krebf-mono-family:  'JetBrains Mono', ui-monospace, monospace;
  --krebf-brand-family: 'Cormorant Garamond', Georgia, serif;
  --krebf-text-shadow:  none;
  --krebf-scanlines:    none;

  background: var(--krebf-bg-deep);
  color: var(--krebf-text);
  font-family: var(--krebf-ui-family);
  box-shadow: 0 4px 16px rgba(0,0,0,0.12), 0 0 0 1px rgba(122,72,32,0.18);
}


/* ============ THEME: inherit (borrow colours/fonts from WP theme) ======== */
.krebf-root[data-krebf-theme="inherit"] {
  --krebf-bg-deep:      transparent;
  --krebf-bg-panel:     color-mix(in srgb, currentColor 8%, transparent);
  --krebf-bg-panel-2:   color-mix(in srgb, currentColor 14%, transparent);
  --krebf-screen-bg:    color-mix(in srgb, currentColor 4%, transparent);
  --krebf-accent:       currentColor;
  --krebf-accent-bright:currentColor;
  --krebf-accent-dim:   color-mix(in srgb, currentColor 60%, transparent);
  --krebf-accent-glow:  transparent;
  --krebf-brass:        color-mix(in srgb, currentColor 50%, transparent);
  --krebf-brass-dark:   color-mix(in srgb, currentColor 30%, transparent);
  --krebf-text:         currentColor;
  --krebf-text-muted:   color-mix(in srgb, currentColor 65%, transparent);
  --krebf-ink:          currentColor;
  --krebf-rule:         color-mix(in srgb, currentColor 18%, transparent);
  --krebf-led-on:       currentColor;
  --krebf-led-off:      color-mix(in srgb, currentColor 20%, transparent);
  --krebf-led-green:    #4a7030;
  --krebf-led-red:      #a83030;
  --krebf-screen-family:inherit;
  --krebf-ui-family:    inherit;
  --krebf-mono-family:  ui-monospace, 'JetBrains Mono', monospace;
  --krebf-brand-family: inherit;
  --krebf-text-shadow:  none;
  --krebf-scanlines:    none;

  background: transparent;
  color: inherit;
  font-family: inherit;
  box-shadow: 0 0 0 1px var(--krebf-rule);
}


/* ============ SCANLINE / GRAIN OVERLAYS (only retro themes) ============== */
.krebf-root[data-krebf-theme="amber"]::before,
.krebf-root[data-krebf-theme="green"]::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.05;
  z-index: 999;
  background: radial-gradient(ellipse at 50% 0%, var(--krebf-accent-glow), transparent 60%);
}


/* ============ FRAME LAYOUT =============================================== */
.krebf-root .krebf-frame {
  height: 100%;
  width: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding: var(--krebf-padding);
  gap: var(--krebf-gap);
  min-height: 0;
  min-width: 0;
}


/* ============ HEADER ===================================================== */
.krebf-root .krebf-titlebar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: clamp(8px, 1.5cqw, 20px);
  padding: clamp(6px, 1cqw, 10px) clamp(8px, 1.5cqw, 18px);
  background: linear-gradient(180deg, var(--krebf-bg-panel-2) 0%, var(--krebf-bg-panel) 100%);
  border: 1px solid var(--krebf-rule);
  border-radius: var(--krebf-radius-sm);
  min-width: 0;
}

.krebf-root .krebf-logo {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
  overflow: hidden;
}
.krebf-root .krebf-mark {
  font-family: var(--krebf-brand-family);
  font-size: var(--krebf-mark-font-size);
  letter-spacing: 0.12em;
  color: var(--krebf-accent);
  text-shadow: var(--krebf-text-shadow);
  line-height: 1;
}
.krebf-root .krebf-sub {
  font-family: var(--krebf-ui-family);
  font-style: italic;
  font-size: var(--krebf-sub-font-size);
  color: var(--krebf-accent-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.krebf-root .krebf-header-mid {
  display: flex;
  gap: clamp(8px, 1.2cqw, 16px);
  justify-content: center;
  flex-wrap: wrap;
  min-width: 0;
}
.krebf-root .krebf-indicator {
  display: flex;
  gap: 5px;
  align-items: center;
  font-family: var(--krebf-mono-family);
  font-size: var(--krebf-btn-font-size);
  letter-spacing: 0.08em;
  color: var(--krebf-accent-dim);
}
.krebf-root .krebf-led {
  display: inline-block;
  width: var(--krebf-led-size);
  height: var(--krebf-led-size);
  border-radius: 50%;
  background: var(--krebf-led-off);
  transition: background var(--krebf-transition), box-shadow var(--krebf-transition);
}
.krebf-root .krebf-led.krebf-on {
  background: var(--krebf-led-on);
  box-shadow: 0 0 6px var(--krebf-accent-glow);
}
.krebf-root .krebf-led-green.krebf-on {
  background: var(--krebf-led-green);
  box-shadow: 0 0 6px color-mix(in srgb, var(--krebf-led-green) 60%, transparent);
}

.krebf-root .krebf-ctrl-group {
  display: flex;
  gap: clamp(4px, 0.6cqw, 8px);
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}
.krebf-root .krebf-right {
  justify-content: flex-end;
}


/* ============ BUTTONS & DROPDOWN ========================================= */
.krebf-root .krebf-btn {
  font-family: var(--krebf-mono-family);
  font-size: var(--krebf-btn-font-size);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--krebf-text);
  background: linear-gradient(180deg, var(--krebf-bg-panel-2) 0%, var(--krebf-bg-panel) 100%);
  border: 1px solid var(--krebf-brass-dark);
  border-radius: var(--krebf-radius-sm);
  padding: clamp(4px, 0.8cqw, 8px) clamp(8px, 1.4cqw, 14px);
  cursor: pointer;
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--krebf-accent) 10%, transparent), 0 1px 3px rgba(0,0,0,0.35);
  transition: all var(--krebf-transition);
  white-space: nowrap;
}
.krebf-root .krebf-btn:hover {
  border-color: var(--krebf-accent);
  color: var(--krebf-accent-bright);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--krebf-accent) 18%, transparent), 0 0 10px var(--krebf-accent-glow);
}
.krebf-root .krebf-btn.krebf-primary {
  background: linear-gradient(180deg, color-mix(in srgb, var(--krebf-accent) 12%, var(--krebf-bg-panel-2)) 0%, var(--krebf-bg-panel) 100%);
  border-color: var(--krebf-accent);
  color: var(--krebf-accent);
  text-shadow: var(--krebf-text-shadow);
}
.krebf-root .krebf-btn.krebf-primary:hover { color: var(--krebf-accent-bright); }
.krebf-root .krebf-btn.krebf-ghost {
  background: transparent;
  border-color: var(--krebf-brass-dark);
  color: var(--krebf-text-muted);
}
.krebf-root .krebf-btn.krebf-ghost:hover {
  color: var(--krebf-accent);
  border-color: var(--krebf-brass);
}
.krebf-root .krebf-dropdown {
  min-width: clamp(120px, 18cqw, 200px);
  max-width: 100%;
  appearance: none;
  -webkit-appearance: none;
  padding-right: clamp(20px, 2cqw, 28px);
  background-image: linear-gradient(45deg, transparent 50%, var(--krebf-accent-dim) 50%),
                    linear-gradient(135deg, var(--krebf-accent-dim) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.krebf-root .krebf-file-input-label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.krebf-root .krebf-file-input-label input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}


/* ============ DISPLAY / SCREEN =========================================== */
.krebf-root .krebf-display {
  position: relative;
  background: var(--krebf-screen-bg);
  border: 1px solid var(--krebf-rule);
  border-radius: var(--krebf-radius-sm);
  overflow: hidden;
  min-height: 0;
  min-width: 0;
}

/* Scanlines (amber + green only) */
.krebf-root[data-krebf-theme="amber"] .krebf-display::before,
.krebf-root[data-krebf-theme="green"] .krebf-display::before {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    0deg,
    transparent 0,
    transparent 2px,
    color-mix(in srgb, var(--krebf-accent) 5%, transparent) 2px,
    color-mix(in srgb, var(--krebf-accent) 5%, transparent) 3px
  );
  z-index: 10;
  opacity: 0.5;
}
/* Vignette on amber/green */
.krebf-root[data-krebf-theme="amber"] .krebf-display::after,
.krebf-root[data-krebf-theme="green"] .krebf-display::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 80px rgba(0,0,0,0.45);
  z-index: 9;
}

.krebf-root .krebf-screen-wrap {
  position: relative;
  padding: clamp(8px, 1.4cqw, 20px);
  height: 100%;
  width: 100%;
  overflow: hidden;
  z-index: 2;
  min-width: 0;
}

.krebf-root .krebf-screen {
  font-family: var(--krebf-screen-family);
  font-size: var(--krebf-screen-font-size);
  line-height: 1.15;
  color: var(--krebf-accent);
  text-shadow: var(--krebf-text-shadow);
  white-space: pre;
  height: 100%;
  width: 100%;
  overflow: hidden;
  letter-spacing: 0.02em;
  word-break: normal;
  overflow-wrap: normal;
}

/* Theme-specific overrides for the screen text color */
.krebf-root[data-krebf-theme="paperwhite"] .krebf-screen {
  color: var(--krebf-text);
  letter-spacing: normal;
  line-height: 1.4;
  white-space: pre-wrap;
}
.krebf-root[data-krebf-theme="inherit"] .krebf-screen {
  color: var(--krebf-text);
  white-space: pre-wrap;
}

/* Upper-window lines have no visual decoration — they're plain text just
 * like the lower window. The previous attempt to highlight the upper
 * window with a left border / tinted background produced visible separator
 * lines between consecutive menu items in PunyInform's talk_menu and
 * similar UIs that print one item per upper-window line. Z-machine
 * interpreters do not visually distinguish the upper window. */
.krebf-root .krebf-screen .upper {
  display: block;
}
.krebf-root .krebf-screen .sty-reverse {
  background: var(--krebf-accent);
  color: var(--krebf-screen-bg);
  text-shadow: none;
}
.krebf-root .krebf-screen .sty-bold   { font-weight: 700; color: var(--krebf-accent-bright); }
.krebf-root .krebf-screen .sty-italic { font-style: italic; }

.krebf-root .cursor {
  display: inline-block;
  width: 0.6em;
  height: 1em;
  background: var(--krebf-accent);
  vertical-align: text-bottom;
  animation: krebf-blink 1.1s steps(2) infinite;
}
@keyframes krebf-blink { 50% { opacity: 0; } }


/* ============ FOOTER CONTROLS ============================================ */
.krebf-root .krebf-controls {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: clamp(8px, 1.2cqw, 14px);
  padding: clamp(6px, 1cqw, 12px);
  background: linear-gradient(180deg, var(--krebf-bg-panel-2) 0%, var(--krebf-bg-panel) 100%);
  border: 1px solid var(--krebf-rule);
  border-radius: var(--krebf-radius-sm);
  min-width: 0;
}

.krebf-root .krebf-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.krebf-root .krebf-prompt-glyph {
  font-family: var(--krebf-screen-family);
  font-size: clamp(14px, 1.8cqw, 22px);
  color: var(--krebf-accent);
  text-shadow: var(--krebf-text-shadow);
  line-height: 1;
}
.krebf-root [data-el="input"] {
  flex: 1;
  min-width: 0;
  font-family: var(--krebf-screen-family) !important;
  font-size: clamp(13px, 1.7cqw, 18px);
  background: var(--krebf-screen-bg) !important;
  /* Match the screen's text colour exactly so the user sees their own
   * typing in the same hue as the game output. Marked !important to
   * defeat aggressive theme rules like `input { color: black; }`. */
  color: var(--krebf-accent) !important;
  -webkit-text-fill-color: var(--krebf-accent) !important;
  text-shadow: var(--krebf-text-shadow);
  border: 1px solid var(--krebf-rule);
  border-radius: var(--krebf-radius-sm);
  padding: clamp(4px, 0.8cqw, 8px) clamp(8px, 1.2cqw, 12px);
  letter-spacing: 0.03em;
  caret-color: var(--krebf-accent);
}
/* Safari resets text-fill-color when focused (it thinks the input may
 * receive autofill); we re-assert all three colour properties on :focus
 * with the same !important so the typing colour stays correct. */
.krebf-root [data-el="input"]:focus,
.krebf-root [data-el="input"]:focus-visible,
.krebf-root [data-el="input"]:active {
  color: var(--krebf-accent) !important;
  -webkit-text-fill-color: var(--krebf-accent) !important;
  background: var(--krebf-screen-bg) !important;
  caret-color: var(--krebf-accent) !important;
  border-color: var(--krebf-accent);
  box-shadow: 0 0 8px var(--krebf-accent-glow);
}
/* Safari/Chrome autofill highlights inputs in yellow with black text. We
 * override that for our command line so the user's command never appears
 * in the wrong colour. The animation-name trick is the established way to
 * defeat -webkit-autofill background and text-fill-color. */
.krebf-root [data-el="input"]:-webkit-autofill,
.krebf-root [data-el="input"]:-webkit-autofill:hover,
.krebf-root [data-el="input"]:-webkit-autofill:focus,
.krebf-root [data-el="input"]:-webkit-autofill:active {
  -webkit-text-fill-color: var(--krebf-accent) !important;
  caret-color: var(--krebf-accent) !important;
  -webkit-box-shadow: 0 0 0 1000px var(--krebf-screen-bg) inset !important;
  box-shadow: 0 0 0 1000px var(--krebf-screen-bg) inset !important;
  transition: background-color 99999s ease-in-out 0s;
}
.krebf-root [data-el="input"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.krebf-root [data-el="input"]::placeholder {
  color: var(--krebf-accent-dim);
  font-style: italic;
  -webkit-text-fill-color: var(--krebf-accent-dim);
  opacity: 1;
}


/* ============ OVERLAYS (save / restore / about / info) =================== */
.krebf-root .krebf-overlay {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--krebf-bg-deep) 85%, rgba(0,0,0,0.7));
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: clamp(14px, 2cqw, 30px);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.krebf-root .krebf-overlay.krebf-active {
  display: flex;
}

.krebf-root .krebf-dialog {
  background: linear-gradient(180deg, var(--krebf-bg-panel-2) 0%, var(--krebf-bg-panel) 100%);
  border: 1px solid var(--krebf-brass);
  border-radius: var(--krebf-radius);
  padding: clamp(18px, 2.5cqw, 32px);
  max-width: min(520px, 94%);
  width: 100%;
  max-height: 86%;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6), 0 0 0 1px var(--krebf-rule);
}

.krebf-root .krebf-dialog h2 {
  font-family: var(--krebf-brand-family);
  font-size: clamp(16px, 2.2cqw, 22px);
  letter-spacing: 0.08em;
  color: var(--krebf-accent);
  margin: 0 0 6px 0;
  text-shadow: var(--krebf-text-shadow);
}
.krebf-root .krebf-flourish {
  font-family: var(--krebf-ui-family);
  font-style: italic;
  color: var(--krebf-accent-dim);
  font-size: clamp(12px, 1.5cqw, 15px);
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--krebf-rule);
}
.krebf-root .krebf-dialog p {
  font-size: clamp(13px, 1.5cqw, 16px);
  line-height: 1.5;
  color: var(--krebf-text);
  margin: 0 0 12px 0;
}
.krebf-root .krebf-dialog input[type="text"] {
  width: 100%;
  padding: 8px 12px;
  font-family: var(--krebf-mono-family);
  font-size: 14px;
  background: var(--krebf-screen-bg);
  color: var(--krebf-accent-bright);
  border: 1px solid var(--krebf-rule);
  border-radius: var(--krebf-radius-sm);
  margin: 8px 0;
}
.krebf-root .krebf-dialog input[type="text"]:focus {
  border-color: var(--krebf-accent);
  box-shadow: 0 0 6px var(--krebf-accent-glow);
}
.krebf-root .krebf-dialog-buttons {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--krebf-rule);
}

.krebf-root .krebf-save-list {
  max-height: 260px;
  overflow-y: auto;
  margin: 10px 0;
}
.krebf-root .krebf-save-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: var(--krebf-bg-panel);
  border: 1px solid var(--krebf-rule);
  border-radius: var(--krebf-radius-sm);
  margin-bottom: 6px;
  cursor: pointer;
  transition: background var(--krebf-transition), border-color var(--krebf-transition);
}
.krebf-root .krebf-save-item:hover,
.krebf-root .krebf-save-item.krebf-active {
  background: color-mix(in srgb, var(--krebf-accent) 8%, var(--krebf-bg-panel));
  border-color: var(--krebf-accent-dim);
}
.krebf-root .krebf-save-item .krebf-name {
  font-family: var(--krebf-mono-family);
  font-size: 13px;
  color: var(--krebf-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.krebf-root .krebf-save-item .krebf-meta {
  font-size: 11px;
  color: var(--krebf-text-muted);
  margin-top: 2px;
}
.krebf-root .krebf-save-item .krebf-del {
  background: transparent;
  border: 1px solid var(--krebf-rule);
  color: var(--krebf-text-muted);
  border-radius: 3px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}
.krebf-root .krebf-save-item .krebf-del:hover {
  color: var(--krebf-led-red);
  border-color: var(--krebf-led-red);
}
.krebf-root .krebf-empty {
  color: var(--krebf-text-muted);
  font-style: italic;
  font-size: 14px;
  padding: 20px;
  text-align: center;
}

.krebf-root .krebf-credits {
  font-size: 12px;
  color: var(--krebf-text-muted);
  line-height: 1.6;
  border-top: 1px solid var(--krebf-rule);
  padding-top: 12px;
  margin-top: 12px;
}
.krebf-root .krebf-credits a {
  color: var(--krebf-accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--krebf-accent-dim);
}
.krebf-root .krebf-credits a:hover {
  color: var(--krebf-accent-bright);
  border-bottom-style: solid;
}


/* ============ DRAG-AND-DROP TARGET ====================================== */
.krebf-root.krebf-dragover {
  outline: 2px dashed var(--krebf-accent);
  outline-offset: -8px;
}
.krebf-root.krebf-dragover .krebf-screen-wrap::after {
  content: 'drop story file to load';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--krebf-mono-family);
  font-size: clamp(14px, 2cqw, 22px);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--krebf-accent);
  background: color-mix(in srgb, var(--krebf-bg-deep) 70%, transparent);
  text-shadow: var(--krebf-text-shadow);
  pointer-events: none;
  z-index: 50;
}


/* ============ NARROW LAYOUT (container-query-driven) ===================== */
@container krebf (max-width: 520px) {
  .krebf-root .krebf-titlebar {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .krebf-root .krebf-header-mid {
    justify-content: flex-start;
  }
  .krebf-root .krebf-controls {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .krebf-root .krebf-ctrl-group.krebf-right {
    justify-content: flex-start;
  }
  .krebf-root .krebf-sub {
    display: none;
  }
}

@container krebf (max-width: 380px) {
  .krebf-root .krebf-header-mid {
    display: none;
  }
  .krebf-root .krebf-dropdown {
    min-width: 0;
    flex: 1;
  }
}


/* ============ PRINT ====================================================== */
@media print {
  .krebf-root {
    background: white !important;
    color: black !important;
    box-shadow: none !important;
  }
  .krebf-root .krebf-overlay,
  .krebf-root .krebf-titlebar,
  .krebf-root .krebf-controls {
    display: none !important;
  }
}
