/* Virtual Mind XR — web. Colors come from the theme (theme.js sets the --vars on :root). */
:root {
  --bg: rgba(248,250,252,.95); --surface: #fff; --surfaceAlt: #eef2f7; --surfaceHover: #e4ecfa; --outline: #e3e8ef;
  --accent: #3b6fc8; --accentHover: #4f82da; --accentPressed: #2f5ca8; --onAccent: #fff;
  --danger: #c94f4f; --dangerHover: #d96363; --dangerPressed: #a83e3e; --onDanger: #fff;
  --text: #1e2733; --textMuted: #5b6573; --textPlaceholder: #8a93a0; --textAccent: #3b6fc8; --textDanger: #c0392b;
  --edge: rgba(59,111,200,.75); --font: 'Plus Jakarta Sans', system-ui, sans-serif; --scale: 1; --header-image: none;
  --radius: 14px; --room: radial-gradient(1200px 700px at 30% 20%, #e9eef4, #cfd8e3 60%, #bcc7d4);
}
:root[data-dark="1"] { --room: radial-gradient(1200px 700px at 30% 20%, #2a313c, #161a21 65%, #0e1116); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--room); color: var(--text); font-family: var(--font); font-size: calc(15px * var(--scale)); overflow: hidden; }
button, input, textarea { font: inherit; color: inherit; }
#app { position: fixed; inset: 0; }
.unsupported { margin: 20vh auto; max-width: 520px; padding: 24px; background: var(--bg); border-radius: var(--radius); }

/* ---------- icons (headset sprites used as masks, tinted by currentColor) */
.icon { display: inline-block; width: 1.25em; height: 1.25em; flex: none; background: currentColor;
  -webkit-mask: var(--icon) center / contain no-repeat; mask: var(--icon) center / contain no-repeat; }
.icon.flip, .back .icon { transform: scaleX(-1); }

/* ---------- buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 8px 18px;
  border-radius: 10px; border: 1px solid var(--outline); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 600;
  transition: background .12s, transform .06s; white-space: nowrap; }
.btn:hover:not(:disabled) { background: var(--surfaceHover); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-accent { background: var(--accent); border-color: transparent; color: var(--onAccent); }
.btn-accent:hover:not(:disabled) { background: var(--accentHover); }
.btn-accent:active:not(:disabled) { background: var(--accentPressed); }
.btn-danger { background: var(--danger); border-color: transparent; color: var(--onDanger); }
.btn-danger:hover:not(:disabled) { background: var(--dangerHover); }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--outline); background: var(--surface); color: var(--text); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--surfaceHover); }
.recording { background: var(--danger) !important; color: var(--onDanger) !important; animation: rec 1.2s infinite; }
@keyframes rec { 50% { opacity: .7; } }

/* ---------- panels (the headset's floating windows) */
.panel { position: relative; max-width: 100%; max-height: calc(100vh - 32px); display: flex; flex-direction: column;
  background: var(--bg); border: 1px solid var(--outline); border-radius: 22px; box-shadow: 0 24px 60px rgba(0,0,0,.25);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); overflow: hidden; }
.panel-header-image { position: absolute; inset: 0 0 auto 0; height: 120px; background: var(--header-image) center / cover; pointer-events: none; opacity: .9; }
.panel-title { position: relative; margin: 0; padding: 20px 24px 8px; font-size: 1.55em; font-weight: 700; }
.panel-title.with-actions { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.title-actions { display: flex; gap: 10px; font-size: calc(14px * var(--scale)); }
.panel-content { position: relative; padding: 8px 24px 12px; overflow: auto; flex: 1; }
.panel-footer { position: relative; display: flex; gap: 12px; justify-content: center; padding: 12px 24px 18px; flex-wrap: wrap; }
.panel-hint { text-align: center; color: var(--textMuted); font-size: .82em; padding: 0 16px 14px; }
.panel::after { content: ""; position: absolute; bottom: 6px; left: 50%; width: 72px; height: 5px; margin-left: -36px; border-radius: 3px; background: var(--outline); }

.screen { position: absolute; inset: 0; }
.screen-browser { display: flex; align-items: center; justify-content: center; padding: 16px; }
.screen-browser.dropping .panel { outline: 3px dashed var(--accent); outline-offset: 6px; }

.modal-backdrop { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(10,14,20,.28); z-index: 50; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.dialog-message { white-space: pre-line; line-height: 1.5; margin: 6px 0; }

#toasts { position: fixed; left: 50%; bottom: 96px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.25); transition: opacity .3s; max-width: 80vw; text-align: center; }
.toast.hide { opacity: 0; }

/* ---------- browser */
.browser { min-height: 480px; }
.carousel { position: relative; display: flex; align-items: center; gap: 8px; }
.carousel-track { flex: 1; display: flex; gap: 24px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 24px calc(50% - 120px) 44px; scrollbar-width: none; }
.carousel-track::-webkit-scrollbar { display: none; }
.carousel-arrow { width: 40px; height: 64px; border: none; border-radius: 12px; background: var(--surfaceAlt); color: var(--text); font-size: 30px; cursor: pointer; flex: none; }
.carousel-arrow:disabled { opacity: .3; cursor: default; }
.carousel-empty { text-align: center; color: var(--textMuted); padding: 40px 20px; }
.project-card { position: relative; flex: none; width: calc(240px * var(--scale)); height: calc(170px * var(--scale)); scroll-snap-align: center;
  background: var(--surface); border: 1px solid var(--outline); border-top: 5px solid var(--accent); border-radius: 12px;
  padding: 14px 16px; cursor: pointer; transition: transform .2s, opacity .2s, box-shadow .2s; opacity: .6; transform: scale(.88); }
.project-card.center { opacity: 1; transform: scale(1.05); box-shadow: 0 12px 30px rgba(0,0,0,.15); }
.project-card:hover { opacity: 1; }
.project-card.detective { border-top-color: #8b5a2b; }
.project-title { font-size: 1.25em; font-weight: 700; line-height: 1.25; max-height: 2.6em; overflow: hidden; }
.project-folder { color: var(--textAccent); font-size: .85em; margin-top: 18px; }
.project-meta { color: var(--textMuted); font-size: .8em; margin-top: 4px; }
.project-actions { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px; }
.project-actions .icon-btn { width: 32px; height: 32px; }

/* ---------- forms */
.field-label { display: block; font-weight: 600; margin: 12px 0 6px; }
.field-row { display: flex; gap: 8px; align-items: center; }
.text-input { flex: 1; width: 100%; min-height: 44px; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--outline); background: var(--surface); }
.text-input:focus, .note-text:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.text-input::placeholder, .note-text::placeholder { color: var(--textPlaceholder); }
.field-error { color: var(--textDanger); min-height: 1.4em; font-size: .9em; margin-top: 4px; }
.template-row { display: flex; gap: 10px; flex-wrap: wrap; }
.template-option { flex: 1; min-width: 110px; padding: 12px; border-radius: 12px; border: 1px solid var(--outline); background: var(--surface); cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.template-option small { color: var(--textMuted); }
.template-option.selected { background: var(--accent); color: var(--onAccent); border-color: transparent; }
.template-option.selected small { color: var(--onAccent); opacity: .85; }
.template-desc { color: var(--textMuted); margin: 10px 2px; min-height: 1.4em; }
.setting-row { display: flex; align-items: center; gap: 16px; margin: 14px 0; flex-wrap: wrap; }
.setting-label { width: 170px; color: var(--textMuted); }
.setting-options { display: flex; gap: 10px; flex: 1; flex-wrap: wrap; }
.option { flex: 1; min-width: 110px; min-height: 42px; border-radius: 10px; border: 1px solid var(--outline); background: var(--surface); cursor: pointer; padding: 6px 14px; }
.option:hover { background: var(--surfaceHover); }
.option.selected { background: var(--accent); color: var(--onAccent); border-color: transparent; }
.option.selected::before { content: "✓ "; }
.theme-current { flex: 0 1 220px; }
.setting-note { color: var(--textMuted); font-size: .85em; }
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.theme-option { border-radius: 14px; border: 2px solid transparent; padding: 14px; cursor: pointer; text-align: left; display: flex; flex-direction: column; gap: 10px; box-shadow: 0 4px 14px rgba(0,0,0,.12); }
.theme-option.selected { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent); }
.theme-name { font-weight: 700; font-size: 1.1em; }
.theme-sample { border: 1px solid; border-radius: 10px; padding: 10px; display: flex; flex-direction: column; }
.theme-accent { border-radius: 8px; padding: 8px; text-align: center; font-weight: 600; }
.welcome-steps { padding-left: 1.4em; line-height: 1.5; }
.welcome-steps li { margin: 10px 0; }
.welcome-steps b { display: block; }
.welcome-steps span { color: var(--textMuted); }
.export-options, .photo-source { display: flex; flex-direction: column; gap: 12px; margin: 14px 0; }

/* ---------- map editor */
.screen-map { background: var(--room); }
.map-topbar { position: absolute; inset: 12px 12px auto 12px; z-index: 10; display: flex; align-items: center; gap: 14px;
  padding: 8px 10px; border-radius: 16px; background: var(--bg); border: 1px solid var(--outline); box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.map-title { font-weight: 700; font-size: 1.2em; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-status { color: var(--textMuted); font-size: .85em; }
.map-viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; outline: none; }
.map-viewport:active { cursor: grabbing; }
.map-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.map-world.view-anim { transition: transform .4s ease; }
.map-world.aligning .card { transition: left .4s ease, top .4s ease; }
.map-edges { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; pointer-events: none; }
.edge { stroke: var(--edge); stroke-width: 3; fill: none; stroke-linecap: round; }
.edge.twine { stroke: #b0261c; stroke-width: 3.5; filter: drop-shadow(0 3px 2px rgba(0,0,0,.45)); }
.temp-edge { display: none; stroke: var(--accent); stroke-width: 3; stroke-dasharray: 8 6; }
.map-cards { position: absolute; left: 0; top: 0; }

.card { position: absolute; width: 200px; height: 120px; border-radius: 12px; background: var(--surface); border: 2px solid var(--outline);
  box-shadow: 0 6px 16px rgba(0,0,0,.14); cursor: grab; user-select: none; touch-action: none; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 35%, transparent), 0 8px 20px rgba(0,0,0,.18); }
.card.dragging { cursor: grabbing; z-index: 5; box-shadow: 0 14px 30px rgba(0,0,0,.25); }
.card.link-target { border-color: #2fa84f; box-shadow: 0 0 0 5px rgba(47,168,79,.45); }
.card.unlink-target { border-color: #d64545; box-shadow: 0 0 0 5px rgba(214,69,69,.45); }
.card.pulse { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px color-mix(in srgb, var(--accent) 45%, transparent); } }
.card-face { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 12px; overflow: hidden; border-radius: 10px; }
.card-title { font-size: calc(20px * var(--scale)); font-weight: 700; text-align: center; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; word-break: break-word; }
.card-title.long { font-size: calc(15px * var(--scale)); }
.card-thumb { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card-actions { position: absolute; left: 50%; top: calc(100% + 6px); transform: translateX(-50%); display: flex; gap: 5px; opacity: 0; transition: opacity .15s; pointer-events: none; }
.card:hover .card-actions, .card.selected .card-actions { opacity: 1; pointer-events: auto; }
.card-btn { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--outline); background: var(--surface); color: var(--text); cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }
.card-btn:hover { background: var(--surfaceHover); }
.card-btn:disabled { opacity: .4; }
.connector { position: absolute; left: 100%; top: 50%; width: 58px; height: 30px; margin-top: -15px; cursor: crosshair; opacity: 0; transition: opacity .15s; }
.card:hover .connector, .card.selected .connector { opacity: 1; }
.connector-stem { position: absolute; left: 0; top: 14px; width: 36px; height: 3px; background: var(--accent); opacity: .6; }
.connector-dot { position: absolute; right: 0; top: 2px; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); border: 3px solid var(--surface); box-shadow: 0 2px 6px rgba(0,0,0,.3); }

/* detective mode */
.board { position: absolute; border: 22px solid transparent; border-image: url(img/wood.png) 30 round; box-sizing: content-box; margin: -22px; box-shadow: 0 20px 50px rgba(0,0,0,.45); }
.board-surface { position: absolute; inset: 0; background: #22302a url(img/chalkboard.png) center / cover; }
.board-tray { position: absolute; left: 6%; right: 6%; bottom: -46px; height: 18px; background: url(img/wood.png) center / cover; border-radius: 3px; box-shadow: 0 6px 10px rgba(0,0,0,.35); }
.board-tray::after { content: ""; position: absolute; left: 62%; top: -5px; width: 48px; height: 9px; border-radius: 4px; background: #f3f0e6; }
.board-resize { position: absolute; right: -36px; bottom: -36px; width: 28px; height: 28px; border-radius: 50%; background: radial-gradient(circle at 35% 35%, #f2d27a, #a87b22); box-shadow: 0 3px 8px rgba(0,0,0,.5); cursor: nwse-resize; }
.card.paper { background: #f6efd9 url(img/paper_card.png) center / cover; border: none; border-radius: 3px; transform: rotate(var(--tilt));
  box-shadow: 0 8px 14px rgba(0,0,0,.45); color: #2a2620; }
.card.paper .card-title { font-family: 'Special Elite', monospace; font-weight: 400; }
.card.paper.selected { box-shadow: 0 0 0 3px #f2d27a, 0 10px 18px rgba(0,0,0,.5); }
.pin { position: absolute; left: 50%; top: -4px; width: 22px; height: 22px; margin-left: -11px; border-radius: 50%; z-index: 2;
  background: radial-gradient(circle at 35% 35%, #ff7a6b, #b3261e 70%); box-shadow: 0 4px 5px rgba(0,0,0,.5); }
.is-board .card-actions .card-btn { background: #f6efd9; color: #2a2620; }

.map-zoom { position: absolute; right: 16px; bottom: 110px; z-index: 10; display: flex; flex-direction: column; gap: 6px; }
.map-zoom button { width: 42px; height: 42px; border-radius: 12px; border: 1px solid var(--outline); background: var(--bg); color: var(--text); font-size: 20px; cursor: pointer; box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.map-dock { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 10; display: flex; gap: 6px; padding: 8px;
  border-radius: 18px; background: var(--bg); border: 1px solid var(--outline); box-shadow: 0 10px 30px rgba(0,0,0,.18); max-width: calc(100vw - 24px); overflow-x: auto; }
.dock-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 84px; padding: 8px 10px; border: none; border-radius: 12px; background: transparent; color: var(--text); cursor: pointer; font-size: .78em; font-weight: 600; }
.dock-btn .icon { width: 22px; height: 22px; }
.dock-btn:hover:not(:disabled) { background: var(--surfaceHover); }
.dock-btn:disabled { opacity: .4; cursor: default; }

.map-side { position: absolute; right: 16px; top: 84px; bottom: 100px; z-index: 20; display: none; }
.map-side.open { display: flex; align-items: flex-start; }
.side-panel { max-height: 100%; }
.search-results { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.search-result { text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--outline); background: var(--surface); cursor: pointer; }
.search-result:hover { background: var(--surfaceHover); }
.result-snippet { color: var(--textMuted); font-size: .88em; margin-top: 4px; }
.result-snippet mark { background: none; color: var(--textAccent); font-weight: 700; }
.search-empty { color: var(--textMuted); }
.study-progress { color: var(--textMuted); font-size: .85em; }
.study-question { font-size: 1.3em; font-weight: 700; margin: 10px 0 14px; }
.study-answer { white-space: pre-line; line-height: 1.5; padding: 12px; border-radius: 10px; background: var(--surfaceAlt); margin-bottom: 14px; }
.study-buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.study-done { font-size: 1.2em; font-weight: 700; }
.study-next { color: var(--textMuted); }

/* ---------- note editor */
.note-editor { height: min(780px, calc(100vh - 32px)); }
.note-body { display: flex; gap: 14px; height: 100%; min-height: 360px; }
.note-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.note-text { flex: 1; width: 100%; resize: none; padding: 14px; border-radius: 12px; border: 1px solid var(--outline); background: var(--surface); line-height: 1.5; font-size: 1.02em; }
.note-view { flex: 1; overflow: auto; padding: 14px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--outline); }
.note-message { min-height: 1.5em; color: var(--textMuted); font-size: .9em; margin-top: 6px; }
.note-tools { display: flex; flex-direction: column; gap: 8px; }
.tool-btn { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 92px; padding: 10px 6px; border-radius: 12px; border: 1px solid var(--outline); background: var(--surface); cursor: pointer; font-size: .78em; font-weight: 600; }
.tool-btn .icon { width: 24px; height: 24px; }
.tool-btn:hover:not(:disabled) { background: var(--surfaceHover); }
.tool-btn:disabled { opacity: .4; }
.markdown { line-height: 1.55; }
.md-line { min-height: 1.55em; white-space: pre-wrap; word-break: break-word; }
.md-h1 { font-size: 1.3em; font-weight: 700; margin: 6px 0; }
.md-h3 { font-weight: 700; }
.md-blank { min-height: .8em; }
.md-li { padding-left: 4px; }
.md-missing { color: var(--textMuted); }
.md-img { display: block; max-width: 100%; max-height: 420px; border-radius: 10px; margin: 8px 0; cursor: zoom-in; }
.md-audio { display: flex; align-items: center; gap: 10px; margin: 8px 0; padding: 8px 12px; border-radius: 10px; background: var(--surfaceAlt); }
.md-audio audio { height: 34px; flex: 1; }
.md-task { display: flex; gap: 10px; align-items: flex-start; margin: 4px 0; cursor: pointer; }
.md-task input { width: 20px; height: 20px; accent-color: var(--accent); margin-top: 2px; }
.md-task.done span { text-decoration: line-through; color: var(--textMuted); }
.markdown a { color: var(--textAccent); }

/* ---------- photos */
.camera-video { width: 100%; border-radius: 12px; background: #000; }
.crop-stage { position: relative; display: inline-block; max-width: 100%; user-select: none; }
.crop-image { display: block; max-width: 100%; max-height: 60vh; border-radius: 8px; }
.crop-frame { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.45); cursor: move; touch-action: none; }
.crop-handle { position: absolute; width: 22px; height: 22px; background: #fff; border-radius: 50%; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.crop-handle.tl { left: -11px; top: -11px; cursor: nwse-resize; } .crop-handle.tr { right: -11px; top: -11px; cursor: nesw-resize; }
.crop-handle.bl { left: -11px; bottom: -11px; cursor: nesw-resize; } .crop-handle.br { right: -11px; bottom: -11px; cursor: nwse-resize; }
.search-status { color: var(--textMuted); margin: 10px 0; font-size: .9em; }
.image-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.image-cell { display: flex; flex-direction: column; gap: 4px; padding: 6px; border-radius: 10px; border: 1px solid var(--outline); background: var(--surface); cursor: pointer; text-align: left; font-size: .78em; }
.image-cell img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 6px; background: var(--surfaceAlt); }
.image-cell span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--textMuted); }
.image-cell:hover { outline: 2px solid var(--accent); }

@media (max-width: 700px) {
  .dock-btn { min-width: 64px; font-size: .7em; }
  .note-body { flex-direction: column; }
  .note-tools { flex-direction: row; flex-wrap: wrap; }
  .tool-btn { width: auto; flex: 1; }
  .image-grid { grid-template-columns: repeat(2, 1fr); }
  .setting-label { width: 100%; }
  .map-side { left: 16px; }
}
