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

:root {
  --bg:             #f0eee8;
  --toolbar-bg:     #ffffff;
  --toolbar-border: #e2e0d8;
  --btn-bg:         #ffffff;
  --btn-hover:      #f5f3ef;
  --btn-border:     #d4d2ca;
  --btn-text:       #2c2c2a;
  --text-muted:     #888780;
  --dot:            13px;
  --shadow:         0 2px 8px rgba(0,0,0,.10), 0 1px 2px rgba(0,0,0,.06);
  --shadow-drag:    0 10px 32px rgba(0,0,0,.18), 0 2px 6px rgba(0,0,0,.10);
  --purple:         #534AB7;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg); overflow: hidden; height: 100vh;
  display: flex; flex-direction: column;
}

/* ── Lobby ───────────────────────────────────────────────── */
#lobby {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 9000;
}
#lobby-box {
  background: #fff; border-radius: 18px; padding: 36px 40px; width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,.14); max-width: 92vw;
}
#lobby-box h1  { font-size: 26px; color: var(--purple); margin-bottom: 4px; }
#lobby-box .sub { font-size: 14px; color: var(--text-muted); margin-bottom: 28px; }

.lobby-tabs   { display: flex; gap: 6px; margin-bottom: 24px; }
.ltab {
  flex: 1; padding: 8px; border-radius: 8px; border: 1.5px solid var(--btn-border);
  background: var(--btn-bg); font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit; color: var(--btn-text); transition: all .12s;
}
.ltab.active { background: var(--purple); color: #fff; border-color: var(--purple); }

.lobby-section       { display: none; }
.lobby-section.active { display: block; }

.field        { margin-bottom: 16px; }
.field label  { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted);
                margin-bottom: 5px; text-transform: uppercase; letter-spacing: .04em; }
.field input  {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1.5px solid var(--btn-border);
  font-size: 14px; font-family: inherit; background: #fafaf8; outline: none; transition: border-color .15s;
}
.field input:focus        { border-color: var(--purple); }
.field input.code-input   { text-transform: uppercase; letter-spacing: .15em; font-size: 18px;
                            font-weight: 700; text-align: center; }
.lobby-btn {
  width: 100%; padding: 11px; border-radius: 9px; border: none;
  background: var(--purple); color: #fff; font-size: 14px; font-weight: 600;
  font-family: inherit; cursor: pointer; transition: background .12s; margin-top: 4px;
}
.lobby-btn:hover { background: #4540a0; }
.lobby-err   { font-size: 13px; color: #A32D2D; margin-top: 10px; min-height: 20px; }

.key-reveal {
  background: #EEEDFE; border-radius: 10px; padding: 14px 16px; margin-top: 18px; display: none;
}
.key-reveal .klabel  { font-size: 12px; font-weight: 700; color: #3C3489; margin-bottom: 4px; }
.key-reveal .kval    { font-size: 22px; font-weight: 800; color: #3C3489; letter-spacing: .18em; }
.key-reveal .ktkey   { font-size: 11px; color: #534AB7; word-break: break-all; margin-top: 6px; }
.key-reveal .kwarn   { font-size: 11px; color: #D85A30; margin-top: 6px; }
.key-reveal .enter-btn { margin-top: 14px; }

/* ── Toolbar ─────────────────────────────────────────────── */
#toolbar {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding: 7px 14px; background: var(--toolbar-bg);
  border-bottom: 1px solid var(--toolbar-border); flex-shrink: 0; z-index: 100;
}
.title { font-size: 15px; font-weight: 700; color: var(--purple); letter-spacing: -.3px; }
.sep   { width: 1px; height: 22px; background: var(--toolbar-border); margin: 0 3px; flex-shrink: 0; }

button {
  display: inline-flex; align-items: center; gap: 5px; padding: 5px 11px;
  font-size: 12.5px; font-family: inherit; font-weight: 500;
  border: 1px solid var(--btn-border); background: var(--btn-bg); color: var(--btn-text);
  border-radius: 7px; cursor: pointer; transition: background .12s; white-space: nowrap;
}
button:hover    { background: var(--btn-hover); }
button.primary  { background: var(--purple); color: #fff; border-color: var(--purple); }
button.primary:hover { background: #4540a0; }
button.danger:hover  { background: #FCEBEB; border-color: #E24B4A; color: #A32D2D; }
button:disabled { opacity: .4; cursor: not-allowed; }

.swatch-group { display: flex; gap: 5px; align-items: center; }
.swatch {
  width: 22px; height: 22px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; transition: transform .12s, border-color .12s; flex-shrink: 0;
}
.swatch:hover  { transform: scale(1.15); }
.swatch.active { border-color: #2c2c2a; transform: scale(1.1); }

#zoom-label { font-size: 12px; color: var(--text-muted); min-width: 38px; text-align: center; }

#status-pill {
  display: flex; align-items: center; gap: 5px; font-size: 12px;
  padding: 4px 10px; border-radius: 20px; border: 1px solid var(--btn-border);
  background: var(--btn-bg); margin-left: auto; flex-shrink: 0;
}
#status-dot          { width: 7px; height: 7px; border-radius: 50%; background: #ccc; flex-shrink: 0; }
#status-dot.ok       { background: #1D9E75; }
#status-dot.busy     { background: #EF9F27; }
#status-dot.error    { background: #E24B4A; }

/* lock banner */
#lock-banner {
  display: none; background: #FAEEDA; border-bottom: 1px solid #EF9F27;
  padding: 6px 16px; font-size: 13px; font-weight: 600; color: #633806;
  text-align: center; flex-shrink: 0;
}
#lock-banner.show { display: block; }

/* teacher-only toolbar items hidden until body.is-teacher */
.teacher-only { display: none !important; }
body.is-teacher .teacher-only { display: inline-flex !important; }

/* ── Canvas ──────────────────────────────────────────────── */
#world-wrap { flex: 1; overflow: hidden; position: relative; cursor: default; }
#world      { position: absolute; top: 0; left: 0; transform-origin: 0 0; width: 4000px; height: 4000px; }
#grid-svg   { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; }
#edge-svg   { position: absolute; top: 0; left: 0; width: 4000px; height: 4000px;
              pointer-events: none; overflow: visible; }
.edge-del   { pointer-events: all; cursor: pointer; }

/* ── Popples ─────────────────────────────────────────────── */
.popple {
  position: absolute; min-width: 130px; min-height: 74px;
  border-radius: 13px; border: 2.5px solid; padding: 12px 14px;
  cursor: grab; user-select: none; display: flex; flex-direction: column;
  box-shadow: var(--shadow); transition: box-shadow .15s;
}
.popple:active          { cursor: grabbing; }
.popple.dragging        { box-shadow: var(--shadow-drag); z-index: 1000 !important; }
.popple.selected        { outline: 3px solid rgba(83,74,183,.55); outline-offset: 2px; }

.popple-owner { font-size: 10px; font-weight: 700; opacity: .55; margin-bottom: 4px;
                text-transform: uppercase; letter-spacing: .04em; }

.popple textarea {
  background: transparent; border: none; outline: none;
  font-family: inherit; font-size: 13.5px; font-weight: 500;
  resize: none; width: 100%; line-height: 1.45;
  cursor: text; overflow: hidden; min-height: 36px;
}
.popple textarea::placeholder { opacity: .5; }

.dot {
  position: absolute; width: var(--dot); height: var(--dot);
  border-radius: 50%; background: #fff; border: 2.5px solid;
  cursor: crosshair; opacity: 0; transition: opacity .15s; z-index: 10;
}
.popple:hover .dot, .popple.selected .dot { opacity: 1; }
.dot[data-dir="t"] { top:    calc(var(--dot)/-2); left:   50%;  transform: translateX(-50%); }
.dot[data-dir="b"] { bottom: calc(var(--dot)/-2); left:   50%;  transform: translateX(-50%); }
.dot[data-dir="l"] { left:   calc(var(--dot)/-2); top:    50%;  transform: translateY(-50%); }
.dot[data-dir="r"] { right:  calc(var(--dot)/-2); top:    50%;  transform: translateY(-50%); }

.popple-del {
  position: absolute; top: -9px; right: -9px; width: 20px; height: 20px;
  border-radius: 50%; background: #E24B4A; color: #fff; font-size: 13px; font-weight: 700;
  line-height: 1; display: none; align-items: center; justify-content: center;
  cursor: pointer; border: 2px solid #fff; z-index: 20;
}
.popple.selected .popple-del { display: flex; }

.popple-resize {
  position: absolute; bottom: 3px; right: 4px; width: 14px; height: 14px;
  cursor: se-resize; opacity: 0; transition: opacity .15s;
}
.popple:hover .popple-resize, .popple.selected .popple-resize { opacity: .4; }

/* ── Toast ───────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(10px);
  background: #2c2c2a; color: #fff; padding: 8px 18px; border-radius: 8px;
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 9999;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Help overlay ────────────────────────────────────────── */
#help-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 5000; opacity: 0; pointer-events: none; transition: opacity .2s;
}
#help-overlay.show { opacity: 1; pointer-events: all; }
#help-box {
  background: #fff; border-radius: 14px; padding: 28px 32px;
  max-width: 420px; width: 90%; box-shadow: 0 20px 60px rgba(0,0,0,.25);
  max-height: 88vh; overflow-y: auto;
}
#help-box h2 { font-size: 18px; margin-bottom: 16px; color: var(--purple); }
#help-box table { width: 100%; border-collapse: collapse; font-size: 13px; }
#help-box td    { padding: 6px 0; vertical-align: top; }
#help-box td:first-child { color: var(--purple); font-weight: 600; padding-right: 14px; white-space: nowrap; }
#help-box tr + tr td { border-top: 1px solid #f0eee8; }

/* ── Layout Components ────────────────────────────────────────── */
.logo-container {
    display: flex;
    flex-direction: column; /* Stack the image and text vertically */
    align-items: center;    /* Center them horizontally */
    text-align: center;     /* Center the text itself */
    margin: 20px auto;      /* Center the entire container on the page */
}

.sub {
    margin-top: 10px;       /* Adds a clean space between the logo and text */
    font-family: sans-serif; /* Clean font style for a modern look */
}
/* ── Auth panels (login / register) ─────────────────────────────── */
.auth-toggle {
  font-size: 12px; color: var(--text-muted); margin-top: 14px; text-align: center;
}
.auth-toggle a {
  color: var(--purple); cursor: pointer; text-decoration: underline;
}

/* ── Teacher dashboard (room list) ──────────────────────────────── */
#teacher-dashboard { display: none; }
#teacher-dashboard.active { display: block; }

.teacher-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.teacher-header .welcome {
  font-size: 13px; font-weight: 600; color: var(--purple);
}
.teacher-header .sign-out {
  font-size: 12px; color: var(--text-muted); cursor: pointer;
  text-decoration: underline; background: none; border: none; padding: 0;
}

.rooms-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 280px; overflow-y: auto; margin-bottom: 14px;
  padding-right: 2px;
}
.rooms-list:empty::after {
  content: 'No MindBubbles yet — create your first one below.';
  font-size: 13px; color: var(--text-muted); display: block; padding: 8px 0;
}

.room-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  border: 1.5px solid var(--btn-border); background: #fafaf8;
  cursor: pointer; transition: border-color .12s, background .12s;
}
.room-card:hover { border-color: var(--purple); background: #EEEDFE; }
.room-card .rc-info { flex: 1; min-width: 0; }
.room-card .rc-name {
  font-size: 13.5px; font-weight: 600; color: var(--btn-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.room-card .rc-meta {
  font-size: 11px; color: var(--text-muted); margin-top: 2px;
}
.room-card .rc-code {
  font-size: 16px; font-weight: 800; color: var(--purple);
  letter-spacing: .1em; flex-shrink: 0;
}
.room-card .rc-del {
  width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--btn-border);
  background: #fff; color: #A32D2D; font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; line-height: 1;
}
.room-card .rc-del:hover { background: #FCEBEB; border-color: #E24B4A; }

.new-room-form {
  display: flex; gap: 8px; margin-top: 4px;
}
.new-room-form input {
  flex: 1; padding: 9px 12px; border-radius: 8px; border: 1.5px solid var(--btn-border);
  font-size: 13px; font-family: inherit; background: #fafaf8; outline: none;
}
.new-room-form input:focus { border-color: var(--purple); }
.new-room-form button {
  padding: 9px 14px; border-radius: 8px; background: var(--purple);
  color: #fff; border: none; font-size: 13px; font-weight: 600;
  font-family: inherit; cursor: pointer; white-space: nowrap;
}
.new-room-form button:hover { background: #4540a0; }

/* wider lobby box for teacher dashboard */
#lobby-box.wide { width: 480px; }

/* ── Exit / back to dashboard button ────────────────────────────── */
#exitBtn {
  background: #F1EFE8;
  border-color: var(--btn-border);
  color: var(--btn-text);
  margin-left: 4px;
}
#exitBtn:hover {
  background: #EEEDFE;
  border-color: var(--purple);
  color: var(--purple);
}
