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

:root {
  --bg:             #f0eee8;
  --bar-bg:         #e6e4dd;
  --surface:        #ffffff;
  --surface-2:      #fafaf8;
  --toolbar-bg:     #ffffff;
  --toolbar-border: #e2e0d8;
  --btn-bg:         #ffffff;
  --btn-hover:      #f5f3ef;
  --btn-border:     #d4d2ca;
  --btn-text:       #2c2c2a;
  --text-muted:     #888780;
  --purple:         #534AB7;
  --purple-light:   #EEEDFE;
  --purple-dark:    #4540a0;
  --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);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--btn-text); overflow: hidden; height: 100vh; height: 100svh;
  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: var(--surface); 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; color: var(--btn-text); background: var(--surface-2); 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: var(--purple-dark); }
.lobby-err   { font-size: 13px; color: #A32D2D; margin-top: 10px; min-height: 20px; }

.key-reveal {
  background: var(--purple-light); 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: var(--purple); 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; flex-direction: column;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--toolbar-border); flex-shrink: 0; z-index: 100;
}
.tb-row {
  display: flex; align-items: center; gap: 6px; padding: 5px 14px; width: 100%;
  flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.tb-row::-webkit-scrollbar { display: none; }
.tb-top { border-bottom: 1px solid var(--toolbar-border); }
.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: var(--purple-dark); }
button.danger:hover  { background: #FCEBEB; border-color: #E24B4A; color: #A32D2D; }
button:disabled { opacity: .4; cursor: not-allowed; }
.tb-icon-btn { width: 30px; height: 30px; padding: 0; border-radius: 50%; justify-content: center; flex-shrink: 0; gap: 0; }

.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: var(--btn-text); transform: scale(1.1); }
.swatch.themed { width: 26px; height: 26px; font-size: 13px; display: flex; align-items: center; justify-content: center; line-height: 1; }
.swatch-sep    { width: 1px; height: 20px; background: var(--toolbar-border); flex-shrink: 0; margin: 0 2px; }

#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; }

/* ── My Bubbles Panel (student board) ───────────────────── */
#my-bubbles-panel {
  display: none;
  flex-direction: row;
  align-items: stretch;
  gap: 8px;
  padding: 12px 12px 8px;
  height: 94px;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--toolbar-bg);
  border-bottom: 2px solid var(--toolbar-border);
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}
#my-bubbles-panel.visible { display: flex; }
#my-bubbles-panel::-webkit-scrollbar { height: 3px; }
#my-bubbles-panel::-webkit-scrollbar-track { background: transparent; }
#my-bubbles-panel::-webkit-scrollbar-thumb { background: var(--btn-border); border-radius: 2px; }

#panel-tab {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 24px;
  background: var(--toolbar-bg);
  border-bottom: 1px solid var(--toolbar-border);
  flex-shrink: 0;
  user-select: none;
  -webkit-user-select: none;
}
#panel-tab-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
}
#panel-pin-btn {
  font-size: 11px;
  padding: 0 8px;
  height: 18px;
  border-radius: 9px;
  border: 1px solid var(--btn-border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  transition: background .12s, color .12s, border-color .12s;
}
#panel-pin-btn.pinned {
  background: rgba(83,74,183,.1);
  color: #534AB7;
  border-color: rgba(83,74,183,.3);
}
#panel-pin-btn:hover { background: var(--btn-hover); }
#panel-pin-btn.pinned:hover { background: rgba(83,74,183,.18); }

.myb-card {
  min-width: 140px;
  max-width: 200px;
  flex: 0 0 auto;
  border-radius: 10px;
  border: 2px solid;
  padding: 6px 9px 7px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: box-shadow .15s, transform .1s;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.myb-card:hover { box-shadow: 0 2px 10px rgba(0,0,0,.14); }
.myb-card.selected { box-shadow: 0 0 0 3px #534AB7, 0 3px 14px rgba(83,74,183,.22); transform: translateY(-2px); }

.myb-ta {
  flex: 1;
  resize: none;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 12px;
  line-height: 1.4;
  overflow: hidden;
  min-height: 36px;
  padding: 0;
  outline: none;
  cursor: pointer;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
.myb-ta::placeholder { opacity: .45; }

.myb-owner {
  font-size: 10px;
  font-weight: 700;
  opacity: .55;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.myb-del {
  position: absolute;
  top: -8px; right: -8px;
  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 var(--surface);
  z-index: 20;
  transition: transform .1s;
}
.myb-card:hover .myb-del,
.myb-card.selected .myb-del { display: flex; }
.myb-del:hover { transform: scale(1.15); }

/* 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 #534AB7; outline-offset: 3px; box-shadow: 0 0 0 5px rgba(83,74,183,.18), var(--shadow); }

.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; }
/* Readonly canvas textareas are display-only — pass all pointer events to the bubble */
.popple textarea[readonly] { pointer-events: none; cursor: inherit; }

.dot {
  position: absolute; width: var(--dot); height: var(--dot);
  border-radius: 50%; background: var(--surface); border: 2.5px solid;
  cursor: crosshair; opacity: 0; transition: opacity .15s; z-index: 10;
}
.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 var(--surface); 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; }

.popple-text { font-size: 13.5px; font-weight: 500; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.view-only-badge { font-size: 12px; font-weight: 600; color: var(--text-muted); background: var(--btn-hover); border-radius: 20px; padding: 3px 10px; border: 1px solid var(--btn-border); white-space: nowrap; }

/* ── Presentation mode ───────────────────────────────────── */
body.present-mode #toolbar { display: none; }
#present-bar {
  position: fixed; bottom: 24px; right: 24px;
  background: rgba(30,26,55,0.82); backdrop-filter: blur(8px);
  color: #fff; border-radius: 14px; padding: 8px 14px;
  display: none; align-items: center; gap: 8px;
  z-index: 9000; opacity: 0.3; transition: opacity .2s;
  user-select: none;
}
#present-bar:hover { opacity: 1; }
body.present-mode #present-bar { display: flex; }
#present-bar button {
  background: rgba(255,255,255,.13); border: 1px solid rgba(255,255,255,.18);
  color: #fff; border-radius: 8px; padding: 5px 11px;
  font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit;
  display: flex; align-items: center; gap: 5px;
}
#present-bar button:hover { background: rgba(255,255,255,.26); }
#present-bar .pb-sep { width: 1px; height: 16px; background: rgba(255,255,255,.2); }
#pb-zoom { font-size: 12px; min-width: 36px; text-align: center; }

.popple-vote {
  display: none; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; letter-spacing: .01em;
  border: 1.5px solid transparent; border-radius: 20px;
  padding: 2px 9px 2px 6px; margin-top: 5px; align-self: flex-start;
  background: rgba(0,0,0,.05); color: inherit; opacity: .6;
  cursor: pointer; font-family: inherit;
  transition: background .12s, opacity .12s, border-color .12s;
  user-select: none;
}
.popple-vote:hover { opacity: 1; background: rgba(0,0,0,.09); }
.popple-vote.voted { opacity: 1; background: rgba(127,119,221,.18); border-color: rgba(127,119,221,.55); }

/* ── 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: var(--surface); 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 var(--toolbar-border); }

/* ── 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: var(--surface-2);
  cursor: pointer; transition: border-color .12s, background .12s;
}
.room-card:hover { border-color: var(--purple); background: var(--purple-light); }
.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: var(--surface); 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: var(--surface-2); 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: var(--purple-dark); }

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

/* ── Bubble edit modal ─────────────────────────────────────── */
.edit-modal-overlay {
  position: fixed; inset: 0; z-index: 900;
  background: rgba(0,0,0,.45);
  display: none; align-items: center; justify-content: center;
}
.edit-modal-overlay.open { display: flex; }
.edit-modal-box {
  background: var(--surface);
  border-radius: 14px;
  width: min(480px, 92vw);
  max-height: 80vh;
  box-shadow: 0 8px 40px rgba(0,0,0,.28);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.edit-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--toolbar-border);
  flex-shrink: 0;
}
.edit-modal-label {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em;
}
.edit-modal-close {
  font-size: 22px; line-height: 1; padding: 0 2px 2px;
  color: var(--text-muted); background: none; border: none; cursor: pointer;
}
.edit-modal-close:hover { color: var(--btn-text); }
.edit-modal-ta {
  flex: 1; resize: none; min-height: 160px;
  padding: 14px 16px; font-size: 15px; line-height: 1.55;
  border: none; outline: none;
  background: transparent; color: var(--btn-text);
  font-family: inherit;
}
.edit-modal-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--toolbar-border);
  display: flex; justify-content: flex-end;
  flex-shrink: 0;
}
.edit-modal-footer .edit-modal-done {
  padding: 8px 24px; background: var(--purple);
  color: #fff; border: none; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.edit-modal-footer .edit-modal-done:hover { background: var(--purple-dark); }

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

/* ── Locked board — student view ─────────────────────────────── */
.board-locked {
  cursor: default !important;
}
.board-locked textarea {
  cursor: default !important;
}

/* ── Teacher star in owner label ─────────────────────────────── */
.popple-owner {
  font-size: 10px;
  font-weight: 700;
  opacity: .6;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}


