@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&family=VT323&display=swap');

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

:root {
  --bg-page-a:       #f6d9c4;
  --bg-page-b:       #f1c8e0;
  --bg-page-c:       #cdb6ef;
  --bg-window:       #f7ecd6;
  --bg-input:        #fffaf0;
  --bg-hover:        #ffb3a7;
  --bg-active:       #bdeae2;
  --bg-console:      #1c2618;
  --console-text:    #79e07a;
  --accent:          #4fa39b;
  --accent2:         #e8736b;
  --text-primary:    #3d2b1f;
  --text-secondary:  #7a5a3f;
  --text-muted:      #a3886a;
  --border:          #3d2b1f;
  --shadow-sm:       3px 3px 0 rgba(61,43,31,.85);
  --shadow-md:       5px 5px 0 rgba(61,43,31,.85);
  --radius-sm:       4px;
  --radius-md:       6px;
  --font-main:       'VT323', ui-monospace, monospace;
  --font-pixel:      'Press Start 2P', monospace;
  --transition:      all .12s ease;
}

html, body {
  min-height: 100%;
  background: #e7cdf0;
  background-image:
    linear-gradient(135deg, var(--bg-page-a) 0%, var(--bg-page-b) 45%, var(--bg-page-c) 100%),
    repeating-linear-gradient(0deg, rgba(61,43,31,.05) 0 1px, transparent 1px 26px),
    repeating-linear-gradient(90deg, rgba(61,43,31,.05) 0 1px, transparent 1px 26px);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 19px;
  line-height: 1.5;
}

.kb-page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Generic retro window chrome ── */
.kb-window {
  background: var(--bg-window);
  border: 3px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  animation: winOpen .3s cubic-bezier(.34,1.56,.64,1) both;
}
@keyframes winOpen {
  from { opacity: 0; transform: translateY(14px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.win-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: linear-gradient(to right, #f6a8ad, #e8736b);
  border-bottom: 3px solid var(--border);
}
.win-titlebar.teal { background: linear-gradient(to right, #a9e6dd, #4fa39b); }
.win-title {
  font-family: var(--font-pixel);
  font-size: 11px;
  color: #fff8ea;
  text-shadow: 1px 1px 0 rgba(61,43,31,.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.win-controls { display: flex; gap: 5px; flex-shrink: 0; }
.win-btn {
  width: 18px;
  height: 18px;
  background: #fff8ea;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: var(--text-primary);
  box-shadow: 1.5px 1.5px 0 rgba(61,43,31,.6);
  cursor: pointer;
  transition: var(--transition);
}
.win-btn:hover { background: var(--bg-hover); transform: translate(1px,1px); }
.win-btn.win-close { background: #ffb3a7; }

.kb-window-body { padding: 18px 20px; }

/* ── Header window ── */
.kb-header-body {
  padding: 22px 24px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  position: relative;
}
.btn-back {
  position: absolute;
  left: 20px;
  top: 18px;
  font-family: var(--font-main);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
  background: #fff8ea;
  border: 2.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.btn-back:hover { background: var(--bg-hover); transform: translate(1px,1px); box-shadow: 2px 2px 0 rgba(61,43,31,.7); }
.kb-header-body h1 {
  font-family: var(--font-pixel);
  font-size: clamp(14px, 2.6vw, 19px);
  margin-top: 18px;
  text-shadow: 2px 2px 0 #fff8ea;
}
.kb-header-body p { color: var(--text-secondary); font-size: 17px; }
.kb-stat-pill {
  margin-top: 4px;
  font-family: var(--font-pixel);
  font-size: 10px;
  background: var(--bg-active);
  border: 2px solid var(--border);
  border-radius: 20px;
  padding: 7px 16px;
  color: var(--text-primary);
}

/* ── How it works grid ── */
.how-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.how-card {
  background: var(--bg-input);
  border: 2.5px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 14px 14px 16px;
  position: relative;
  transition: var(--transition);
}
.how-card:hover { transform: translate(-1px,-2px); box-shadow: 6px 7px 0 rgba(61,43,31,.7); }
.how-step {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: #fff8ea;
  background: var(--accent2);
  border: 2px solid var(--border);
  display: inline-block;
  padding: 3px 8px;
  border-radius: 3px;
  margin-bottom: 8px;
}
.how-icon { font-size: 28px; margin-bottom: 4px; }
.how-title { font-weight: 700; font-size: 18px; margin-bottom: 4px; }
.how-card p { color: var(--text-secondary); font-size: 15px; line-height: 1.4; }

/* ── Two-column layout (left stack + typewriter) ── */
.kb-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
}
.kb-col-left {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.kb-col-right {
  display: flex;
  flex-direction: column;
}
.kb-col-right .kb-window { flex: 1; }

/* ── Dropzone ── */
.dropzone {
  border: 3px dashed var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  padding: 36px 18px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
}
.dropzone:hover, .dropzone.dragover {
  background: var(--bg-active);
  border-color: var(--accent);
}
.dropzone-icon { font-size: 40px; margin-bottom: 6px; }
.dropzone-text { font-size: 19px; font-weight: 700; }
.dropzone-sub { font-size: 14px; color: var(--text-muted); margin-top: 2px; }

.file-list {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.file-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 14px;
  box-shadow: 2px 2px 0 rgba(61,43,31,.5);
}
.file-row .file-icon { font-size: 18px; flex-shrink: 0; }
.file-row .file-meta { flex: 1; overflow: hidden; }
.file-row .file-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-row .file-size { color: var(--text-muted); font-size: 12px; }
.file-row .file-status {
  font-family: var(--font-pixel);
  font-size: 8px;
  padding: 4px 8px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  flex-shrink: 0;
  white-space: nowrap;
}
.file-status.pending   { background: #ffe9b3; }
.file-status.uploading { background: #bdeae2; animation: pulseStatus 1s infinite; }
.file-status.done      { background: #c8f0bf; }
.file-status.error     { background: #ffb3a7; }
@keyframes pulseStatus { 0%,100%{opacity:1;} 50%{opacity:.5;} }

/* ── Typewriter ── */
.typewriter-shell {
  background: #2b3a2c;
  border: 3px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.typewriter-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #1c2618;
  color: #9fdf94;
  font-family: var(--font-pixel);
  font-size: 8.5px;
  padding: 7px 10px;
  letter-spacing: .03em;
}
.typewriter-led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #79e07a;
  box-shadow: 0 0 6px #79e07a;
  animation: ledBlink 1.6s infinite;
}
@keyframes ledBlink { 0%,100%{opacity:1;} 50%{opacity:.3;} }

.typewriter-screen { position: relative; }
.typewriter-textarea {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  background: #18230f;
  color: #9fdf94;
  border: none;
  outline: none;
  font-family: var(--font-main);
  font-size: 19px;
  line-height: 1.55;
  padding: 16px 18px;
  caret-color: #9fdf94;
  text-shadow: 0 0 4px rgba(159,223,148,.5);
}
.typewriter-textarea::placeholder { color: #5c8a55; }

.typewriter-cursor {
  position: absolute;
  left: 18px;
  top: 16px;
  width: 10px;
  height: 22px;
  background: #9fdf94;
  box-shadow: 0 0 6px #9fdf94;
  animation: blinkCursor 1s steps(1) infinite;
  pointer-events: none;
}
.typewriter-textarea:focus ~ .typewriter-cursor,
.typewriter-textarea:not(:placeholder-shown) ~ .typewriter-cursor { display: none; }
@keyframes blinkCursor { 0%,50%{opacity:1;} 51%,100%{opacity:0;} }

.kb-window.kb-window-max { box-shadow: 9px 9px 0 rgba(61,43,31,.85); }

/* ── Retro receipt printer ── */
.printer-unit {
    position: relative;
    width: 260px;
    margin: 30px auto;
    min-height: 320px;
}
.printer-body {
  width: 260px;
  height: 70px;
  background: linear-gradient(to bottom, #e8d2a0, #d9bd84);
  border: 3px solid var(--border);
  border-radius: 0 0 10px 10px;
  position: relative;
  z-index: 5;
}
.printer-screen {
  position: absolute;
  top: -16px;
  left: 18px;
  width: 140px;
  height: 28px;
  background: #10170d;
  border: 2.5px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-family: var(--font-main);
  font-size: 14px;
  color: #79e07a;
  overflow: hidden;
  white-space: nowrap;
}
.printer-slot {
  position: absolute;
  left: 20px;
  right: 20px;
  top: 18px;
  height: 10px;
  background: rgba(0,0,0,.25);
  border-radius: 2px;
}

.receipt-paper {
  position: absolute;
  left: 50%;
  top: 24px;
  transform: translateX(-50%) translateY(-100%);
  width: 220px;
  background: #fffaf0;
  border: 2px solid var(--border);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  z-index: 1;
  clip-path: inset(100% 0 0 0);
  opacity: 0;
  pointer-events: none;
}

/* ── Single active-state rule — no duplicate ── */
.printer-unit.is-printing .receipt-paper {
  animation: printReceipt 1.2s ease forwards;
  pointer-events: auto;
}

@keyframes printReceipt {
  0% {
    opacity: 1;
    transform: translateX(-50%) translateY(-100%);
    clip-path: inset(100% 0 0 0);
  }
  100% {
    opacity: 1;
    transform: translateX(-50%) translateY(30px);
    clip-path: inset(0 0 0 0);
  }
}

.receipt-paper::before,
.receipt-paper::after {
  content: "";
  display: block;
  position: absolute;
  left: 0;
  width: 100%;
  height: 8px;
  background:
    linear-gradient(-45deg, #fffaf0 4px, transparent 0),
    linear-gradient(45deg,  #fffaf0 4px, transparent 0);
  background-position: 4px 0;
  background-repeat: repeat-x;
  background-size: 8px 8px;
}
.receipt-paper::before { top: -8px; }
.receipt-paper::after  { bottom: -8px; }

.receipt-header, .receipt-subheader, .receipt-message {
  padding: 3px 0;
}
.receipt-header {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-pixel);
  font-size: 11px;
  border-bottom: 1px dashed var(--text-muted);
  padding-bottom: 8px;
  margin-bottom: 6px;
}
.receipt-subheader {
  font-size: 13px;
  color: var(--text-secondary);
  border-bottom: 1px dashed var(--text-muted);
  margin-bottom: 4px;
  padding-bottom: 6px;
}
.receipt-table {
  width: 100%;
  font: inherit;
  color: inherit;
  border-collapse: collapse;
}
.receipt-table td {
  padding: 2px 0;
  font-size: 14px;
  vertical-align: top;
}
.receipt-table td:first-child { color: var(--text-secondary); }
.receipt-table td:last-child { text-align: right; font-weight: 700; white-space: nowrap; }
.receipt-table tr.receipt-total td {
  border-top: 1px dashed var(--text-muted);
  padding-top: 6px;
  font-weight: 700;
}
.receipt-message {
  text-align: center;
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ── Retro buttons ── */
.typewriter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}
.btn-retro {
  font-family: var(--font-main);
  font-weight: 700;
  font-size: 15px;
  padding: 10px 16px;
  border: 2.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
  background: var(--bg-input);
  color: var(--text-primary);
}
.btn-retro:hover  { transform: translate(1px,1px); box-shadow: 2px 2px 0 rgba(61,43,31,.7); }
.btn-retro:active { transform: translate(3px,3px); box-shadow: none; }
.btn-save     { background: var(--bg-active); }
.btn-download { background: #ffe9b3; }
.btn-clear    { background: var(--bg-hover); }

/* ── Status console ── */
.console-body {
  background: var(--bg-console);
  color: var(--console-text);
  font-family: var(--font-main);
  font-size: 15px;
  padding: 14px 16px;
  height: 170px;
  overflow-y: auto;
  line-height: 1.5;
}
.console-body::-webkit-scrollbar { width: 10px; }
.console-body::-webkit-scrollbar-thumb { background: var(--console-text); }
.console-line { white-space: pre-wrap; word-break: break-word; }
.console-line.console-success { color: #c8f0bf; }
.console-line.console-error   { color: #ff9c8d; }
.console-line.console-info::before { content: ""; }

/* ── Responsive ── */
@media (max-width: 860px) {
  .kb-columns { grid-template-columns: 1fr; }
  .kb-col-left, .kb-col-right { width: 100%; }
  .how-grid   { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .how-grid { grid-template-columns: 1fr; }
  .btn-back { position: static; align-self: flex-start; margin-bottom: 6px; }
  .kb-header-body h1 { margin-top: 0; }
}
/* ══════════════════════════════════════════════
   KB HEALTH DASHBOARD
══════════════════════════════════════════════ */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}
.dash-card {
  background: var(--bg-input);
  border: 2.5px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: var(--transition);
}
.dash-card:hover { transform: translate(-1px,-2px); box-shadow: 6px 7px 0 rgba(61,43,31,.7); }
.dash-card--wide { grid-column: span 1; }
.dash-label {
  font-family: var(--font-pixel);
  font-size: 7.5px;
  color: var(--text-muted);
  letter-spacing: .05em;
}
.dash-value {
  font-family: var(--font-pixel);
  font-size: 28px;
  color: var(--accent2);
  line-height: 1.1;
  text-shadow: 2px 2px 0 rgba(61,43,31,.15);
  transition: all .4s ease;
}
.dash-value--sm { font-size: 15px; color: var(--text-primary); }
.dash-sub {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}
.dash-bar-track {
  height: 10px;
  background: rgba(61,43,31,.1);
  border: 1.5px solid var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin: 4px 0 2px;
}
.dash-bar {
  height: 100%;
  background: var(--accent2);
  border-radius: 1px;
  transition: width .8s cubic-bezier(.34,1.56,.64,1);
}
.dash-bar--teal   { background: var(--accent); }
.dash-bar--yellow { background: #d4a017; }
.dash-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.dash-led {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #79e07a;
  box-shadow: 0 0 6px #79e07a;
  flex-shrink: 0;
}
.dash-led.dash-led--red   { background: #ff9c8d; box-shadow: 0 0 6px #ff9c8d; }
.dash-led.dash-led--amber { background: #ffe080; box-shadow: 0 0 6px #ffe080; animation: ledBlink 1.6s infinite; }
.dash-status-text { font-size: 14px; color: var(--text-secondary); }

@media (max-width: 860px) { .dash-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .dash-grid { grid-template-columns: 1fr; } }


/* ══════════════════════════════════════════════
   MP3 PLAYER
══════════════════════════════════════════════ */
.player-shell {
  background: #1a1a2e;
  border: 2.5px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

/* Visualizer */
.player-viz {
  background: #0d0d1a;
  padding: 4px 6px 2px;
  line-height: 0;
}
#vizCanvas { width: 100%; height: 48px; display: block; }

/* Track display */
.player-display {
  background: #0f1923;
  border-top: 2px solid #333;
  border-bottom: 2px solid #333;
  padding: 8px 12px 6px;
}
.player-display-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}
.player-time, .player-duration {
  font-family: var(--font-pixel);
  font-size: 10px;
  color: #79e07a;
  flex-shrink: 0;
  min-width: 38px;
}
.player-duration { text-align: right; }
.player-marquee-wrap {
  flex: 1;
  overflow: hidden;
  background: #0a1015;
  border: 1.5px solid #333;
  border-radius: 2px;
  padding: 4px 6px;
}
.player-marquee {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: #79e07a;
  white-space: nowrap;
  display: inline-block;
  text-shadow: 0 0 6px rgba(121,224,122,.5);
}
.player-marquee.scrolling {
  animation: marqueeScroll linear infinite;
}
@keyframes marqueeScroll {
  0%   { transform: translateX(100%); }
  100% { transform: translateX(-100%); }
}

/* Progress bar */
.player-progress-wrap {
  height: 10px;
  background: #0a1015;
  border: 1.5px solid #333;
  border-radius: 2px;
  cursor: pointer;
  overflow: hidden;
}
.player-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(to right, #4fa39b, #79e07a);
  border-radius: 1px;
  transition: width .1s linear;
  pointer-events: none;
}

/* Controls */
.player-controls {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 12px;
  background: #16213e;
  flex-wrap: wrap;
}
.player-btns { display: flex; gap: 6px; }
.player-btn {
  width: 36px;
  height: 36px;
  background: #0f3460;
  border: 2px solid #4fa39b;
  border-radius: 3px;
  color: #79e07a;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 2px 2px 0 rgba(0,0,0,.5);
  transition: var(--transition);
}
.player-btn:hover { background: #1a4a7a; transform: translate(1px,1px); box-shadow: 1px 1px 0 rgba(0,0,0,.5); }
.player-btn:active { transform: translate(2px,2px); box-shadow: none; }
.player-btn--play {
  width: 44px;
  height: 44px;
  font-size: 18px;
  background: #4fa39b;
  border-color: #79e07a;
  color: #0d0d1a;
}
.player-btn--play:hover { background: #5fc0b5; }

.player-vol-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.player-vol-label {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: #4fa39b;
  flex-shrink: 0;
}
.player-vol-slider {
  flex: 1;
  -webkit-appearance: none;
  height: 6px;
  background: #0a1015;
  border: 1.5px solid #333;
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.player-vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: #4fa39b;
  border: 2px solid #79e07a;
  border-radius: 2px;
  cursor: pointer;
}

.player-load-btn {
  font-size: 13px;
  padding: 8px 14px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Playlist */
.player-playlist {
  background: #0d0d1a;
  border-top: 2px solid #333;
  max-height: 140px;
  overflow-y: auto;
  padding: 6px 0;
}
.player-playlist::-webkit-scrollbar { width: 8px; }
.player-playlist::-webkit-scrollbar-thumb { background: #4fa39b; }
.player-playlist-empty {
  font-family: var(--font-pixel);
  font-size: 9px;
  color: #2a4a3a;
  text-align: center;
  padding: 16px;
}
.player-track-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  cursor: pointer;
  transition: background .1s;
  font-size: 14px;
  color: #5a9a8a;
}
.player-track-row:hover { background: #0f1f2f; color: #79e07a; }
.player-track-row.active {
  background: #0f3460;
  color: #79e07a;
  font-weight: 700;
}
.player-track-num {
  font-family: var(--font-pixel);
  font-size: 8px;
  color: #2a4a3a;
  min-width: 20px;
}
.player-track-row.active .player-track-num { color: #4fa39b; }
.player-track-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
