:root {
  --ink: #1f2421;
  --ink-soft: #5b635d;
  --line: #d9dcd6;
  --line-soft: #ebede9;
  --paper: #ffffff;
  --canvas-bg: #f3f4f1;
  --weekend: #fdf2c4;
  --term: #fbe9a7;
  --accent: #c0492f;
  --month-head: #f7f7f5;
  --shadow: 0 1px 3px rgba(31,36,33,.08), 0 8px 30px rgba(31,36,33,.06);
  --mono: "SF Mono", ui-monospace, "Cascadia Mono", "Roboto Mono", Menlo, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; font-family: var(--sans); color: var(--ink); }
body { background: var(--canvas-bg); }

.bar {
  position: fixed; top: 0; left: 0; right: 0; height: 56px; z-index: 20;
  display: flex; align-items: center; gap: 18px; padding: 0 18px;
  background: rgba(255,255,255,.82); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 650; letter-spacing: -.01em; font-size: 15px; }
.brand b { color: var(--accent); }
.group { display: flex; align-items: center; gap: 8px; }
.bar label { font-size: 12px; color: var(--ink-soft); font-weight: 550; }
.yr { font-family: var(--mono); font-size: 15px; font-weight: 600; background: var(--paper);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; width: 82px; text-align: center; }
.step { display: flex; }
.step button, .ctl button {
  font-family: var(--sans); font-size: 13px; font-weight: 550; color: var(--ink);
  background: var(--paper); border: 1px solid var(--line); cursor: pointer;
  height: 32px; min-width: 32px; padding: 0 10px; transition: background .12s, border-color .12s;
}
.step button:hover, .ctl button:hover { background: #f4f5f2; border-color: #c6c9c3; }
.step button:first-child { border-radius: 8px 0 0 8px; }
.step button:last-child { border-radius: 0 8px 8px 0; margin-left: -1px; }
.ctl button { border-radius: 8px; }
.spacer { flex: 1; }
.toggle { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink-soft); cursor: pointer; user-select: none; }
.toggle input { accent-color: var(--accent); width: 15px; height: 15px; }
.zoomlabel { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); min-width: 42px; text-align: right; }
.slider-label { font-size: 12px; color: var(--ink-soft); font-weight: 550; }
.slider-val { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); min-width: 24px; }
input[type=range] { width: 72px; accent-color: var(--accent); cursor: pointer; }
.savestate { font-size: 11px; color: var(--ink-soft); min-width: 60px; }

#viewport {
  position: fixed; inset: 56px 0 0 0; overflow: hidden; cursor: grab;
  background: radial-gradient(circle at 1px 1px, #e3e5e0 1px, transparent 0); background-size: 26px 26px;
}
#viewport.drag { cursor: grabbing; }
#scene { position: absolute; top: 0; left: 0; transform-origin: 0 0; will-change: transform; }
#gridLayer { position: relative; z-index: 1; }
#overlay { position: absolute; top: 0; left: 0; z-index: 2; pointer-events: none; }
#overlay .card { pointer-events: auto; }

.planner { background: var(--paper); box-shadow: var(--shadow); border-radius: 10px; }
table.grid { border-collapse: collapse; }
table.grid th, table.grid td { border: 1px solid var(--line-soft); }
.corner { width: 64px; }
thead .dow { width: 30px; height: 30px; font-family: var(--mono); font-size: 11px; font-weight: 600;
  color: var(--ink-soft); background: var(--month-head); text-align: center; }
thead .dow.wknd { color: var(--accent); background: #fcf6dd; }
.moncol { width: 64px; font-size: 13px; font-weight: 650; letter-spacing: .02em; background: var(--month-head);
  text-align: left; padding: 0 0 0 12px; text-transform: uppercase; }
.moncol .yr-tiny { display:block; font-family: var(--mono); font-weight: 500; font-size: 10px; color: var(--ink-soft); letter-spacing: 0; }
td.day { width: 30px; height: 30px; vertical-align: top; position: relative; background: var(--paper); }
td.day .n { position: absolute; top: 2px; left: 4px; font-family: var(--mono); font-size: 10px; color: var(--ink-soft); }
td.day.wknd { background: var(--weekend); }
td.day.wknd .n { color: #9a7b1e; }
td.day.pad { background: #fafbf9; }
td.day.term { box-shadow: inset 0 0 0 9999px rgba(251,233,167,.6); }
td.day.term.wknd { box-shadow: inset 0 0 0 9999px rgba(246,224,138,.55); }
td.day .tb { position: absolute; left: 1px; right: 1px; bottom: 1px; font-family: var(--mono);
  font-size: 8px; line-height: 1.05; color: #8a6d12; font-weight: 650; text-align: center; white-space: nowrap; overflow: hidden; }
td.day.today { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---- overlay cards (starter; Claude Code will extend to bars/arrows) ---- */
.card {
  position: absolute; min-width: 64px; max-width: 220px; padding: 6px 8px;
  background: #fff3b0; border: 1px solid #e9c75a; border-radius: 6px;
  font-size: 11px; line-height: 1.3; color: #4a3d0e; box-shadow: 0 2px 6px rgba(31,36,33,.14);
  cursor: grab; user-select: none;
}
.card.drag { cursor: grabbing; box-shadow: 0 6px 16px rgba(31,36,33,.2); }
.card[contenteditable="true"] { cursor: text; outline: 2px solid var(--accent); }
.card .x { position: absolute; top: -8px; right: -8px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 12px; line-height: 18px; text-align: center;
  cursor: pointer; opacity: 0; transition: opacity .12s; }
.card:hover .x { opacity: 1; }

.panel {
  position: fixed; right: 16px; top: 72px; z-index: 25; width: 300px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 16px; font-size: 13px;
  transform: translateX(calc(100% + 24px)); transition: transform .26s cubic-bezier(.4,.0,.2,1);
}
.panel.open { transform: none; }
.panel h2 { margin: 0 0 4px; font-size: 13px; letter-spacing: .02em; text-transform: uppercase; }
.panel p.hint { margin: 0 0 12px; font-size: 11.5px; color: var(--ink-soft); line-height: 1.5; }
.term-row { display: grid; grid-template-columns: 1fr 96px 44px 26px; gap: 6px; align-items: center; margin-bottom: 7px; }
.term-row input { font-size: 12px; width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; background: #fcfcfb; }
.term-row input[type=date] { font-family: var(--mono); font-size: 11px; }
.term-row input.wk { font-family: var(--mono); text-align: center; }
.term-row .del { border: none; background: none; color: var(--ink-soft); cursor: pointer; font-size: 15px; }
.term-row .del:hover { color: var(--accent); }
.term-head { display: grid; grid-template-columns: 1fr 96px 44px 26px; gap: 6px; font-size: 10px; color: var(--ink-soft);
  text-transform: uppercase; letter-spacing: .03em; margin-bottom: 5px; }
.addbtn { margin-top: 6px; width: 100%; font-size: 12px; font-weight: 550; background: #f4f5f2;
  border: 1px dashed var(--line); border-radius: 7px; padding: 7px; cursor: pointer; }
.addbtn:hover { border-color: var(--accent); color: var(--accent); }
.hintbar { position: fixed; left: 18px; bottom: 16px; z-index: 15; font-size: 11.5px; color: var(--ink-soft);
  background: rgba(255,255,255,.8); padding: 7px 11px; border-radius: 8px; border: 1px solid var(--line); }
.hintbar b { color: var(--ink); font-weight: 600; }

/* ---- Fabric canvas wrapper ---- */
#viewport .canvas-container {
  position: absolute !important;
  top: 0 !important; left: 0 !important;
}

/* ---- inline rect label editor ---- */
#editTextarea {
  position: fixed;
  display: none;
  z-index: 50;
  resize: none;
  border: none;
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-radius: 2px;
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(2px);
  font-family: var(--sans);
  font-weight: 600;
  font-size: 13px;
  color: rgba(0,0,0,0.72);
  text-align: center;
  padding: 4px 6px;
  box-sizing: border-box;
  line-height: 1.4;
  overflow: hidden;
}

/* ---- draw-mode & toolbar extras ---- */
.ctl button.active { background: var(--ink); color: #fff; border-color: var(--ink); }
#viewport.draw-mode { cursor: crosshair; }

.color-picker { display: flex; align-items: center; gap: 5px; }
.swatch {
  width: 18px; height: 18px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; transition: border-color .12s, transform .1s;
  flex-shrink: 0;
}
.swatch:hover { transform: scale(1.2); }
.swatch.selected { border-color: var(--ink); }

/* ─── overlay panel (slides from left) ─────────────────────────────────── */
.overlay-panel {
  left: 16px; right: auto;
  transform: translateX(calc(-100% - 24px));
  min-width: 260px; max-width: 320px;
}
.overlay-panel.open { transform: none; }

.ov-row {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 8px; border-radius: 8px; cursor: pointer;
  margin-bottom: 3px; border: 1.5px solid transparent;
  transition: background .12s, border-color .12s;
  user-select: none;
}
.ov-row:hover  { background: #f4f5f2; }
.ov-row.active { border-color: var(--accent); background: #fef5f3; }

.ov-eye {
  font-size: 13px; background: none; border: none; cursor: pointer;
  color: var(--ink); padding: 0; width: 16px; line-height: 1; flex-shrink: 0;
}
.ov-eye.off { color: var(--ink-soft); opacity: 0.4; }

.ov-colour-swatch {
  width: 18px; height: 18px; border-radius: 50%;
  border: 1.5px solid rgba(0,0,0,0.12); cursor: pointer;
  padding: 0; flex-shrink: 0; appearance: none; -webkit-appearance: none;
  background: none;
}
.ov-colour-swatch::-webkit-color-swatch-wrapper { padding: 0; border-radius: 50%; }
.ov-colour-swatch::-webkit-color-swatch         { border: none; border-radius: 50%; }

.ov-name      { flex: 1; font-size: 12px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ov-name-edit { font-size: 12px; font-weight: 550; flex: 1; border: 1px solid var(--accent);
                border-radius: 4px; padding: 1px 4px; outline: none; min-width: 0; }

.ov-scope {
  font-size: 9px; text-transform: uppercase; font-weight: 650; letter-spacing: .04em;
  padding: 2px 5px; border-radius: 4px; flex-shrink: 0;
}
.ov-scope.course     { background: #e8f4fd; color: #2471a3; }
.ov-scope.department { background: #fef9e7; color: #b7950b; }
.ov-scope.faculty    { background: #eafaf1; color: #1e8449; }
.ov-scope.university { background: #f5eef8; color: #7d3c98; }

.ov-del {
  background: none; border: none; color: var(--ink-soft); cursor: pointer;
  font-size: 15px; padding: 0; opacity: 0; flex-shrink: 0;
}
.ov-row:hover .ov-del { opacity: 1; }
.ov-del:hover { color: var(--accent); }

.add-ov-form {
  margin-top: 10px; display: flex; flex-direction: column; gap: 7px;
  border-top: 1px solid var(--line-soft); padding-top: 10px;
}
.add-ov-form input[type="text"],
.add-ov-form select {
  font-size: 12px; border: 1px solid var(--line); border-radius: 6px;
  padding: 5px 8px; background: #fcfcfb; width: 100%; font-family: var(--sans);
}
.add-ov-form input[type="color"] {
  width: 100%; height: 30px; border: 1px solid var(--line); border-radius: 6px;
  cursor: pointer; padding: 2px 4px;
}
.add-ov-actions { display: flex; gap: 7px; }
.add-ov-actions button {
  flex: 1; font-size: 12px; font-weight: 550; padding: 6px; border-radius: 6px;
  cursor: pointer; border: 1px solid var(--line); background: #f4f5f2; font-family: var(--sans);
  transition: background .12s;
}
.add-ov-actions button:first-child { background: var(--ink); color: #fff; border-color: var(--ink); }
.add-ov-actions button:first-child:hover { background: #2e3530; }
.add-ov-actions button:last-child:hover  { background: #eceee9; }

/* ---- overlay rectangles ---- */
.rect-item {
  position: absolute; border: 1.5px solid rgba(0,0,0,0.18); border-radius: 3px;
  cursor: grab; user-select: none; box-sizing: border-box;
}
.rect-item.drag { cursor: grabbing; }
.rect-item .x {
  position: absolute; top: -8px; right: -8px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #fff; font-size: 12px; line-height: 18px; text-align: center;
  cursor: pointer; opacity: 0; transition: opacity .12s; z-index: 2;
}
.rect-item:hover .x { opacity: 1; }
.rect-text {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  padding: 6px; font-size: 12px; font-weight: 550; color: rgba(0,0,0,0.65);
  text-align: center; word-break: break-word; line-height: 1.35; box-sizing: border-box;
}
.rect-text[contenteditable="true"] { outline: 2px solid var(--accent); outline-offset: -2px; cursor: text; border-radius: 2px; }

/* resize handles */
.rh {
  position: absolute; width: 8px; height: 8px;
  background: #fff; border: 1.5px solid #666; border-radius: 2px;
  opacity: 0; transition: opacity .12s; z-index: 3;
}
.rect-item:hover .rh { opacity: 1; }
.rh-nw { top: -4px;            left: -4px;            cursor: nw-resize; }
.rh-n  { top: -4px;            left: calc(50% - 4px); cursor: n-resize; }
.rh-ne { top: -4px;            right: -4px;           cursor: ne-resize; }
.rh-e  { top: calc(50% - 4px); right: -4px;           cursor: e-resize; }
.rh-se { bottom: -4px;         right: -4px;           cursor: se-resize; }
.rh-s  { bottom: -4px;         left: calc(50% - 4px); cursor: s-resize; }
.rh-sw { bottom: -4px;         left: -4px;            cursor: sw-resize; }
.rh-w  { top: calc(50% - 4px); left: -4px;            cursor: w-resize; }
