/* Level Designer — self-contained styles, no external fonts or assets. */
:root {
  --bg-page: #f4ece1;
  --bg-surface: #fffbf5;
  --bg-base: #ffffff;
  --bg-header: #fff8ee;
  --text-primary: #2a2118;
  --text-secondary: #5c5046;
  --text-tertiary: #8a7d70;
  --text-danger: #c0392b;
  --text-warning: #9a5b00;
  --border: #d4c8b8;
  --border-weak: #e8ddd0;
  --border-strong: #b8a894;
  --border-focus: #c49212;
  --fill-secondary: #efe6d8;
  --fill-hover: #e4d8c6;
  --fill-pressed: #d4c4ae;
  --fill-accent: rgba(181, 113, 46, 0.14);
  --btn-primary-bg: #b5712e;
  --btn-primary-text: #fff8ee;
  --btn-primary-hover: #9a5e24;
  --shadow: 0 1px 2px rgba(42, 33, 24, 0.06), 0 6px 18px rgba(42, 33, 24, 0.06);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-page: #16110e;
    --bg-surface: #241c16;
    --bg-base: #2c231c;
    --bg-header: #1d1712;
    --text-primary: #f5efe6;
    --text-secondary: #c4b8a8;
    --text-tertiary: #8a7d70;
    --text-danger: #f07167;
    --text-warning: #e8a838;
    --border: #4a3f35;
    --border-weak: #3a322b;
    --border-strong: #6a5c50;
    --border-focus: #f2c230;
    --fill-secondary: #3a322b;
    --fill-hover: #4a3f35;
    --fill-pressed: #5a4c40;
    --fill-accent: rgba(242, 194, 48, 0.16);
    --btn-primary-bg: #d4893a;
    --btn-primary-text: #1a1410;
    --btn-primary-hover: #e09a4e;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}

#app { min-height: 100%; }

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(32px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 16px;
  margin-bottom: 18px;
  padding: 12px 16px;
  background: var(--bg-header);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  position: sticky;
  top: env(safe-area-inset-top, 0);
  z-index: 20;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1 1 auto;
  min-width: 0;
}

.header-brand img {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  flex-shrink: 0;
}

.header h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.summary {
  margin: 2px 0 0;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.saved-dot {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  padding: 0 4px;
}

.section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px 18px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
}

.prose {
  margin: 0 0 12px;
  color: var(--text-secondary);
  font-size: 0.92rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 20px;
}

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

.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: flex-end;
}

.row-center { align-items: center; }

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 140px;
  min-width: 0;
}

.field-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 550;
}

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  background: var(--bg-base);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.95rem;
  min-height: 40px;
}

textarea.mono,
textarea {
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.4;
  resize: vertical;
  white-space: pre;
  min-height: 16em;
}

textarea.wrap { white-space: pre-wrap; }

input:focus, select:focus, textarea:focus, button:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 1px;
}

.btn, button.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--fill-secondary);
  color: var(--text-primary);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  min-height: 44px;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:hover { background: var(--fill-hover); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
  border-color: transparent;
}
.btn-primary:hover { background: var(--btn-primary-hover); }

.btn-subtle {
  background: transparent;
  border-color: var(--border);
  min-height: 36px;
  font-weight: 550;
}

.btn-install {
  background: var(--bg-base);
  border: 1px dashed var(--border-focus);
  color: var(--text-primary);
  min-height: 40px;
  font-size: 0.85rem;
}

.confirm-wrap {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.confirm-q { color: var(--text-danger); font-size: 12px; }

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  min-height: 44px;
}

.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }

.toggle-track {
  width: 44px;
  height: 26px;
  border-radius: 13px;
  background: var(--fill-pressed);
  border: 1px solid var(--border);
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s;
}

.toggle-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--bg-base);
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
  transition: transform 0.15s;
}

.toggle input:checked + .toggle-track {
  background: var(--btn-primary-bg);
  border-color: transparent;
}
.toggle input:checked + .toggle-track::after { transform: translateX(18px); }
.toggle-label { font-size: 0.92rem; }

.seg {
  display: inline-flex;
  flex-wrap: wrap;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-base);
}

.seg button {
  appearance: none;
  border: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text-primary);
  padding: 8px 12px;
  min-height: 40px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 18px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin: 8px 0 12px;
}

.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  border: 1px solid var(--border);
}

.board-wrap {
  flex: 1 1 300px;
  min-width: 0;
  max-width: 640px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.board {
  display: grid;
  gap: 3px;
  touch-action: none;
  overscroll-behavior: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.tile {
  aspect-ratio: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
  position: relative;
}

.tile svg { display: block; width: 100%; height: 100%; pointer-events: none; }

.sel-bar {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.sel-count {
  min-width: 80px;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.clear-sel {
  flex: 1 1 140px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--fill-secondary);
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 600;
}

.warnings {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.warn-head, .warn-item { color: var(--text-warning); }
.warn-head { font-size: 0.9rem; font-weight: 650; }
.warn-item { font-size: 12px; }

.hint {
  margin-top: 8px;
  color: var(--text-tertiary);
  font-size: 12px;
}

.editor-pane {
  flex: 1 1 260px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  color: var(--text-primary);
}

.compass {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  gap: 4px;
}

.compass-cell {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 20px;
}

.compass-cell.on {
  background: #F2C230;
  color: #3A2A00;
}

.attr-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.attr-name {
  width: 72px;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 5px;
  border: 1px solid var(--border);
  display: inline-block;
}

.step-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.step-row.active { border-color: var(--border-focus); box-shadow: 0 0 0 1px var(--border-focus); }

.step-pick {
  flex: 1 1 200px;
  cursor: pointer;
  font-size: 0.9rem;
}

.msg { font-size: 12px; color: var(--text-secondary); }
.msg.warn { color: var(--text-warning); }

.hidden-file { display: none; }

.board-layout {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: flex-start;
}

.muted { color: var(--text-tertiary); font-size: 0.9rem; }
