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

:root {
  --bg:     #0d0f1a;
  --surf:   #161929;
  --surf2:  #1e2235;
  --border: #2a2f4a;
  --accent: #7c6fff;
  --text:   #dde1f5;
  --muted:  #6370a0;
  --dot:    #252945;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* ── Toolbar ─────────────────────────────────────────── */

#toolbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: 54px;
  background: var(--surf);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 22px;
  gap: 12px;
  z-index: 3000;
  box-shadow: 0 2px 12px rgba(0,0,0,.4);
}

.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.4px;
  margin-right: auto;
}
.brand em { font-style: normal; color: var(--accent); }

.hint {
  font-size: 12px;
  color: var(--muted);
  border-right: 1px solid var(--border);
  padding-right: 14px;
}

.btn {
  height: 34px;
  padding: 0 15px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: opacity .15s, transform .1s;
}
.btn:hover  { opacity: .85; }
.btn:active { transform: scale(.96); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); opacity: 1; }

/* ── Workspace / Canvas ──────────────────────────────── */

#workspace {
  position: fixed;
  inset: 54px 0 0;
  overflow: auto;
}

#canvas {
  position: relative;
  min-width: 3200px;
  min-height: 2200px;
  padding: 52px 52px 200px;
  background-color: var(--bg);
  background-image: radial-gradient(circle, var(--dot) 1px, transparent 1px);
  background-size: 30px 30px;
}

/* ── Year table ──────────────────────────────────────── */

.year-table {
  position: absolute;
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  width: 560px;
  min-width: 340px;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  transition: box-shadow .15s;
  z-index: 10;
}
.year-table:hover { box-shadow: 0 0 0 1.5px var(--accent); }
.year-table.dragging-table,
.year-table.resizing-table {
  box-shadow: 0 16px 40px rgba(0,0,0,.55);
  opacity: .96;
  z-index: 500;
}

/* Resize handle (bottom-right corner) */
.table-resize {
  position: absolute;
  right: 4px;
  bottom: 4px;
  width: 18px;
  height: 18px;
  cursor: nwse-resize;
  opacity: 0;
  transition: opacity .15s;
  border-radius: 0 0 12px 0;
}
.table-resize::after {
  content: '';
  position: absolute;
  right: 3px;
  bottom: 3px;
  width: 9px;
  height: 9px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
}
.year-table:hover .table-resize { opacity: .8; }
.table-resize:hover::after { border-color: var(--accent); }

.table-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  cursor: move;
  padding: 2px 0 6px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.table-head-grip {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 2px 4px;
  opacity: .35;
  flex-shrink: 0;
}
.table-head-grip span {
  display: block;
  width: 16px;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}
.table-title {
  font-size: 15px;
  font-weight: 700;
  cursor: text;
  flex: 1;
}
.table-title:hover { color: var(--accent); }
.year-badge {
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 99px;
  letter-spacing: .6px;
}

.semesters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  flex: 1;
}

/* ── Semester column ─────────────────────────────────── */

.semester {
  background: var(--surf2);
  border: 1.5px solid var(--border);
  border-radius: 11px;
  padding: 13px;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  transition: border-color .15s, background .15s;
}
.semester.over {
  border-color: var(--accent);
  background: #1a1b35;
}

.sem-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .9px;
  margin-bottom: 11px;
}

.course-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}

.drop-line {
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
  margin: 1px 0;
  display: none;
}
.drop-line.active { display: block; }

/* ── Course card ─────────────────────────────────────── */

.course-card {
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 500;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 7px;
  cursor: grab;
  transition: opacity .15s;
}
.course-card:active { cursor: grabbing; }
.course-card.placeholder { opacity: .2; pointer-events: none; }

.card-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-del {
  opacity: 0;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.3);
  color: rgba(255,255,255,.9);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity .12s, background .12s;
  font-family: inherit;
}
.course-card:hover .card-del,
.bubble:hover      .card-del { opacity: 1; }
.card-del:hover { background: rgba(0,0,0,.5); }

/* ── Add course row ──────────────────────────────────── */

.add-row { margin-top: 8px; }

.add-btn {
  width: 100%;
  padding: 6px;
  background: none;
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, color .15s;
}
.add-btn:hover { border-color: var(--accent); color: #b8a9ff; }

.add-input {
  width: 100%;
  padding: 6px 9px;
  background: var(--surf);
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  color: var(--text);
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}

/* ── Floating bubble ─────────────────────────────────── */

.bubble {
  position: absolute;
  padding: 9px 13px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: grab;
  z-index: 200;
  box-shadow: 0 4px 18px rgba(0,0,0,.4);
  transition: box-shadow .15s;
  white-space: nowrap;
}
.bubble:hover    { box-shadow: 0 6px 26px rgba(0,0,0,.55); }
.bubble:active   { cursor: grabbing; }
.bubble.placeholder { opacity: .2; pointer-events: none; }
.bubble .card-del   { opacity: 0; }

/* ── Drag ghost ──────────────────────────────────────── */

#ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
}
#ghost > * {
  transform: rotate(3deg) scale(1.05);
  box-shadow: 0 12px 36px rgba(0,0,0,.55) !important;
  cursor: grabbing !important;
  opacity: 1 !important;
  pointer-events: none;
}

/* ── Rename input ────────────────────────────────────── */

.rename-input {
  background: transparent;
  border: none;
  border-bottom: 1.5px solid rgba(255,255,255,.7);
  color: #fff;
  font-size: inherit;
  font-weight: inherit;
  font-family: inherit;
  outline: none;
  width: 120px;
  padding: 0;
  -webkit-user-select: text;
  user-select: text;
}

/* ── Color-cycle button on courses ───────────────────── */

.card-recolor {
  opacity: 0;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.55);
  background: rgba(255,255,255,.15);
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity .12s, border-color .12s, transform .12s;
  padding: 0;
}
.course-card:hover .card-recolor,
.bubble:hover      .card-recolor { opacity: 1; }
.card-recolor:hover {
  border-color: #fff;
  transform: scale(1.2);
}

/* ── Palette picker ──────────────────────────────────── */

#palette-wrap { position: relative; }

#palette-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
}

.pal-dots {
  display: flex;
  gap: 3px;
}
.pal-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

#palette-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px;
  z-index: 4000;
  min-width: 230px;
  box-shadow: 0 10px 32px rgba(0,0,0,.55);
  display: none;
}
#palette-menu.open { display: block; }

.pal-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .12s;
}
.pal-option:hover  { background: var(--surf2); }
.pal-option.active { background: var(--surf2); outline: 1.5px solid var(--accent); }

.pal-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  min-width: 62px;
}

.pal-swatches {
  display: flex;
  gap: 3px;
  flex-wrap: wrap;
  max-width: 110px;
}
.pal-swatch {
  width: 13px;
  height: 13px;
  border-radius: 50%;
}

.pal-divider {
  height: 1px;
  background: var(--border);
  margin: 7px 4px;
}
.pal-section-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--muted);
  padding: 2px 10px 6px;
}
.pal-action-btn {
  width: calc(100% - 8px);
  margin: 0 4px;
  padding: 8px 10px;
  background: var(--surf2);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background .12s, border-color .12s;
}
.pal-action-btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

.bg-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 2px 10px 6px;
  align-items: center;
}
.bg-swatch {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform .12s, border-color .12s;
}
.bg-swatch:hover  { transform: scale(1.12); }
.bg-swatch.active { border-color: var(--accent); }
.bg-custom {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1.5px dashed var(--muted);
  border-radius: 7px;
  background: none;
  cursor: pointer;
}
.bg-custom::-webkit-color-swatch-wrapper { padding: 2px; }
.bg-custom::-webkit-color-swatch { border: none; border-radius: 4px; }

/* ── Search panel ────────────────────────────────────────── */

#search-panel {
  position: fixed;
  top: 54px;
  right: -295px;
  width: 280px;
  height: calc(100vh - 54px);
  background: var(--surf);
  border-left: 1px solid var(--border);
  z-index: 2500;
  display: flex;
  flex-direction: column;
  transition: right .22s cubic-bezier(.4,0,.2,1);
  box-shadow: -4px 0 24px rgba(0,0,0,.35);
}
#search-panel.open { right: 0; }

.sp-head {
  display: flex;
  align-items: center;
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-shrink: 0;
}
.sp-title { font-size: 14px; font-weight: 600; flex: 1; }

.sp-input-wrap {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#search-q {
  width: 100%;
  background: var(--surf2);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
  transition: border-color .15s;
}
#search-q:focus { border-color: var(--accent); }
#search-q::placeholder { color: var(--muted); }

.sp-results {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}
.sp-hint {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  padding: 24px 12px;
  line-height: 1.5;
}
.sp-item {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: grab;
  transition: background .12s;
  user-select: none;
}
.sp-item:hover   { background: var(--surf2); }
.sp-item:active  { cursor: grabbing; }
.sp-item-code   { font-size: 11.5px; font-weight: 700; color: var(--accent); }
.sp-item-name   { font-size: 12px; color: var(--text); margin-top: 1px; line-height: 1.35; }
.sp-count       { font-size: 11px; color: var(--muted); padding: 4px 10px 2px; }

/* ── Import / Export modal ───────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(3px);
}
.modal-backdrop.hidden { display: none; }

.modal-box {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 540px;
  max-width: 95vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,.7);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  gap: 10px;
}
.modal-head h2 {
  font-size: 16px;
  font-weight: 700;
  flex: 1;
}
.modal-close {
  width: 28px; height: 28px;
  border-radius: 8px;
  border: none;
  background: var(--surf2);
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.modal-close:hover { background: var(--border); color: var(--text); }

.modal-body {
  padding: 20px 22px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  margin-bottom: 6px;
}

.modal-file-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 22px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  position: relative;
}
.modal-file-zone:hover,
.modal-file-zone.drag-over {
  border-color: var(--accent);
  background: rgba(124,111,255,.06);
}
.modal-file-zone input[type=file] {
  position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.modal-file-zone-icon { font-size: 26px; margin-bottom: 6px; }
.modal-file-zone p { font-size: 13px; color: var(--muted); }
.modal-file-zone p strong { color: var(--accent); }
.modal-file-name {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text);
  font-weight: 500;
}

.modal-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}
.modal-divider::before,
.modal-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.modal-textarea {
  width: 100%;
  height: 140px;
  background: var(--surf2);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  font-family: 'Consolas', 'Courier New', monospace;
  padding: 10px 12px;
  resize: vertical;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
  transition: border-color .15s;
}
.modal-textarea:focus { border-color: var(--accent); }
.modal-textarea::placeholder { color: var(--muted); }

.format-hint {
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.6;
  background: var(--surf2);
  border-radius: 8px;
  padding: 10px 12px;
}
.format-hint code {
  background: rgba(124,111,255,.15);
  color: #b8a9ff;
  padding: 1px 4px;
  border-radius: 4px;
  font-family: 'Consolas', monospace;
  font-size: 11px;
}

.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.radio-group {
  display: flex;
  gap: 12px;
  margin-right: auto;
}
.radio-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.radio-label input { accent-color: var(--accent); cursor: pointer; }

.modal-status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  display: none;
}
.modal-status.ok    { display: block; background: rgba(16,185,129,.15); color: #6ee7b7; }
.modal-status.error { display: block; background: rgba(239,68,68,.15);  color: #fca5a5; }
