:root {
  --bg: #16181d;
  --bg-2: #1e2128;
  --surface: #23262e;
  --surface-2: #2b2f39;
  --border: #383d49;
  --text: #e6e1d6;
  --muted: #9a958a;
  --accent: #e8c170;
  --accent-2: #c99a3e;
  --danger: #e0705f;
  --ok: #7cc47c;
  --gm: #e07a6a;
  --player: #6fa8d6;
  --shared: #8fd18f;
  --radius: 8px;
  /* Keep in sync with EMOJI_FONTS in js/fonts.js: the OS emoji font first, so emoji look the same everywhere. */
  --emoji-fonts: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", "Twemoji Mozilla", "EmojiOne Color", "Android Emoji", "Segoe UI Symbol";
  --font: system-ui, -apple-system, "Segoe UI", Roboto, var(--emoji-fonts), sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; font-weight: 650; }
h1 { font-size: 1.7rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: .95rem; }
p { margin: 0 0 .75em; }
.muted { color: var(--muted); }
.small { font-size: .85em; }
.center { text-align: center; }
.pre { white-space: pre-wrap; }
.grow { flex: 1; min-width: 0; }
.error { color: var(--danger); }
.notice { background: rgba(232, 193, 112, .12); border: 1px solid rgba(232, 193, 112, .35); padding: .6em .8em; border-radius: var(--radius); }
.loading, .empty { padding: 3rem 1rem; text-align: center; color: var(--muted); }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
[hidden] { display: none !important; }

/* ---------- form controls ---------- */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 6px; padding: .45em .6em; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=color] { padding: 2px; height: 2.2em; }
input[type=range] { padding: 0; accent-color: var(--accent); }
.field { display: block; margin-bottom: .8em; }
.field > span { display: block; font-size: .85em; color: var(--muted); margin-bottom: .25em; }
.check { display: flex; gap: .5em; align-items: center; font-size: .9em; margin: .35em 0; cursor: pointer; }
.inline { display: flex; gap: .5em; }
.inline select { width: auto; }

.btn {
  font: inherit; font-size: .9em; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 6px; padding: .45em .9em; cursor: pointer;
  display: inline-flex; align-items: center; gap: .3em; white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: #1b1a17; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #f0cf8a; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.link { background: none; border: none; color: var(--accent); padding: .3em .4em; }
.btn.small { font-size: .8em; padding: .3em .6em; }
.btn.icon { padding: .2em .5em; min-width: 2em; justify-content: center; }
.btn.wide { width: 100%; justify-content: center; padding: .65em; }

.badge { display: inline-block; font-size: .72em; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; padding: .15em .55em; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); }
.badge.role-admin { color: #c7a0ff; border-color: #6d5a94; }
.badge.role-gm { color: var(--gm); border-color: #87483f; }
.badge.role-player { color: var(--player); border-color: #3f6487; }
.badge.hidden-badge { color: var(--muted); text-transform: none; }
.role-switch { width: auto; font-size: .85em; padding: .3em .5em; }

/* ---------- layout ---------- */
.topnav { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.25rem; background: var(--bg-2); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: .5em; font-weight: 700; font-size: 1.1rem; color: var(--text); }
.brand img { width: 26px; height: 26px; }
.topnav nav { margin-left: auto; display: flex; gap: 1.1rem; align-items: center; }
.topnav nav a { color: var(--text); }
.page { max-width: 1150px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.head-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.breadcrumbs { font-size: .85em; color: var(--muted); margin-bottom: .5rem; }
.section-title { margin-top: 2rem; color: var(--muted); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1.25rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1.25rem; align-items: start; }
.columns > .card { margin-bottom: 0; }
.columns + * { margin-top: 1.25rem; }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.section-head h2 { margin: 0; }

.campaign-card { color: var(--text); display: block; margin: 0; transition: border-color .15s; }
.campaign-card:hover { border-color: var(--accent-2); text-decoration: none; }
.card-head { display: flex; justify-content: space-between; gap: .5rem; align-items: start; }

.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; align-items: center; gap: .5rem; padding: .55rem 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.list-row:first-child { border-top: none; }
.row-actions { display: flex; gap: .35rem; }
.role-chip { display: inline-flex; align-items: center; gap: 2px; }
.chip-x { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 1.05em; padding: 0 .2em; }
.chip-x:hover { color: var(--danger); }
.add-member { margin-top: .75rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.search-results { list-style: none; padding: 0; margin: .5rem 0 0; }
.search-results li { display: flex; align-items: center; gap: .5rem; padding: .3rem 0; }

.types .type-row { display: flex; gap: .35rem; align-items: center; padding: .25rem 0; }
.types .swatch { width: 2.4em; flex: none; }
.types .icon-input { width: 3.2em; flex: none; text-align: center; padding: .4em .2em; }
.subhead { margin: .8rem 0 .1rem; font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.types .style-select { width: auto; flex: none; font-size: .85em; padding: .35em .3em; }
.types .width-input { width: 3.6em; flex: none; padding: .35em .3em; }
.danger-zone { border-color: #6b3a33; margin-top: 1.25rem; }

.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
.auth-card { width: 100%; max-width: 380px; padding: 1.75rem; }
.auth-brand { display: flex; align-items: center; gap: .6rem; justify-content: center; margin-bottom: 1.25rem; }
.auth-brand img { width: 40px; }
.auth-brand h1 { margin: 0; }

.table-wrap { overflow-x: auto; padding: 0; }
table.users { width: 100%; border-collapse: collapse; }
table.users th, table.users td { text-align: left; padding: .6rem .9rem; border-top: 1px solid var(--border); }
table.users th { border-top: none; font-size: .8em; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
td.num { text-align: right; }
.toggle { display: flex; gap: .4em; align-items: center; }

/* ---------- dialogs & toasts ---------- */
dialog.modal { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 0; width: min(440px, calc(100vw - 2rem)); }
dialog.modal::backdrop { background: rgba(0, 0, 0, .6); }
.dialog-body { padding: 1.4rem; }
.dialog-body .actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
#toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; z-index: 1000; pointer-events: none; }
.toast { background: var(--surface-2); border: 1px solid var(--border); padding: .6rem 1rem; border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0, 0, 0, .4); transition: opacity .5s; max-width: 90vw; }
.toast.error { border-color: var(--danger); }
.toast.fade { opacity: 0; }

/* ---------- map editor ---------- */
main.fullscreen { height: 100vh; overflow: hidden; }
.map-shell { display: flex; flex-direction: column; height: 100%; }
.map-top { display: flex; align-items: center; gap: .6rem; padding: .45rem .8rem; background: var(--bg-2); border-bottom: 1px solid var(--border); }
.map-title { font-size: 1.05rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); flex: none; }
.conn.on { background: var(--ok); }
.map-body { flex: 1; display: flex; min-height: 0; }
.canvas-wrap { flex: 1; position: relative; min-width: 0; }
.map-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; cursor: crosshair; }
.map-canvas[data-tool=select] { cursor: default; }
.map-shell.player .map-canvas { cursor: default; }
.map-canvas.pan-ready { cursor: grab; }
.map-canvas.panning { cursor: grabbing; }
.hud { position: absolute; left: .6rem; bottom: .5rem; font: 12px ui-monospace, monospace; color: var(--muted); background: rgba(0, 0, 0, .45); padding: .15rem .5rem; border-radius: 4px; pointer-events: none; }
.hud:empty { display: none; }

.toolbox { width: 230px; flex: none; display: flex; flex-direction: column; min-height: 0; background: var(--bg-2); border-right: 1px solid var(--border); }
.toolbox-body { flex: 1; min-height: 0; overflow-y: auto; padding: .7rem; }
.toolbox-foot { flex: none; padding: .35rem .7rem; border-top: 1px solid var(--border); }
/* Collapse / expand the GM toolbox */
.tools-toggle { width: 1.9rem; height: 1.9rem; display: inline-flex; align-items: center; justify-content: center; padding: 0 0 .15rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; color: var(--muted); font: 1.25rem/1 system-ui, sans-serif; cursor: pointer; }
.tools-toggle:hover, .tools-toggle:focus-visible { color: var(--text); border-color: var(--muted); }
.tools-show { position: absolute; left: .6rem; bottom: .5rem; z-index: 3; display: none; box-shadow: 0 2px 8px rgba(0, 0, 0, .4); }
.map-shell.tools-hidden .toolbox { display: none; }
.map-shell.tools-hidden .tools-show { display: inline-flex; }
.map-shell.tools-hidden .hud { left: 3rem; bottom: .9rem; }
.tool-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem; }
.tool { display: flex; flex-direction: column; align-items: center; gap: .1rem; padding: .45rem .2rem; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; color: var(--text); cursor: pointer; font: inherit; }
.tool:hover { border-color: var(--muted); }
.tool.active { border-color: var(--accent); background: rgba(232, 193, 112, .12); }
.tool-icon { font-size: 1.25rem; }
.tool-label { font-size: .75em; }
.tool-help { font-size: .8em; color: var(--muted); margin: .6rem 0; }
.brush { margin: .4rem 0 .8rem; }
.palette { display: flex; flex-direction: column; gap: 2px; margin-bottom: .8rem; }
.swatch-btn { display: flex; align-items: center; gap: .5rem; padding: .25rem .35rem; background: none; border: 1px solid transparent; border-radius: 6px; color: var(--text); cursor: pointer; font: inherit; font-size: .88em; text-align: left; }
.swatch-btn:hover { background: var(--surface); }
.swatch-btn.active { border-color: var(--accent); background: rgba(232, 193, 112, .1); }
.swatch { width: 26px; height: 22px; border-radius: 4px; border: 1px solid rgba(0, 0, 0, .4); display: inline-grid; place-items: center; font-size: 13px; flex: none; clip-path: polygon(25% 0, 75% 0, 100% 50%, 75% 100%, 25% 100%, 0 50%); }
.swatch.marker { background: var(--surface-2); clip-path: none; border-radius: 50%; width: 24px; height: 24px; font-size: 14px; }
.mode-toggle { display: flex; gap: .35rem; align-items: center; margin: .2rem 0 .6rem; }
.mode-toggle .btn.active { border-color: var(--accent); background: rgba(232, 193, 112, .12); }
.line-sample { display: inline-block; width: 26px; height: 0; flex: none; vertical-align: middle; position: relative; }
.line-sample.cliff::after { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 6px;
  background: linear-gradient(135deg, var(--c) 25%, transparent 25%) 0 0 / 6px 6px repeat-x,
              linear-gradient(225deg, var(--c) 25%, transparent 25%) 0 0 / 6px 6px repeat-x; }
.swatch-btn .line-sample { margin: 0 2px; }
.hex-lines { display: flex; align-items: center; gap: .5rem; margin-top: .4rem; }
.hex-lines:empty { display: none; }
.tool-options { border-top: 1px solid var(--border); padding-top: .5rem; margin-top: .3rem; }
.undo-row { display: flex; gap: .35rem; margin: .6rem 0; }
.legend { margin-top: .6rem; }

.panel { width: 360px; flex: none; overflow-y: auto; background: var(--bg-2); border-left: 1px solid var(--border); }
.panel-section { padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
.panel-section:last-child { border-bottom: none; }
.hex-title { display: flex; justify-content: space-between; align-items: start; gap: .5rem; }
.hex-title h2 { margin: 0; word-break: break-word; }
.hex-head p { margin: .2rem 0 0; }
.hex-title .panel-mode { flex: none; margin-top: .15rem; }
/* GM hex summary: visibility toggle pills and a quick action, in one row */
.quick-row { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .5rem; }
.pill { border: 1px solid var(--border); background: transparent; color: inherit; font: inherit; font-size: .78rem;
  padding: .15rem .6rem; border-radius: 999px; cursor: pointer; line-height: 1.4; }
.pill:hover { border-color: var(--muted); }
.pill.off { color: #ff8a7a; border-color: rgba(255, 138, 122, .55); background: rgba(255, 138, 122, .08); }
.pill.action { color: var(--muted); border-style: dashed; }
.hidden-tag { color: #ff8a7a; }
.hex-fields .field { margin-bottom: .55rem; }
.hex-fields .btn { margin-top: .5rem; }
.places { list-style: none; margin: .5rem 0 0; padding: 0; max-height: 45vh; overflow-y: auto; }
.place { display: flex; align-items: center; gap: .5rem; width: 100%; background: none; border: none; color: var(--text); padding: .35rem .3rem; border-radius: 5px; cursor: pointer; font: inherit; font-size: .9em; text-align: left; }
.place:hover { background: var(--surface); }
.place-icon { width: 1.4em; text-align: center; }
.legend-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: .3rem; font-size: .85em; }
.legend-list li { display: flex; align-items: center; gap: .4rem; }

/* notes */
.notes { margin-bottom: 1rem; border-left: 3px solid var(--border); padding-left: .6rem; }
/* An empty section is tagged .empty, which must not pick up the page-wide .empty placeholder style */
.notes.empty { padding: 0 0 0 .6rem; text-align: left; color: inherit; }
.notes.gm { border-color: var(--gm); }
.notes.player { border-color: var(--player); }
.notes.shared { border-color: var(--shared); }
.notes-head { position: relative; display: flex; justify-content: space-between; align-items: baseline; }
.notes-head h3 { margin: 0; }
.notes.gm h3 { color: var(--gm); }
.notes.player h3 { color: var(--player); }
.notes.shared h3 { color: var(--shared); }
.notes-head .btn { padding: .15em .7em; }
/* A tiny (i) beside a heading; its text shows on hover, or on focus (keyboard or tap) */
.info-tip { display: inline-flex; align-items: center; justify-content: center; width: 1.2em; height: 1.2em; margin-left: .4em;
  border: 1px solid currentColor; border-radius: 50%; font: italic 600 .72rem/1 Georgia, serif; vertical-align: .2em; opacity: .55; cursor: help; outline: none; }
.info-tip:hover, .info-tip:focus-visible, .info-tip:focus { opacity: 1; }
.info-tip::after { content: attr(data-tip); position: absolute; left: 0; top: calc(100% + .3rem); z-index: 6; width: max-content; max-width: 100%;
  padding: .35rem .55rem; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; box-shadow: 0 4px 14px rgba(0, 0, 0, .5);
  font: 400 .8rem/1.35 system-ui, sans-serif; text-align: left; white-space: normal; opacity: 0; visibility: hidden; transition: opacity .12s; pointer-events: none; }
.info-tip:hover::after, .info-tip:focus::after { opacity: 1; visibility: visible; }
.notes-footer { font-size: .78em; color: var(--muted); margin: .1rem 0 .35rem; }
.notes-footer { margin-top: .3rem; }
/* read-only display in the side panel */
.notes-content { cursor: default; }
.notes-content .ql-editor.notes-body { padding: .15rem 0; font-size: .92em; line-height: 1.55; white-space: normal; overflow: visible; height: auto; }
.notes.empty .notes-body::after { content: 'Nothing recorded yet.'; color: var(--muted); font-style: italic; }
.notes-body p { margin: 0 0 .35em; }

/* editor window */
dialog.notes-modal { width: min(920px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); }
.notes-modal-head { display: flex; align-items: baseline; gap: .75rem; flex-wrap: wrap; margin-bottom: .6rem; }
.notes-modal-head h2 { margin: 0; }
.notes-modal.gm .notes-modal-head h2 { color: var(--gm); }
.notes-modal.player .notes-modal-head h2 { color: var(--player); }
.notes-modal.shared .notes-modal-head h2 { color: var(--shared); }
.editor-frame { display: flex; flex-direction: column; height: 55vh; min-height: 200px; max-height: 80vh; resize: vertical; overflow: hidden; }
.editor-frame .ql-toolbar.ql-snow { flex: none; border-color: var(--border); background: var(--surface-2); border-radius: 6px 6px 0 0; }
.editor-frame .ql-container.ql-snow { flex: 1; min-height: 0; border-color: var(--border); background: var(--bg); border-radius: 0 0 6px 6px; font: inherit; font-size: 1rem; }
.editor-frame .ql-editor { line-height: 1.6; }
.editor-frame .ql-editor.ql-blank::before { color: var(--muted); font-style: normal; }
.drag-hint { margin: .35rem 0 0; text-align: right; }
.notes-modal .actions, .confirm-row { display: flex; align-items: center; gap: .5rem; margin-top: .75rem; }
.conflict { display: flex; align-items: center; gap: .75rem; background: rgba(224, 112, 95, .12); border: 1px solid #87483f; border-radius: 6px; padding: .5rem .75rem; margin-bottom: .6rem; font-size: .9em; }
.ql-snow .ql-stroke { stroke: var(--text); }
.ql-snow .ql-fill { fill: var(--text); }
.ql-snow .ql-picker { color: var(--text); }
.ql-snow .ql-picker-options { background: var(--surface-2); border-color: var(--border) !important; }
.ql-snow button:hover .ql-stroke, .ql-snow .ql-active .ql-stroke { stroke: var(--accent) !important; }
.ql-snow button:hover .ql-fill, .ql-snow .ql-active .ql-fill { fill: var(--accent) !important; }
.ql-snow .ql-picker-label:hover, .ql-snow .ql-picker-item:hover, .ql-snow .ql-active { color: var(--accent) !important; }
.ql-snow .ql-tooltip { background: var(--surface-2); color: var(--text); border-color: var(--border); box-shadow: 0 4px 14px rgba(0, 0, 0, .5); z-index: 5; }
.ql-snow .ql-tooltip input[type=text] { background: var(--bg); color: var(--text); border-color: var(--border); }
.ql-snow a { color: var(--accent); }

@media (max-width: 900px) {
  .toolbox { width: 170px; }
  .tool-label { display: none; }
  .panel { width: 300px; }
}
@media (max-width: 680px) {
  .map-body { flex-direction: column; }
  .toolbox { width: auto; border-right: none; border-bottom: 1px solid var(--border); max-height: 30vh; }
  .tool-grid { grid-template-columns: repeat(6, 1fr); }
  .canvas-wrap { min-height: 45vh; }
  .panel { width: auto; border-left: none; border-top: 1px solid var(--border); max-height: 35vh; }
  .topnav nav { gap: .7rem; font-size: .9em; }
}

/* tokens */
.token-chip { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; border: 2px solid #f4efe4; font-size: 16px; flex: none; box-shadow: 0 1px 3px rgba(0, 0, 0, .5); }
.token-chip.small { width: 22px; height: 22px; font-size: 12px; border-width: 1.5px; }
.hex-title .token-chip { margin-right: .5rem; align-self: center; }
.hex-title h2 { flex: 1; }
.token-row { align-items: center; margin-bottom: .6rem; }
.token-row .swatch { width: 2.4em; flex: none; }
.token-row .icon-input { width: 3.2em; flex: none; text-align: center; }
.btn-row { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .6rem; }
.btn-row .btn { margin-top: 0; }
.panel .section-head h3 { margin: 0; }
.map-canvas.over-token { cursor: grab; }
.map-canvas.dragging-token { cursor: grabbing; }

/* map labels */
.label-preview { background: #e9e2cf; border-radius: 6px; padding: .5rem .7rem; text-align: center; font-size: 1.05rem; line-height: 1.3; max-height: 30vh; overflow: auto; }
.label-preview p { margin: 0; }
.size-row { align-items: center; }
.size-row input[type=range] { flex: 1; min-width: 0; }
.size-row input[type=number] { width: 4.5em; flex: none; }
.label-style { gap: .75rem; align-items: flex-end; }
.label-style .swatch { width: 3em; }
.rotation-row { display: flex; gap: 4px; flex-wrap: wrap; margin-top: .25rem; }
.rotation-row .rot { width: 2.6em; height: 2.4em; justify-content: center; padding: 0; }
.rotation-row .rot.active { border-color: var(--accent); background: rgba(232, 193, 112, .15); }
.rot-glyph { display: inline-block; font-family: Georgia, serif; font-size: .85rem; }
.notes-modal.label .notes-modal-head h2 { color: var(--accent); }
.notes-modal.label .editor-frame { height: 30vh; }
.notes-modal.label .ql-editor { font-family: Georgia, serif; font-size: 1.2rem; text-align: center; }

/* emoji picker */
.emoji-field { display: flex; align-items: stretch; gap: 3px; flex: none; }
.field .emoji-field { flex: 1; }
.field .emoji-field input { flex: 1; }
.emoji-btn { padding: 0 .45em; font-size: 1rem; line-height: 1; }
.emoji-pop { position: fixed; z-index: 2000; width: 360px; max-width: calc(100vw - 16px); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 10px 30px rgba(0, 0, 0, .55); overflow: hidden; display: flex; flex-direction: column; }
/* The popover has a fixed height (set in emoji.js); the active tab fills it and scrolls inside. */
.picker-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.emoji-favs { flex: none; padding: .5rem .6rem .35rem; border-bottom: 1px solid var(--border); }
.emoji-favs-title { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .25rem; }
.emoji-favs-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 1px; }
.emoji-favs-grid button { background: none; border: none; border-radius: 5px; font-size: 1.15rem; line-height: 1.5; padding: 0; cursor: pointer; }
.emoji-favs-grid button:hover, .emoji-favs-grid button:focus-visible { background: var(--surface-2); outline: none; }
emoji-picker {
  width: 100%;
  --emoji-font-family: var(--emoji-fonts), sans-serif;
  flex: 1;
  min-height: 0;
  height: auto;
  --background: var(--surface);
  --border-color: var(--border);
  --button-hover-background: var(--surface-2);
  --button-active-background: #3a3f4b;
  --indicator-color: var(--accent);
  --input-border-color: var(--border);
  --input-font-color: var(--text);
  --input-placeholder-color: var(--muted);
  --outline-color: var(--accent-2);
  --category-font-color: var(--muted);
  --num-columns: 9;
  --emoji-size: 1.35rem;
  --border-size: 0;
}

/* ruler */
.map-top .btn.active { border-color: #ffd65a; background: rgba(255, 214, 90, .15); color: #fff4cf; }
.map-canvas.ruler-mode { cursor: crosshair; }
.ruler-hud { position: absolute; top: .6rem; left: 50%; transform: translateX(-50%); max-width: calc(100% - 1.5rem); background: rgba(20, 22, 28, .9); border: 1px solid #ffd65a; border-radius: 8px; padding: .35rem .8rem; font-size: .85rem; color: #fff4cf; pointer-events: none; text-align: center; box-shadow: 0 4px 14px rgba(0, 0, 0, .4); }
.ruler-hud .muted { color: var(--muted); }

/* admin settings */
.settings-card { padding: .85rem 1.1rem; }
.toggle-row { display: flex; align-items: center; gap: .6rem; cursor: pointer; }
.toggle-row input[type=checkbox] { width: 1.1rem; height: 1.1rem; }
.reg-status { margin: .35rem 0 0 1.7rem; }

/* tileset icons */
.icon-img { display: inline-block; width: 1.2em; height: 1.2em; object-fit: contain; vertical-align: middle; }
.swatch .swatch-icon.icon-img { width: 16px; height: 16px; }
.swatch.marker .swatch-icon.icon-img { width: 18px; height: 18px; }
.token-chip .chip-icon.icon-img { width: 70%; height: 70%; }
.place-icon .list-icon.icon-img { width: 1.15em; height: 1.15em; }
.icon-preview { padding: 0 .35em; min-width: 3.2em; justify-content: center; }
.icon-preview .preview-img { width: 1.5em; height: 1.5em; }
.field .emoji-field .icon-preview { flex: 1; justify-content: flex-start; }
.dialog-msg { white-space: pre-line; max-height: 50vh; overflow: auto; }

/* icon picker tabs + tileset grid */
.picker-tabs { display: flex; border-bottom: 1px solid var(--border); }
.picker-tab { flex: 1; background: none; border: none; color: var(--muted); padding: .5rem; cursor: pointer; font: inherit; font-size: .85rem; font-weight: 600; border-bottom: 2px solid transparent; }
.picker-tab:hover { color: var(--text); }
.picker-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.picker-msg { padding: 1rem; color: var(--muted); font-size: .9rem; margin: 0; }
.picker-toolbar { flex: none; display: flex; gap: .4rem; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
.picker-toolbar select { width: auto; max-width: 45%; font-size: .85rem; padding: .3rem .4rem; }
.picker-toolbar input { font-size: .85rem; padding: .3rem .5rem; }
.tileset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 2px; padding: .4rem .5rem .6rem; flex: 1; min-height: 0; overflow-y: auto; align-content: start; }
.tileset-cat { grid-column: 1 / -1; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: .45rem .1rem .1rem; }
.tileset-cat:first-child { margin-top: .1rem; }
.tileset-icon { display: grid; place-items: center; aspect-ratio: 1; background: none; border: 1px solid transparent; border-radius: 6px; padding: 3px; cursor: pointer; }
.tileset-icon:hover, .tileset-icon:focus-visible { background: var(--surface-2); outline: none; }
.tileset-icon.active { border-color: var(--accent); }
.tileset-icon .tileset-img { width: 100%; height: 100%; }

/* tilesets admin page */
.upload-row { align-items: center; margin-top: .5rem; }
.upload-row input { max-width: 320px; }
.tileset-list .section-head { align-items: flex-start; flex-wrap: wrap; }
.tileset-list h2 { margin: 0 0 .15rem; }
.tileset-details summary { cursor: pointer; color: var(--accent); font-size: .9rem; margin-top: .4rem; }
.tileset-preview { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px; margin-top: .6rem; max-height: 50vh; overflow-y: auto; background: var(--bg-2); border-radius: 6px; padding: .5rem; }
.tileset-preview .tileset-icon { cursor: default; }

/* Map settings page */
.stack-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin: .6rem 0; }
.inline > .field { flex: 1; min-width: 0; }

/* Additional markers in the hex panel */
.extras-list { list-style: none; margin: 0 0 .35rem; padding: 0; }
.extra-row { display: flex; align-items: center; gap: .4rem; padding: .15rem 0; }
.extra-row .check { margin: 0; font-size: .8rem; color: var(--muted); }
.add-extra { font-size: .85rem; }
.also-here { margin: .25rem 0 0; color: var(--muted); }

/* Links in the hex panel: one row per link, the far hex clickable */
.link-list { list-style: none; margin: 0; padding: 0; }
.link-row { display: flex; align-items: center; gap: .45rem; padding: .15rem 0; min-width: 0; }
.link-to { background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; text-align: left;
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-to:hover { text-decoration: underline; }
.link-hex { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.link-main { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.25; }
.link-meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-row .check { margin: 0; font-size: .8rem; color: var(--muted); }
.link-row.is-hidden .link-main { opacity: .6; }
.tool-hint { margin: .2rem 0 .4rem; }
.slot-select { width: 4.2rem; flex: none; font-size: .85rem; padding: .25rem .3rem; }
.type-row > input.grow { min-width: 4rem; flex: 1 1 4rem; }
/* The style picker keeps a fixed width (its longest option, "Cliff (directional)", would push the row's
   delete button out of the card); the full text shows when it's open. */
.types .style-select { width: 7.5em; text-overflow: ellipsis; }

/* Appearance tab: terrain and roads stacked on the left, the wider markers card on the right. */
.appearance-grid { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(0, 1.6fr); gap: 1.25rem; align-items: start; }
.appearance-stack { display: grid; gap: 1.25rem; min-width: 0; }
.appearance-grid .card { margin-bottom: 0; min-width: 0; }
@media (max-width: 900px) { .appearance-grid { grid-template-columns: 1fr; } }

/* Overview panel: the Places list fills whatever height the other sections leave, and scrolls. */
.panel:has(> .places-section) { display: flex; flex-direction: column; }
.panel:has(> .places-section) > .panel-section { flex: none; }
.panel:has(> .places-section) > .places-section { flex: 1 0 14rem; display: flex; flex-direction: column; }
.places-section > .places { flex: 1 1 0; max-height: none; min-height: 0; }

/* Hex grid settings */
.grid-settings .inline > .field input[type=number] { width: 100%; }
.sub-fields { align-items: end; }
.sub-fields .check { margin-bottom: .8em; white-space: nowrap; }
.region-names .region-key { flex: none; min-width: 6.5rem; }
.add-region { align-items: end; }
.add-region .btn { margin-bottom: .8em; }

/* Map settings tabs */
.settings-tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; flex-wrap: wrap; }
.settings-tab { background: none; border: none; border-bottom: 2px solid transparent; margin-bottom: -1px; padding: .6rem 1rem; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.settings-tab:focus-visible { outline: 2px solid var(--accent-2); outline-offset: -2px; }
.single-column { max-width: 46rem; }

/* Additional markers' names: an inline box, blank shows the marker type */
.extra-name { min-width: 0; padding: .15rem .35rem; font-size: .9rem; }
