:root {
  --bg: #f4f1ea;
  --panel: #fffdf8;
  --ink: #1a1a1a;
  --muted: #5c5c5c;
  --line: #c9c2b4;
  --accent: #2f4f4f;
  --accent-hover: #1f3535;
  --danger: #7a2e2e;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
label {
  font: inherit;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  letter-spacing: 0.02em;
}

.brand p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: flex-end;
}

button,
.file-btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  padding: 0.4rem 0.75rem;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: var(--shadow);
}

button:hover,
.file-btn:hover {
  border-color: #9f9686;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-hover);
}

.file-btn {
  display: inline-flex;
  align-items: center;
}

.layout {
  display: grid;
  grid-template-columns: 168px 1fr 168px;
  gap: 0.75rem;
  padding: 0.75rem;
  min-height: calc(100vh - 78px);
}

/* Column wrappers (no chrome) — panels live inside */
.palette-column {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-height: calc(100vh - 100px);
  min-height: 0;
}

/* Shared card for Terrain / Features / Room keys */
.palette-panel {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
  isolation: isolate;
}

.palette-panel--grow {
  flex: 1 1 auto;
}

.palette-panel--fixed {
  flex: 0 0 auto;
}

.palette-title {
  box-sizing: border-box;
  margin: 0;
  padding: 0.55rem 0.5rem 0.45rem;
  min-height: 2.25rem;
  font-size: 0.95rem;
  line-height: 1.25;
  font-weight: 700;
  display: flex;
  align-items: center;
  background: var(--panel);
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  box-shadow: none;
  flex-shrink: 0;
}

.palette-scroll {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow: auto;
  flex: 1;
  min-height: 0;
  padding: 0.5rem;
}

.palette-panel-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.5rem;
  flex-shrink: 0;
}

.palette-features-tools {
  display: flex;
  flex-direction: column;
  padding: 0.65rem 0.5rem;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  background: var(--panel);
}

.palette-rotate {
  width: 100%;
  flex-shrink: 0;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  box-shadow: none;
}

.tile-btn {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  width: 100%;
  text-align: center;
  padding: 0.35rem 0.15rem 0.4rem;
  background: #fff;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: 4px;
  box-shadow: none;
  position: relative;
  z-index: 0;
}

.tile-btn.active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.preview-wrap {
  display: grid;
  grid-template-columns: 1.35rem 1fr 1.35rem;
  align-items: center;
  width: 100%;
}

.var-arrow {
  padding: 0;
  min-width: 0;
  width: 100%;
  height: 64px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
  line-height: 1;
  box-shadow: none;
  border: none;
  background: transparent;
  color: var(--muted);
}

.var-arrow:hover {
  color: var(--ink);
  border-color: transparent;
}

.tile-btn canvas {
  width: 64px;
  height: 64px;
  justify-self: center;
  display: block;
  background: #fff;
  border: 1px solid var(--line);
}

.tile-meta {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  align-items: center;
}

.tile-meta strong {
  font-size: 0.88rem;
}

.tile-meta span,
.tile-meta .var-label {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: capitalize;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-width: 0;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.55rem 0.75rem;
}

.toolbar label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.9rem;
}

.toolbar input[type="number"] {
  width: 4rem;
  padding: 0.2rem 0.35rem;
}

.toolbar input[type="range"] {
  width: 7rem;
}

.toolbar .check {
  gap: 0.3rem;
}

.toolbar-checks {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-left: auto;
}

.hint {
  color: var(--muted);
  font-size: 0.85rem;
  flex: 1 1 100%;
  text-align: center;
}

.floating-panel {
  position: fixed;
  z-index: 40;
  top: 7.5rem;
  right: 12rem;
  width: 280px;
  height: 320px;
  min-width: 220px;
  min-height: 160px;
  max-width: min(90vw, 480px);
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

.floating-panel-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 24px;
  height: 24px;
  cursor: nwse-resize;
  touch-action: none;
  z-index: 2;
}

.floating-panel-resize::before {
  content: "";
  position: absolute;
  right: 5px;
  bottom: 5px;
  width: 14px;
  height: 14px;
  background:
    linear-gradient(135deg,
      transparent 0 42%,
      var(--muted) 42% 48%,
      transparent 48% 58%,
      var(--muted) 58% 64%,
      transparent 64% 74%,
      var(--muted) 74% 80%,
      transparent 80%);
  opacity: 0.75;
}

.floating-panel-resize:hover::before,
.floating-panel-resize:active::before {
  opacity: 1;
}

.floating-panel[hidden] {
  display: none !important;
}

.floating-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.55rem;
  background: #f0ebe3;
  border-bottom: 1px solid var(--line);
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
}

.floating-panel-header:active {
  cursor: grabbing;
}

.floating-panel-header strong {
  font-size: 0.95rem;
}

.floating-panel-header button {
  padding: 0.1rem 0.45rem;
  line-height: 1.2;
  box-shadow: none;
}

.floating-panel-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 0.45rem 0.55rem 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.floating-empty {
  margin: 0.4rem 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.key-note-row {
  display: grid;
  grid-template-columns: 2.4rem 1fr;
  gap: 0.4rem;
  align-items: center;
}

.key-note-row .key-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 1.7rem;
  padding: 0.1rem 0.2rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.85);
  font-weight: 700;
  font-size: 0.85rem;
}

.key-note-row input {
  width: 100%;
  padding: 0.25rem 0.4rem;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}

.canvas-wrap {
  flex: 1;
  min-height: 520px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: auto;
  box-shadow: var(--shadow);
}

.canvas-center {
  box-sizing: border-box;
  min-width: 100%;
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
}

.map-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: none;
  flex: 0 0 auto;
}

.map-title-input {
  display: block;
  width: 100%;
  margin: 0;
  padding: 0.65rem 1rem 0.55rem;
  border: none;
  border-bottom: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  text-align: center;
  font: bold 1.15rem "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  letter-spacing: 0.01em;
}

.map-title-input::placeholder {
  color: #a39a8c;
  font-weight: 600;
}

.map-title-input:focus {
  outline: none;
  background: #fffcf6;
}

#map-canvas {
  display: block;
  cursor: crosshair;
  background: #fff;
  flex: 0 0 auto;
}

.site-footer {
  padding: 0.65rem 1.25rem 0.85rem;
  border-top: 1px solid var(--line);
  background: var(--panel);
  text-align: center;
}

.site-footer p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

.seo-about {
  max-width: 52rem;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 1.75rem;
  color: var(--ink);
}

.seo-about h2 {
  margin: 0 0 0.5rem;
  font-size: 1.15rem;
  font-weight: 700;
}

.seo-about p {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--muted);
}

.seo-about ul {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--muted);
}

.seo-about li {
  margin-bottom: 0.25rem;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .palette-column {
    max-height: none;
  }

  .palette-panel--grow {
    flex: 0 0 auto;
  }

  .tile-btn {
    width: auto;
    min-width: 140px;
    flex: 1 1 140px;
  }

  .hint {
    margin-left: 0;
    width: 100%;
  }
}