/* RainbowHub - CI theme (see ../CI/AGENTS.md). Components use tokens only.
   The user's color (app.js applyColor) overrides the tokens on <html>. */

:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --panel-2: #f7f4ee;
  --border: #e3ddd1;
  --shadow: 0 1px 2px rgba(40, 28, 15, .06), 0 4px 16px rgba(40, 28, 15, .06);
  --text: #241d16;
  --muted: #7a6f62;
  --accent: #e0662f;
  --accent-ink: #ffffff;
  --tone: #2aa594;
  --tone-ink: #ffffff;
  --focus: #2f6fd6;
  --danger: #a33b5c;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16130f;
    --panel: #201c17;
    --panel-2: #29241e;
    --border: #3a332b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    --text: #f1ebe2;
    --muted: #a99d8f;
    --accent: #f07a42;
    --accent-ink: #ffffff;
    --tone: #36bfac;
    --tone-ink: #06231f;
    --focus: #7aa7ff;
    --danger: #f08aa9;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #16130f;
  --panel: #201c17;
  --panel-2: #29241e;
  --border: #3a332b;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  --text: #f1ebe2;
  --muted: #a99d8f;
  --accent: #f07a42;
  --accent-ink: #ffffff;
  --tone: #36bfac;
  --tone-ink: #06231f;
  --focus: #7aa7ff;
  --danger: #f08aa9;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[hidden] { display: none !important; }
h1 { margin: 0; font-size: clamp(28px, 5vw, 38px); letter-spacing: -.03em; }
h2 { margin: 0; font-size: 19px; }
p { margin: 0; }
.muted { color: var(--muted); }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Components ---------- */
.panel {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.btn {
  display: inline-block;
  font: inherit;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .4; cursor: default; }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.grow { flex: 1 1 200px; }
.label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
input[type="text"], select {
  font: inherit;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  width: 100%;
}
input[type="file"] { font: inherit; color: var(--text); max-width: 100%; }
.check { display: flex; align-items: center; gap: 6px; padding-bottom: 8px; white-space: nowrap; }
.msg { margin: 0; color: var(--muted); font-size: 14px; }
.msg.error { color: var(--danger); font-weight: 600; }
.row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; margin: 14px 0 8px; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- Pages ---------- */
.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card-login { padding: 28px; display: grid; gap: 14px; max-width: 420px; text-align: center; justify-items: center; }

.userbar {
  position: fixed; top: 10px; right: 16px; z-index: 5;
  display: flex; align-items: center; gap: 10px; font-size: 13px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 6px 4px 14px; box-shadow: var(--shadow);
}

#hub {
  position: relative; min-height: 100vh; min-width: 100%; outline-offset: -2px; touch-action: pan-x pan-y;
  user-select: none; -webkit-user-select: none;
}
/* Selection rectangle (drag on the empty background) and marked tiles */
.marquee { position: absolute; z-index: 8; pointer-events: none; border: 1px solid var(--accent); }
.marquee::before { content: ""; position: absolute; inset: 0; background: var(--accent); opacity: .18; }
.tile.selected .tile-card { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent), var(--shadow); }
.hint {
  position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none;
  color: var(--muted); font-size: 18px;
}
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 30;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 14px; box-shadow: var(--shadow);
}

/* ---------- Tiles ---------- */
/* --z = tile size / 100 (set on #hub by app.js); sizes scale with it */
#hub { --z: 1; }
.tile {
  position: absolute; width: calc(112px * var(--z)); display: flex; flex-direction: column; align-items: center;
  gap: calc(6px * var(--z)); cursor: pointer; user-select: none; -webkit-user-select: none; touch-action: none;
  border-radius: 14px; outline-offset: 2px;
}
.tile-card {
  width: calc(96px * var(--z)); height: calc(96px * var(--z)); padding: calc(14px * var(--z));
  background: var(--panel); border: 1px solid var(--border); border-radius: calc(18px * var(--z));
  box-shadow: var(--shadow); display: grid; place-items: center;
}
.tile:hover .tile-card, .tile:focus-visible .tile-card { border-color: var(--accent); }
.tile-card img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; -webkit-user-drag: none; }
.tile-name {
  max-width: calc(112px * var(--z)); text-align: center; font-size: max(11px, calc(13px * var(--z)));
  font-weight: 600; line-height: 1.25;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}
.tile.dragging { z-index: 10; cursor: grabbing; }
.tile.dragging .tile-card { box-shadow: 0 8px 28px rgba(0, 0, 0, .28); border-color: var(--accent); }

/* ---------- Context menu ---------- */
.menu { position: fixed; z-index: 20; list-style: none; margin: 0; padding: 6px; min-width: 170px; }
.menu li { padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; }
.menu li:hover, .menu li:focus { background: var(--panel-2); outline: none; box-shadow: inset 0 0 0 1px var(--accent); }

/* ---------- Dialogs ---------- */
dialog.panel { padding: 22px; width: min(440px, calc(100vw - 32px)); margin: auto; }
dialog.panel.wide { width: min(720px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .4); }
#tile-form { display: grid; gap: 14px; }
.icon-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.preview { width: 56px; height: 56px; object-fit: contain; border: 1px solid var(--border); border-radius: 10px; padding: 6px; background: var(--panel-2); }

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; margin-top: 12px; }
.swatch {
  height: 40px; border-radius: 9px; border: 2px solid transparent; font: inherit; font-size: 12px;
  font-weight: 700; cursor: pointer;
}
.swatch[aria-pressed="true"] { border-color: var(--text); box-shadow: 0 0 0 2px var(--panel) inset; }

.table-wrap { overflow-x: auto; margin-top: 10px; }
table.users { width: 100%; border-collapse: collapse; font-size: 14px; }
.users th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 6px 8px; }
.users td { padding: 6px 8px; border-top: 1px solid var(--border); vertical-align: middle; }

/* ---------- Overlay (tile page inside the hub) ---------- */
.overlay { position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; background: var(--bg); }
.overlay-bar {
  flex: 0 0 auto; display: flex; align-items: center; gap: 12px; padding: 6px 12px;
  background: var(--panel); border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
}
.overlay-title { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.overlay iframe { flex: 1; width: 100%; border: 0; background: #fff; }
body.has-overlay { overflow: hidden; }
.small-fab { width: 40px; height: 40px; flex: 0 0 auto; text-decoration: none; }

/* ---------- Admin button ---------- */
/* Round buttons, bottom right: [user management (admins)] [smaller] [bigger] */
.fabs { position: fixed; right: 20px; bottom: 20px; z-index: 6; display: flex; gap: 10px; }
.fab {
  width: 48px; height: 48px; border-radius: 50%; padding: 0;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; cursor: pointer; box-shadow: var(--shadow);
}
.fab:hover { filter: brightness(1.08); }
.fab:disabled { opacity: .4; cursor: default; filter: none; }

@media (max-width: 600px) {
  dialog.panel { padding: 16px; }
  .userbar { right: 8px; }
}
