:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #090d16;
  --surface: #131d31;
  --panel: #1e293b;
  --card: #27354f;
  --text: #f8fafc;
  --text-muted: #94a3b8;
  --correct: #22c55e;
  --correct-bg: rgba(34, 197, 94, 0.25);
  --wrong: #ef4444;
  --wrong-bg: rgba(239, 68, 68, 0.25);
  --accent: #38bdf8;
}



* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ========================================== */
/* MODERN GLOBAL SCROLLBAR STYLING            */
/* ========================================== */

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: #334155 #090d16;
}

/* Chrome, Edge, Safari (WebKit) */
*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: var(--bg);
}

*::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
  border: 2px solid var(--bg);
}

*::-webkit-scrollbar-thumb:hover {
  background: #475569;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding: 16px;
  display: flex;
  justify-content: center;
}

.container {
  width: 100%;
  max-width: 1450px;
  /* Expanded from 1150px */
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* Navigation Bar */
.nav-bar {
  background: var(--surface);
  border: 1px solid #334155;
  padding: 12px 18px;
  border-radius: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 300px;
}

.nav-left label {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--accent);
  white-space: nowrap;
}

select#diagramSelect {
  width: 100%;
  background: var(--panel);
  color: var(--text);
  border: 1.5px solid #475569;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  outline: none;
}

select#diagramSelect:focus {
  border-color: var(--accent);
}

.nav-buttons {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid #475569;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  transition: all 0.15s;
}

.btn:hover {
  background: #334155;
  border-color: var(--accent);
}

.btn-check {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.btn-check:hover {
  background: var(--primary-dark);
}

.btn-shuffle {
  background: #6366f1;
  border-color: #6366f1;
  color: #fff;
}

.btn-shuffle:hover {
  background: #4f46e5;
}

/* Status & Controls */
.status-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid #334155;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  gap: 12px;
}

.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-weight: 700;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent);
}

/* Workspace */
.workspace {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 16px;
}

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
  }
}

/* Labels Bank */
.bank-card {
  background: var(--surface);
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: fit-content;

  /* ADD THESE TWO LINES */
  position: sticky;
  top: 16px;
}

.bank-card h3 {
  font-size: 0.95rem;
  color: var(--accent);
  white-space: pre-line;
}

.bank-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.35;
}

.bank-items {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 6px;
  max-height: 520px;
  overflow-y: auto;
  padding-right: 4px;
}

.chip {
  background: var(--card);
  border: 1.5px solid #475569;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s;
  text-align: center;
  white-space: pre-line;
  /* Renders \n as a newline */
}

.chip:hover {
  border-color: var(--accent);
  background: #2e3e5c;
}


.chip.selected {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.25);
  box-shadow: 0 0 0 2px var(--accent);
}

/* Diagram Canvas */
.diagram-panel {
  background: var(--surface);
  border: 1px solid #334155;
  border-radius: 10px;
  position: relative;
  min-height: 600px;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
  overflow: hidden;
}

.diagram-stage {
  position: relative;
  width: 100%;
  margin: 0 auto;
}

svg.diag-svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Drop Boxes */
.drop-slot {
  position: absolute;
  width: 138px;
  min-height: 38px;
  background: rgba(15, 23, 42, 0.92);
  border: 2px dashed #64748b;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  color: var(--text-muted);
  backdrop-filter: blur(5px);
  cursor: pointer;
  transform: translate(-50%, -50%);
  transition: all 0.15s;
  z-index: 10;
  white-space: pre-line;
  /* Renders \n as a newline */
}

.drop-slot.drag-hover {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.25);
}

.drop-slot.filled {
  border: 1.5px solid var(--accent);
  color: var(--text);
  background: #1e293b;
}

.drop-slot.correct {
  border: 2px solid var(--correct) !important;
  background: var(--correct-bg) !important;
  color: var(--correct) !important;
}

.drop-slot.wrong {
  border: 2px solid var(--wrong) !important;
  background: var(--wrong-bg) !important;
  color: #fca5a5 !important;
}

.btn-toggle {
  background: #8b5cf6;
  border-color: #8b5cf6;
  color: #fff;
}

.btn-toggle:hover {
  background: #7c3aed;
}

.drop-input {
  background: rgba(15, 23, 42, 0.95);
  border: 2px solid #64748b;
  color: #f8fafc;
  font-family: inherit;
  outline: none;

  /* Support for Native Textarea Wrapping */
  display: block !important;
  resize: none;
  overflow: hidden;
  white-space: pre-wrap !important;
  word-wrap: break-word !important;
  line-height: 1.25;
  padding-top: 8px !important;
  padding-bottom: 8px !important;
}

.drop-input::-webkit-scrollbar {
  display: none;
  /* Hide scrollbars as it auto-expands */
}

.drop-input:focus {
  border-color: var(--accent);
  background: rgba(56, 189, 248, 0.15);
}

.drop-input::placeholder {
  color: #64748b;
  font-weight: normal;
}

/* Diagram Canvas */
.diagram-panel {
  background: var(--surface);
  border: 1px solid #334155;
  border-radius: 10px;
  position: relative;
  min-height: 600px;
  display: flex;
  flex-direction: column;
  /* THIS NATIVELY STACKS THE TOP BAR OVER THE STAGE */
  justify-content: flex-start;
  align-items: center;
  padding: 16px;
  overflow-y: auto;
  overflow-x: hidden;
}

/* NEW CONTAINER FOR PROPER HTML FLOW */
.panel-top-bar {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  margin-bottom: 12px;
  z-index: 10;
}



/* image definition */
.slot-badge {
  position: absolute;
  top: -9px;
  left: 6px;
  background: #0f172a;
  color: var(--accent);
  border: 1px solid #475569;
  border-radius: 4px;
  padding: 0 5px;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  pointer-events: none;
  z-index: 12;
}

/* Study Mode & Slide Study-Toggle Button */
.btn-study-mode {
  background: #0d9488;
  border-color: #0f766e;
  color: #fff;
}

.btn-study-mode:hover {
  background: #0f766e;
}

.btn-study-mode.active {
  background: #f59e0b;
  border-color: #d97706;
  color: #090d16;
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.4);
}

.slide-study-toggle {
  background: rgba(19, 29, 49, 0.92);
  color: var(--text-muted);
  border: 1.5px solid #475569;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: all 0.15s;
}

.slide-study-toggle:hover {
  border-color: #facc15;
  color: #f8fafc;
}

.slide-study-toggle.in-list {
  background: rgba(250, 204, 21, 0.18);
  border-color: #facc15;
  color: #facc15;
}

.drop-slot.study-filled {
  border: 2px solid var(--correct) !important;
  background: rgba(15, 23, 42, 0.96) !important;
  color: #4ade80 !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  cursor: default;
  line-height: 1.25;
  padding: 6px 8px;
}

/* ========================================== */
/* MOBILE RESPONSIVE LAYOUT QUERIES           */
/* ========================================== */

@media (max-width: 860px) {
  .workspace {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .status-bar {
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
  }

  .status-bar>div:last-child {
    display: flex;
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px;
  }

  /* Float the bank card at the top of the screen on mobile */
  .bank-card {
    position: sticky !important;
    top: 0 !important;
    z-index: 100;
    /* Forces it above the diagram */
    padding: 10px 12px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.75);
    /* Shadow to separate it from the diagram underneath */
    margin: -8px -8px 0 -8px;
    /* Stretches edge-to-edge on mobile */
    border-radius: 0 0 12px 12px;
    max-height: 200px;
    /* Prevents it from taking up the whole screen */
  }

  .bank-items {
    flex-direction: row;
    flex-wrap: wrap;
    max-height: 130px;
    /* Inner scroll for the chips */
    overflow-y: auto;
  }

  .chip {
    flex: 1 1 auto;
    font-size: 0.8rem;
    padding: 6px 10px;
  }

  /* Stack the navigation buttons neatly */
  .nav-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .nav-left {
    width: 100%;
  }

  .nav-buttons {
    justify-content: center;
    width: 100%;
  }

  .btn {
    flex: 1 1 calc(50% - 8px);
    text-align: center;
  }
}

@media (max-width: 600px) {
  body {
    padding: 4px;
  }



  /* Allow labels to reach the physical left/right screen edges and top/bottom space */
  .diagram-panel {
    padding: 12px 2px;
    overflow: visible;
  }

  .diagram-stage {
    margin: 34px auto 44px auto;
  }

  /* Fit label boxes tightly to their text so short words don't waste horizontal space */
  .drop-slot {
    width: max-content;
    min-width: 64px;
    max-width: 96px;
    min-height: 26px;
    font-size: 0.64rem;
    line-height: 1.15;
    padding: 3px 6px;
  }

  /* Type-in boxes keep a consistent typing width */
  .drop-slot.drop-input {
    width: 90px;
  }

  .drop-slot:focus,
  .drop-slot:hover {
    z-index: 30;
  }

  /* Full-width centered label boxes beneath definitions in Mobile Portrait mode */
  #diagramStage.term-portrait-stage .drop-slot {
    width: 84% !important;
    max-width: 290px !important;
    min-height: 38px !important;
    font-size: 0.82rem !important;
    padding: 6px 10px !important;
  }

    /* Default Mobile Stage */
    .drop-slot.drop-input {
      font-size: 16px !important;
      
      /* Original font size was 0.64rem (10.24px). 10.24 / 16 = 0.64 scale */
      transform: translate(-50%, -50%) scale(0.64) !important;

      /* Multiply original dimensions by 1.5625 (the exact mathematical inverse of 0.64) */
      width: 140.625px !important;       /* originally 90px */
      min-height: 40.625px !important;   /* originally 26px */
      border-width: 3.125px !important;  /* originally 2px */
      border-radius: 9.375px !important; /* originally 6px */
      padding: 12.5px 9.375px !important; /* originally 8px top/bot, 6px left/right */
    }

    /* Portrait Stage (Full-Width Labels) */
    #diagramStage.term-portrait-stage .drop-slot.drop-input {
      font-size: 16px !important;
      
      /* Original font size was 0.82rem (13.12px). 13.12 / 16 = 0.82 scale */
      transform: translate(-50%, -50%) scale(0.82) !important;

      /* Multiply original dimensions by 1.2195 (the exact mathematical inverse of 0.82) */
      width: 102.44% !important;         /* originally 84% */
      max-width: 353.65px !important;    /* originally 290px */
      min-height: 46.34px !important;    /* originally 38px */
      border-width: 2.44px !important;   /* originally 2px */
      border-radius: 7.32px !important;  /* originally 6px */
      padding: 9.75px 12.2px !important; /* originally 8px top/bot, 10px left/right */
    }  

  .slot-badge {
    font-size: 0.55rem;
    top: -12px;
    left: 0;
  }

  .btn {
    font-size: 0.75rem;
    padding: 6px 10px;
  }

  .status-bar {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }

  /* Study mode popout modal adjustments */
  #studyListModal>div,
  #sequenceModal>div {
    width: 95% !important;
    padding: 16px !important;
  }
}

/* ========================================== */
/* SEQUENTIAL CONTROLS                        */
/* ========================================== */
.seq-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 600px) {
  .seq-controls {
    top: 48px;
    right: 8px;
  }
}