/* MisterMR MAP Creator — Steampunk theme */
:root {
  --bg-dark: #1a1510;
  --bg-panel: #2a2218;
  --bg-input: #1f1914;
  --border: #4a3c28;
  --border-light: #6b5a42;
  --text: #e8dcc8;
  --text-dim: #a89880;
  --accent: #c9a227;
  --accent-glow: #e8c547;
  --sea: #1e3a5f;
  --ground: #3d2e1f;
  --city: #c9a227;
  --river: #2a5080;
  --font-display: "Cinzel", "Georgia", serif;
  --font-body: "Crimson Text", "Georgia", serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  background: var(--bg-dark);
  color: var(--text);
  background-image:
    radial-gradient(ellipse at 20% 20%, rgba(201, 162, 39, 0.06) 0%, transparent 50%),
    url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E");
}

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bg-panel);
  border-bottom: 2px solid var(--border);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.header__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--accent);
  text-shadow: 0 0 12px rgba(201, 162, 39, 0.3);
}

.header__actions {
  display: flex;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  padding: 0.5rem 1rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.btn:hover {
  background: #352a1f;
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(201, 162, 39, 0.2);
}

.btn:focus-visible,
.tool-btn:focus-visible,
.input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

.btn--header {
  min-width: 4rem;
}

.btn--primary {
  background: linear-gradient(180deg, #4a3c20 0%, #2a2210 100%);
  border-color: var(--accent);
  color: var(--accent-glow);
}

.btn--primary:hover {
  box-shadow: 0 0 12px rgba(201, 162, 39, 0.4);
}

.btn--secondary {
  width: 100%;
}

.btn--generate {
  width: 100%;
  padding: 0.85rem 1.5rem;
  margin-top: 1rem;
  font-size: 1.1rem;
  font-weight: 600;
  background: linear-gradient(180deg, #5a4a28 0%, #3d3218 100%);
  border: 2px solid var(--accent);
  color: var(--accent-glow);
}

.btn--generate:hover {
  box-shadow: 0 0 16px rgba(201, 162, 39, 0.35);
}

/* Main layout */
.main {
  display: flex;
  height: calc(100vh - 56px - 44px);
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 320px;
  min-width: 320px;
  padding: 1rem;
  background: var(--bg-panel);
  border-right: 2px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sidebar__field label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.2);
}

.sidebar__label {
  margin: 0 0 0.35rem 0;
  font-size: 0.85rem;
  color: var(--text-dim);
}

.sidebar__draw-area {
  flex-shrink: 0;
}

.sidebar__hint {
  margin: 0.35rem 0 0 0;
  font-size: 0.75rem;
  color: var(--text-dim);
  line-height: 1.3;
}

.input-range {
  width: 100%;
  margin: 0.25rem 0;
  accent-color: var(--accent);
}

.sketch-canvas {
  display: block;
  width: 100%;
  max-width: 280px;
  height: auto;
  aspect-ratio: 1;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: 4px;
  cursor: crosshair;
}

.sidebar__tools {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.sidebar__actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.sidebar__actions .btn {
  flex: 1;
  min-width: 0;
}

.tool-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 1.1rem;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}

.tool-btn:hover,
.tool-btn.active {
  border-color: var(--accent);
  background: rgba(201, 162, 39, 0.15);
}

/* Bottom color bar */
.color-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 44px;
  padding: 0 1rem;
  background: var(--bg-panel);
  border-top: 2px solid var(--border);
  flex-shrink: 0;
}

.color-bar__label {
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
}

.btn--small {
  padding: 0.25rem 0.6rem;
  font-size: 0.8rem;
}

.color-swatches.color-swatches--inline {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0;
  flex-wrap: nowrap;
}

.color-swatch {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
}

.color-swatch input[type="color"] {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  background: transparent;
}

/* Map area */
.map-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 1rem;
  background: var(--bg-dark);
}

.map-area__title-overlay {
  position: absolute;
  top: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent-glow);
  text-shadow: 0 0 20px rgba(201, 162, 39, 0.5), 0 2px 4px rgba(0,0,0,0.5);
  pointer-events: none;
  white-space: nowrap;
}

.map-area__canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: var(--bg-input);
  border: 2px solid var(--border);
  border-radius: 4px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-svg-container {
  max-width: 100%;
  max-height: 100%;
  overflow: auto;
}

.map-svg-container svg {
  display: block;
  max-width: 100%;
  height: auto;
}

.map-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.map-area__overlay {
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  display: flex;
  justify-content: space-between;
  pointer-events: none;
}

.map-scale,
.map-compass {
  font-size: 0.85rem;
  color: var(--text-dim);
  background: rgba(26, 21, 16, 0.8);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}

.map-compass {
  font-weight: 700;
  color: var(--accent);
}

/* Export dropdown */
.export-dropdown {
  position: relative;
}

.export-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.25rem;
  min-width: 10rem;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
  z-index: 100;
  display: flex;
  flex-direction: column;
  padding: 0.25rem 0;
}

.export-menu[hidden] {
  display: none !important;
}

.export-menu__item {
  padding: 0.5rem 1rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}

.export-menu__item:hover {
  background: rgba(201, 162, 39, 0.15);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  padding: 0.6rem 1.2rem;
  font-family: var(--font-body);
  font-size: 0.9rem;
  color: var(--text);
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  animation: toast-in 0.25s ease;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(0.5rem);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Load modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal[hidden] {
  display: none !important;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.modal__panel {
  position: relative;
  background: var(--bg-panel);
  border: 2px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  max-width: 90vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}

.load-modal__panel {
  min-width: 320px;
  width: 420px;
  max-height: 70vh;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal__title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent);
}

.modal__close {
  width: 2rem;
  height: 2rem;
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--text-dim);
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.modal__close:hover {
  color: var(--accent);
  background: rgba(201, 162, 39, 0.15);
}

.modal__body {
  padding: 1rem 1.25rem;
  overflow-y: auto;
}

.load-modal__list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.load-modal__item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  text-align: left;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.load-modal__item:hover {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(201, 162, 39, 0.2);
}

.load-modal__item-preview {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-dark);
  object-fit: cover;
}

.load-modal__item-placeholder {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: var(--text-dim);
}

.load-modal__item-info {
  flex: 1;
  min-width: 0;
}

.load-modal__item-name {
  font-weight: 600;
  font-size: 1rem;
  color: var(--accent-glow);
  margin: 0 0 0.25rem 0;
}

.load-modal__item-date {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin: 0;
}

.load-modal__empty {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.95rem;
  text-align: center;
  padding: 1.5rem;
}
