:root {
  --panel: rgba(20, 24, 20, 0.86);
  --line: rgba(255, 255, 255, 0.12);
  --ink: #f1f4ec;
  --muted: #b3bba9;
  --accent: #c8e07a;
  --accent-ink: #18200a;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #1d2a17;
  color: var(--ink);
  font-family: "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
}

#mat {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: grab;
}

#mat.dragging { cursor: grabbing; }
#mat.measuring { cursor: crosshair; }

#overlay {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---------- Settings panel ---------- */

.panel {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: calc(16px + env(safe-area-inset-left, 0px));
  width: 280px;
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 32px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  padding: 14px 16px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  transition: opacity 0.4s;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 16px;
}

.logo {
  width: 20px;
  height: 20px;
  border-radius: 5px;
  background:
    linear-gradient(90deg, transparent 6px, rgba(255, 255, 255, 0.75) 6px 7.5px, transparent 7.5px 12.5px, rgba(255, 255, 255, 0.75) 12.5px 14px, transparent 14px),
    linear-gradient(transparent 6px, rgba(255, 255, 255, 0.75) 6px 7.5px, transparent 7.5px 12.5px, rgba(255, 255, 255, 0.75) 12.5px 14px, transparent 14px),
    #3c6e2a;
}

.icon-btn {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.icon-btn:hover { background: rgba(255, 255, 255, 0.08); color: var(--ink); }

.group {
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.seg {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.3);
}

.seg + .seg, .seg.small { margin-top: 8px; }

.seg button {
  flex: 1;
  padding: 7px 4px;
  white-space: nowrap;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.seg.small button { padding: 5px 6px; font-size: 13px; }
.seg button[data-value="image"] { flex: 1.25; }
.seg button:hover { color: var(--ink); }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

.row {
  display: flex;
  justify-content: space-between;
  margin: 12px 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.row output { color: var(--ink); font-variant-numeric: tabular-nums; }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.inch {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 2px;
  color: var(--muted);
  font-size: 13px;
}

.inch input {
  width: 58px;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--ink);
  font: inherit;
}

.btn {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn:hover { background: rgba(255, 255, 255, 0.12); }
.btn.small { padding: 5px 9px; font-size: 13px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }

.actions { display: flex; gap: 8px; }

.ruler-top { display: flex; gap: 6px; margin-bottom: 8px; }
.ruler-top .toggle { flex: 1; }
.btn.toggle.on, .fab.on { background: #ffd64a; border-color: #ffd64a; color: #2a2004; }

.inch select {
  padding: 5px 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--ink);
  font: inherit;
}

.fab {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: opacity 0.4s;
}

.fab svg { width: 26px; height: 26px; }

.img-actions { display: flex; gap: 6px; margin-top: 10px; }
.img-actions .btn { flex: 1; }

.note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.drop {
  position: fixed;
  inset: 12px;
  display: grid;
  place-items: center;
  border: 3px dashed var(--accent);
  border-radius: 18px;
  background: rgba(15, 20, 12, 0.6);
  pointer-events: none;
  z-index: 20;
}

.drop p {
  margin: 0;
  padding: 12px 20px;
  border-radius: 12px;
  background: var(--panel);
  font-size: 18px;
  font-weight: 600;
}
.actions .btn { flex: 1; }

.help {
  margin: 4px 0 8px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.back { margin: 0; font-size: 13px; }
.back a { color: var(--muted); text-decoration: none; }
.back a:hover { color: var(--ink); text-decoration: underline; }

button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.show-btn {
  position: fixed;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: calc(16px + env(safe-area-inset-left, 0px));
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: opacity 0.4s;
}

.show-btn svg { width: 22px; height: 22px; }

/* After a few quiet seconds, controls and cursor get out of the way */
body.idle .panel, body.idle .show-btn, body.idle .fab { opacity: 0; pointer-events: none; }
body.idle #mat { cursor: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 8px);
  max-width: calc(100vw - 32px);
  padding: 9px 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

.nogl {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  text-align: center;
}

/* ---------- Scrying Table: tokens and the table ---------- */

.logo { background: radial-gradient(circle at 35% 35%, #e6dcff 0 2px, #7d5fd6 3px 8px, transparent 8.5px) 0 -1px no-repeat, #231a3a; }

.status { margin: 0 0 4px; font-weight: 600; }
.status span::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: 1px;
}
.status span.off::before { background: #e0a43a; }
.table-link { margin: 0 0 2px; color: var(--muted); font-size: 12.5px; word-break: break-all; }

.tokens {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.token {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
}

.token img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.55));
  user-select: none;
  -webkit-user-drag: none;
}

/* Every shown token can be dragged; a click opens its controls or details */
.token { pointer-events: auto; cursor: grab; touch-action: none; }
.token.dragging { cursor: grabbing; }
.token.dragging img { filter: drop-shadow(0 10px 14px rgba(0, 0, 0, 0.6)); }
body.measuring .token { pointer-events: none; }

/* Hidden from the others: shown faded to you, with a dashed ring */
.token.unseen img { opacity: 0.5; }
.token.unseen::after {
  content: "";
  position: absolute;
  inset: -3px;
  border: 2px dashed rgba(230, 220, 255, 0.85);
  border-radius: 8px;
  pointer-events: none;
}
.token.selected::before {
  content: "";
  position: absolute;
  inset: -5px;
  border: 3px solid var(--accent);
  border-radius: 10px;
  pointer-events: none;
}

.tok-eye {
  position: absolute;
  top: -10px;
  right: -10px;
  z-index: 1;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: opacity 0.4s;
}
.tok-eye svg { width: 17px; height: 17px; }
.tok-eye:hover { background: #3b2e63; }
.token.unseen .tok-eye { background: #7d5fd6; border-color: #7d5fd6; color: #fff; }

.token-bar {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 15;
  width: 250px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.token-bar .text-in { margin-bottom: 6px; }
.tb-row { display: flex; align-items: center; gap: 6px; }
.tb-row #tokDelete { margin-left: auto; }
.tb-title { margin: 2px 4px 4px; font-size: 15px; font-weight: 700; overflow-wrap: anywhere; }
.tb-title.muted { color: var(--muted); font-weight: 600; }
.tb-note { margin: 4px 4px 0; color: var(--muted); font-size: 12.5px; }
.token-bar #tokSize { min-width: 52px; text-align: center; font-size: 13px; font-weight: 600; }
.token-bar .btn.small { min-width: 32px; }
.btn.danger { color: #ffb4a8; }
.btn.danger:hover { background: rgba(224, 82, 62, 0.25); }

body.idle .token-bar { opacity: 0; pointer-events: none; }
.panel, .show-btn, .fab { z-index: 10; }
.tokens { z-index: 1; }
#overlay { z-index: 2; }
.toast { z-index: 30; }

.name-row { margin-top: 0; }
.text-in {
  width: 100%;
  margin-bottom: 10px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.3);
  color: var(--ink);
  font: inherit;
}
.text-in:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.people { display: flex; flex-wrap: wrap; gap: 5px; margin: 6px 0 8px; padding: 0; list-style: none; }
.people:empty { display: none; }
.people li { padding: 3px 9px; border-radius: 999px; background: rgba(255, 255, 255, 0.08); font-size: 12.5px; }
.people li.you { background: rgba(125, 95, 214, 0.45); }

/* ---------- Closed (the site is switched off) ---------- */
.closed {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(16, 12, 28, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.closed-card {
  max-width: 440px;
  padding: 26px 28px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #1c1730;
  text-align: center;
  line-height: 1.55;
}
.closed-card h1 { margin: 0 0 10px; font-size: 22px; }
.closed-card p { margin: 0 0 12px; color: var(--muted); }
.closed-card a { color: var(--accent); }
.closed-card .btn { width: 100%; margin-top: 8px; }
.closed-card input { width: 100%; margin-top: 8px; }
.closed-card .when { color: var(--ink); font-weight: 600; font-size: 17px; }
body.page { overflow: auto; background: #120e20; }

/* The token's name, along its bottom edge */
.tok-label {
  position: absolute;
  left: 50%;
  bottom: 0;
  max-width: calc(100% + 40px);
  padding: 1px 7px 2px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(14, 11, 24, 0.82);
  color: #fff;
  font-size: var(--label, 12px);
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  text-overflow: ellipsis;
  transform: translate(-50%, 45%);
  pointer-events: none;
}

/* Who's moving a token, shown to everyone else while they drag it */
.tok-mover {
  position: absolute;
  left: 50%;
  top: 0;
  padding: 2px 8px 3px;
  border-radius: 999px;
  background: #7d5fd6;
  color: #fff;
  font-size: var(--label, 12px);
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  transform: translate(-50%, -115%);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.welcome { z-index: 35; }
.welcome .text-in { margin: 4px 0 0; font-size: 16px; }

/* Admin page */
.admin-section { margin: 18px 0 14px; padding-top: 14px; border-top: 1px solid var(--line); text-align: left; }
.admin-section .label { text-align: center; }
.small-when { font-size: 14px; text-align: center; }
.check { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 6px 0 2px; color: var(--muted); font-size: 13px; cursor: pointer; }
.check input { width: auto; margin: 0; accent-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }
.admin-section .note { text-align: center; }
