:root {
  --bg: #1b1f27;
  --panel: #262b36;
  --panel-2: #2f3644;
  --line: #3a4252;
  --text: #e7ebf3;
  --muted: #9aa4b6;
  --accent: #ffb454;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text); background: var(--bg);
  user-select: none; -webkit-user-select: none;
}

#toolbar {
  position: fixed; top: 0; left: 0; right: 0; height: 60px; z-index: 10;
  display: flex; align-items: center; gap: 10px; padding: 0 10px 8px;
  background: linear-gradient(180deg, #2b313d, #232833);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
  overflow-x: auto; overflow-y: hidden; white-space: nowrap;
}
.group { display: flex; align-items: center; gap: 6px; padding-right: 10px; border-right: 1px solid var(--line); height: 34px; }
.group:last-child { border-right: none; }
.group.grow { flex: 1; border: none; }
.brand { font-weight: 700; letter-spacing: .3px; color: var(--accent); font-size: 16px; }

button.tool {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center;
  min-width: 46px; height: 40px; gap: 1px; padding: 3px 6px;
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; font-size: 15px; line-height: 1;
}
button.tool span { font-size: 9.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
button.tool:hover { background: var(--panel-2); }
button.tool.active { background: var(--accent); color: #1b1f27; border-color: var(--accent); }
button.tool.active span { color: #1b1f27; }

button.minor {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 7px; padding: 7px 10px; cursor: pointer; font-size: 12px;
}
button.minor:hover { background: var(--panel-2); }

label { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
select, input[type="text"] {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 5px 6px; font-size: 12px;
}
input[type="range"] { width: 90px; accent-color: var(--accent); }

.swatches { position: relative; }
.swatches .dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff3; display: inline-block; }
.swatches input[type="color"] {
  position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer;
}

#board {
  position: fixed; top: 60px; left: 0;
  width: 100vw; height: calc(100vh - 60px);
  display: block; cursor: crosshair; touch-action: none;
}

#hint {
  position: fixed; left: 50%; bottom: 12px; transform: translateX(-50%);
  background: rgba(20,23,30,.82); color: var(--muted); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: 20px; font-size: 12px; z-index: 5; pointer-events: none;
  backdrop-filter: blur(4px); max-width: 92vw; overflow: hidden; text-overflow: ellipsis;
}
#hint b { color: var(--text); font-weight: 600; }

#status {
  position: fixed; right: 12px; bottom: 12px; z-index: 6;
  background: rgba(20,23,30,.82); border: 1px solid var(--line);
  padding: 5px 10px; border-radius: 8px; font-size: 12px; color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* floating player roster (upper-right, below the toolbar) */
#roster {
  position: fixed; top: 68px; right: 10px; z-index: 8;
  display: flex; flex-direction: column; align-items: flex-end; gap: 5px;
  pointer-events: none;
}
.roster-title { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
#players { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text);
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 3px 8px;
  pointer-events: auto; box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.chip i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.chip.me { border-color: var(--accent); }
.chip.mine { cursor: pointer; }
.chip.mine:hover { background: var(--panel-2); }
.chip .edit { margin-left: 2px; }
.chip.needs-name {
  border-color: var(--accent); color: var(--accent); cursor: pointer;
  animation: chipblink 1.1s ease-in-out infinite;
}
@keyframes chipblink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

button.minor:disabled { opacity: .4; cursor: default; }

/* map save/load dialog */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 12, 16, .6); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
}
.modal-backdrop.hidden { display: none; }
.modal {
  width: min(480px, 92vw); max-height: 80vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .6); overflow: hidden;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  font-weight: 700; color: var(--accent); font-size: 15px;
}
.modal-x { background: none; border: none; color: var(--muted); font-size: 16px; cursor: pointer; padding: 4px 7px; border-radius: 6px; }
.modal-x:hover { background: var(--panel-2); color: var(--text); }
.save-row { display: flex; gap: 8px; padding: 12px 14px; }
.save-row input { flex: 1; }
.modal-sub { padding: 2px 14px 4px; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.map-list { overflow-y: auto; padding: 2px 8px 8px; }
.map-row {
  display: grid; grid-template-columns: 1fr auto auto auto; align-items: center; gap: 10px;
  padding: 8px; border-radius: 8px;
}
.map-row:hover { background: var(--panel-2); }
.map-name { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-date { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.map-del { color: #ff9a9a; }
.modal-empty { padding: 6px 14px 16px; color: var(--muted); font-size: 13px; }

/* login */
.modal.login { width: min(340px, 92vw); }
.modal.login form { display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.modal.login input {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 10px 12px; font-size: 14px;
}
.modal.login input:focus { outline: none; border-color: var(--accent); }
.login-hint { font-size: 12px; color: var(--muted); font-style: italic; }
.login-err { font-size: 12px; color: #ff9a9a; min-height: 15px; }
.login-go {
  background: var(--accent); color: #1b1f27; font-weight: 700; border: none;
  border-radius: 8px; padding: 10px; font-size: 14px; cursor: pointer;
}
.login-go:hover { filter: brightness(1.08); }

/* inline on-canvas text editing */
.canvas-text-input {
  position: fixed; z-index: 20; min-width: 60px;
  background: rgba(15, 18, 24, .25); border: 1px dashed rgba(255, 255, 255, .45);
  border-radius: 3px; outline: none; padding: 2px 3px;
}

/* contextual option groups toggle visibility */
.group.hidden { display: none; }

/* token split-button + shape menu */
.split { position: relative; display: inline-flex; align-items: stretch; }
.split .tool { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.split-caret {
  width: 18px; border: 1px solid var(--line); border-left: none; border-radius: 0 8px 8px 0;
  background: var(--panel); color: var(--muted); cursor: pointer; font-size: 10px;
}
.split-caret:hover { background: var(--panel-2); color: var(--text); }
.tool .ticon { display: inline-flex; align-items: center; justify-content: center; }
.menu {
  position: fixed; z-index: 40;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px; display: grid; grid-template-columns: repeat(6, 34px); gap: 5px;
  max-height: 62vh; overflow-y: auto; box-shadow: 0 10px 26px rgba(0,0,0,.55);
}
.menu.hidden { display: none; }
.menu .sec { grid-column: 1 / -1; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin: 4px 2px 0; }
.shape-btn {
  width: 34px; height: 34px; display: flex; align-items: center; justify-content: center;
  padding: 0; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer;
}
.shape-btn:hover { border-color: var(--accent); }
.shape-btn.active { background: var(--accent); color: #1b1f27; border-color: var(--accent); }

/* preset color swatches */
.swatch-strip { display: grid; grid-template-columns: repeat(6, 15px); gap: 3px; }
.swatch {
  width: 15px; height: 15px; border-radius: 4px; padding: 0; cursor: pointer;
  border: 1px solid rgba(255,255,255,.18);
}
.swatch:hover { border-color: #fff; }
.swatch.active { outline: 2px solid #fff; outline-offset: 1px; }

/* colour pop-over trigger + menu */
.color-btn {
  display: inline-flex; align-items: center; gap: 4px; height: 40px; padding: 0 8px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.color-btn:hover { background: var(--panel-2); }
.color-btn .dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #fff3; display: inline-block; }
.color-btn .mini-caret { font-size: 10px; color: var(--muted); }
.color-menu { display: block; padding: 10px; }
.color-menu .swatch-strip { grid-template-columns: repeat(6, 22px); gap: 6px; }
.color-menu .swatch { width: 22px; height: 22px; border-radius: 5px; }
.custom-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; font-size: 12px; color: var(--muted); }

/* clear dropdown */
.clear-menu { display: flex; flex-direction: column; gap: 2px; padding: 6px; min-width: 150px; }
.menu-item {
  text-align: left; background: none; border: none; color: var(--text);
  padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 12px;
}
.menu-item:hover { background: var(--panel-2); }
.menu-item.danger { color: #ff9a9a; }
.menu-item.danger:hover { background: rgba(255,80,80,.14); }

button.minor.active { background: var(--accent); color: #1b1f27; border-color: var(--accent); }
