:root {
  color-scheme: dark;
  --bg: #111313;
  --panel: #191c1d;
  --panel-2: #202525;
  --line: #313838;
  --text: #eef1ef;
  --muted: #9ba6a4;
  --accent: #b1c301;
  --accent-2: #7fb6a6;
  --danger: #d66a5f;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  min-height: 36px;
  padding: 0 12px;
}

button:hover {
  border-color: #52605e;
}

.start-screen {
  align-items: center;
  background: #06021c;
  display: flex;
  inset: 0;
  justify-content: center;
  opacity: 1;
  position: fixed;
  transition: opacity 0.45s ease;
  z-index: 100;
}

.start-screen.hidden {
  opacity: 0;
  pointer-events: none;
}

.start-inner {
  align-items: center;
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 32px;
  text-align: center;
}

.start-logo {
  animation: start-rise 0.7s ease 0.1s both;
  height: auto;
  max-width: min(560px, 80vw);
  width: 100%;
}

.start-logo .lodestar-star {
  animation: start-glow 4s ease-in-out 0.8s infinite;
  transform-box: fill-box;
  transform-origin: center;
}

.start-tagline {
  animation: start-rise 0.7s ease 0.35s both;
  color: var(--muted);
  font-size: 1rem;
  letter-spacing: 0.02em;
  margin: 0;
}

.start-enter {
  animation: start-rise 0.7s ease 0.55s both;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 10px;
  color: #1b1508;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  min-height: 52px;
  padding: 0 48px;
}

.start-enter:hover {
  border-color: transparent;
  filter: brightness(1.08);
}

.start-credit {
  animation: start-fade 0.9s ease 0.9s both;
  bottom: 24px;
  color: var(--muted);
  font-size: 0.82rem;
  left: 0;
  letter-spacing: 0.03em;
  margin: 0;
  opacity: 0.7;
  position: absolute;
  right: 0;
  text-align: center;
}

@keyframes start-rise {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes start-fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 0.7;
  }
}

@keyframes start-glow {
  0%,
  100% {
    filter: drop-shadow(0 0 2px rgba(177, 195, 1, 0.35));
  }
  50% {
    filter: drop-shadow(0 0 14px rgba(210, 230, 60, 1))
      drop-shadow(0 0 30px rgba(197, 215, 40, 0.85))
      drop-shadow(0 0 48px rgba(177, 195, 1, 0.55));
  }
}

.app-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  height: 100vh;
  width: 100vw;
}

.app-shell[data-role="player"] {
  display: block;
  cursor: none;
}

.app-shell[data-role="player"] .gm-panel {
  display: none;
}

.app-shell[data-role="player"] .stage-controls {
  display: none;
}

.app-shell[data-role="player"] .stage-wrap {
  height: 100vh;
}

.gm-panel {
  background: #06021c;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 18px;
  overflow-y: auto;
  padding: 22px;
}

.brand {
  align-items: center;
  display: flex;
  justify-content: center;
}

.brand-logo {
  display: block;
  height: auto;
  max-width: 220px;
  width: 100%;
}

.eyebrow,
.hint {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
  margin: 0;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: 1.65rem;
  font-weight: 700;
}

h2 {
  font-size: 0.95rem;
  font-weight: 650;
}

.status {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--accent-2);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 5px 9px;
}

.control-section {
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 18px;
}

.section-title {
  align-items: center;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

label {
  color: var(--muted);
  display: grid;
  gap: 7px;
  font-size: 0.83rem;
}

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

input[type="color"] {
  background: transparent;
  border: 0;
  height: 34px;
  padding: 0;
  width: 100%;
}

.file-loader input {
  display: none;
}

.file-loader span,
.primary-button,
.library-button {
  align-items: center;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 6px;
  color: #1b1508;
  cursor: pointer;
  display: flex;
  font-weight: 750;
  justify-content: center;
  min-height: 42px;
  padding: 0 12px;
}

.library-button.empty {
  background: #3a3f3f;
  border-color: #4a5151;
  color: #9aa3a1;
  cursor: default;
}

/* Top GM actions: four icon buttons in a 2x2 grid. */
.top-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.top-action {
  align-items: center;
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: 8px;
  color: #1b1508;
  cursor: pointer;
  display: flex;
  justify-content: center;
  min-height: 52px;
  padding: 0;
}

.top-action:hover:not(:disabled) {
  filter: brightness(1.08);
}

.top-action svg {
  fill: none;
  height: 24px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
  width: 24px;
}

.top-action.empty,
.top-action:disabled {
  background: #3a3f3f;
  border-color: #4a5151;
  color: #9aa3a1;
  cursor: default;
}

.secondary-loader span {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
}

.primary-button,
.library-button {
  width: 100%;
}

.ghost-button {
  min-height: 30px;
  padding: 0 10px;
}

.inline-fields {
  display: grid;
  gap: 12px;
  grid-template-columns: 74px minmax(0, 1fr);
}

.inline-buttons {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.inline-buttons button,
.inline-loader span {
  align-items: center;
  display: flex;
  justify-content: center;
  min-height: 36px;
  width: 100%;
}

.inline-loader {
  cursor: pointer;
}

.inline-loader input {
  display: none;
}

.inline-loader span {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
}

.checkbox-row {
  align-items: center;
  color: var(--text);
  cursor: pointer;
  display: flex;
  flex-direction: row;
  gap: 8px;
}

.checkbox-row input {
  accent-color: var(--accent);
}

.switch input {
  display: none;
}

.switch.with-label {
  align-items: center;
  color: var(--text);
  display: inline-flex;
  font-size: 0.8rem;
  gap: 8px;
}

.switch span {
  background: #3a4241;
  border-radius: 999px;
  display: block;
  height: 24px;
  position: relative;
  width: 44px;
}

.switch span::after {
  background: white;
  border-radius: 50%;
  content: "";
  height: 18px;
  left: 3px;
  position: absolute;
  top: 3px;
  transition: transform 150ms ease;
  width: 18px;
}

.switch input:checked + span {
  background: var(--accent-2);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.segmented,
.fog-actions {
  display: grid;
  gap: 8px;
}

.segmented {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.segmented:has(#brushMode),
.segmented:has(#roundShape) {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.segmented button {
  padding: 0 7px;
}

.segmented .active {
  background: #263635;
  border-color: var(--accent-2);
  color: #c6fff1;
}

.fog-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.hidden {
  display: none !important;
}

.stage-wrap {
  background: #080909;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.stage-controls {
  align-items: start;
  display: flex;
  flex-direction: column;
  gap: 10px;
  left: 14px;
  position: absolute;
  top: 14px;
  z-index: 6;
}

.mode-hint-bar {
  background: rgba(25, 28, 29, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  left: 50%;
  margin: 0;
  max-width: calc(100% - 240px);
  padding: 7px 14px;
  position: absolute;
  text-align: center;
  top: 14px;
  transform: translateX(-50%);
  white-space: nowrap;
  z-index: 6;
}

.app-shell[data-role="player"] .mode-hint-bar {
  display: none;
}

.tool-row {
  align-items: flex-start;
  display: flex;
  gap: 8px;
}

.map-tools {
  background: rgba(25, 28, 29, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 6px;
  grid-template-columns: 1fr 1fr;
  padding: 7px;
  width: 96px;
}

/* Fog-of-war tools live in a ribbon that opens to the right of the toolbar. */
.fog-ribbon {
  background: rgba(25, 28, 29, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  gap: 6px;
  padding: 7px;
}

.fog-ribbon .tool-button {
  width: 38px;
}

.tool-button:disabled {
  cursor: default;
  opacity: 0.4;
}

.tool-button {
  align-items: center;
  aspect-ratio: 1;
  display: grid;
  justify-items: center;
  min-height: 0;
  padding: 0;
}

.tool-button svg {
  fill: none;
  height: 21px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 21px;
}

.tool-button.active {
  background: #263635;
  border-color: var(--accent-2);
  color: #c6fff1;
}

.player-toggles {
  background: rgba(25, 28, 29, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px;
  width: 96px;
}

.toggle-chip {
  align-items: center;
  color: var(--text);
  cursor: pointer;
  display: flex;
  font-size: 0.82rem;
  gap: 8px;
  padding: 3px 4px;
}

.toggle-chip input {
  accent-color: var(--accent);
}

.tool-popover {
  background: rgba(25, 28, 29, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  display: grid;
  gap: 12px;
  min-width: 230px;
  padding: 12px;
}

.tool-popover h2 {
  font-size: 0.9rem;
}

.tool-popover input[type="text"] {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  min-height: 34px;
  padding: 0 10px;
}

.player-fullscreen {
  align-items: center;
  background: rgba(25, 28, 29, 0.6);
  border: 1px solid rgba(120, 130, 130, 0.4);
  border-radius: 8px;
  color: var(--text);
  display: none;
  height: 40px;
  justify-content: center;
  opacity: 0.35;
  position: absolute;
  right: 16px;
  top: 16px;
  transition: opacity 150ms ease;
  width: 40px;
  z-index: 7;
}

.player-fullscreen:hover {
  opacity: 1;
}

.player-fullscreen svg {
  fill: none;
  height: 20px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
  width: 20px;
}

.app-shell[data-role="player"] .player-fullscreen {
  display: flex;
}

/* ---- Floor widget (top-right of GM stage) ---- */
.floor-widget {
  align-items: center;
  background: rgba(25, 28, 29, 0.92);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 4px;
  position: absolute;
  right: 14px;
  top: 14px;
  z-index: 6;
}

.app-shell[data-role="player"] .floor-widget {
  display: none;
}

.floor-widget-btn {
  align-items: center;
  aspect-ratio: 1;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text);
  display: flex;
  justify-content: center;
  min-height: 0;
  padding: 2px;
  width: 30px;
}

.floor-widget-btn:hover:not(:disabled) {
  border-color: var(--line);
  background: var(--panel-2);
}

.floor-widget-btn:disabled {
  cursor: default;
  opacity: 0.3;
}

.floor-widget-btn svg {
  fill: none;
  height: 18px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 18px;
}

.floor-widget-label {
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0 2px;
  text-align: center;
  white-space: nowrap;
}

/* ---- Player floor badge ---- */
.player-floor-badge {
  background: rgba(6, 2, 28, 0.82);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  position: absolute;
  right: 14px;
  top: 14px;
  z-index: 6;
}

/* ---- Floor panel controls in sidebar ---- */
.floor-add-row {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr 1fr;
}

.floor-add-row .ghost-button {
  align-items: center;
  display: flex;
  gap: 6px;
  justify-content: center;
  padding: 0 8px;
}

.floor-add-row svg {
  fill: none;
  flex-shrink: 0;
  height: 16px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 16px;
}

.danger-button {
  background: transparent;
  border-color: rgba(214, 106, 95, 0.45);
  color: var(--danger);
}

.danger-button:hover:not(:disabled) {
  background: rgba(214, 106, 95, 0.1);
  border-color: var(--danger);
}

.danger-button:disabled {
  cursor: default;
  opacity: 0.35;
}

.hint-inline {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
}

.name-dialog select {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  min-height: 38px;
  padding: 0 10px;
  width: 100%;
}

#floorName {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  min-height: 34px;
  padding: 0 10px;
  width: 100%;
}

#battlemap {
  display: block;
  height: 100%;
  width: 100%;
}

.empty-state {
  align-items: center;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 8px;
  inset: 0;
  justify-content: center;
  pointer-events: none;
  position: absolute;
  text-align: center;
}

.empty-state strong {
  color: var(--text);
  font-size: 1.1rem;
}

.empty-state.hidden {
  display: none;
}

.library-dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  max-width: 560px;
  padding: 0;
  width: min(92vw, 560px);
}

.library-dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.name-dialog {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 0;
  width: min(92vw, 360px);
}

.name-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.name-dialog form {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 18px;
}

.name-dialog h2 {
  font-size: 1rem;
}

.name-dialog input[type="text"] {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  min-height: 40px;
  padding: 0 12px;
  width: 100%;
}

.name-dialog-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr auto;
}

.name-dialog-actions .save-btn {
  background: var(--accent);
  border-color: transparent;
  color: #1b1508;
  font-weight: 750;
}

.library-dialog form {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 18px;
}

.dialog-head,
.saved-map-row {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.saved-map-list {
  display: grid;
  gap: 8px;
  max-height: 55vh;
  overflow-y: auto;
}

.saved-map-row {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.saved-map-row strong,
.saved-map-row span {
  display: block;
}

.saved-map-row span {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 3px;
}

.saved-map-actions {
  display: flex;
  gap: 8px;
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(280px, 45vh) 1fr;
  }

  .gm-panel {
    border-bottom: 1px solid var(--line);
    border-right: 0;
    order: 2;
    padding: 16px;
  }

  .stage-wrap {
    height: auto;
    min-height: 0;
    order: 1;
  }
}
