:root {
  --ink: #304b40;
  --muted: #6f837a;
  --forest: #2e6b5a;
  --forest-deep: #1f4d40;
  --mint: #86c9ad;
  --mint-soft: #dcefe7;
  --cream: #fbf6e9;
  --paper: #fffdf7;
  --peach: #f2a678;
  --peach-soft: #fbe3d4;
  --danger: #b34e4e;
  --danger-soft: #f9e1de;
  --warning: #9a6a21;
  --warning-soft: #fbefd5;
  --line: #d9e3dc;
  --shadow: 0 18px 46px rgba(25, 67, 53, 0.12);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 12% 0%, rgba(134, 201, 173, 0.24), transparent 34rem),
    radial-gradient(circle at 100% 90%, rgba(242, 166, 120, 0.16), transparent 32rem),
    #edf4ef;
  color: var(--ink);
  font-family: Inter, ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
}

button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.topbar {
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 12px 24px;
  border-bottom: 1px solid rgba(46, 107, 90, 0.12);
  background: rgba(255, 253, 247, 0.88);
  backdrop-filter: blur(14px);
}

.brand { display: flex; align-items: center; gap: 13px; }
.brand-mushroom { width: 54px; height: 54px; object-fit: contain; filter: drop-shadow(0 7px 9px rgba(46, 107, 90, 0.2)); }
.eyebrow, .step { margin: 0; text-transform: uppercase; letter-spacing: .15em; font-size: 10px; font-weight: 800; color: var(--peach); }
h1 { margin: 1px 0 0; font-family: "Comic Sans MS", "Segoe Print", cursive; font-size: clamp(22px, 2vw, 29px); color: var(--forest); line-height: 1; }
h2 { margin: 2px 0 0; font-size: 17px; color: var(--forest-deep); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.safe-badge { display: inline-flex; align-items: center; gap: 7px; border-radius: 999px; padding: 8px 12px; background: var(--mint-soft); color: var(--forest); font-size: 12px; font-weight: 750; }
.safe-badge span { display: grid; place-items: center; width: 18px; height: 18px; color: white; background: var(--forest); border-radius: 50%; }

.workspace {
  height: calc(100vh - 82px);
  min-height: 620px;
  display: grid;
  grid-template-columns: 276px minmax(420px, 1fr) 300px;
  gap: 14px;
  padding: 14px;
}

.panel, .editor-area {
  min-width: 0;
  border: 1px solid rgba(46, 107, 90, 0.13);
  border-radius: 20px;
  background: rgba(255, 253, 247, 0.95);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel { overflow-y: auto; }
.panel section { padding: 18px; border-bottom: 1px solid var(--line); }
.panel section:last-child { border-bottom: 0; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.section-heading.compact { margin-bottom: 12px; }

label { display: block; margin: 12px 0 6px; color: var(--muted); font-size: 12px; font-weight: 750; }
input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid #cbd8d0;
  border-radius: 11px;
  padding: 8px 10px;
  outline: none;
  background: white;
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--mint); box-shadow: 0 0 0 3px rgba(134, 201, 173, .2); }
.field-row { display: grid; grid-template-columns: 1fr 40px; gap: 7px; }
.field-note, .safety-copy { margin: 7px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.split-action { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 15px; }
.dimension-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.dimension-grid label { margin-top: 0; }

.button, .icon-button, .tool-button, .round-button {
  border: 0;
  cursor: pointer;
  color: var(--ink);
  transition: transform .12s, background .12s, opacity .12s, box-shadow .12s;
}
.button:hover:not(:disabled), .icon-button:hover:not(:disabled), .tool-button:hover:not(:disabled), .round-button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled, .icon-button:disabled, .tool-button:disabled, .round-button:disabled { cursor: not-allowed; opacity: .42; }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 9px 13px; border-radius: 11px; text-decoration: none; font-size: 12px; font-weight: 800; }
.button.primary { background: var(--forest); color: white; box-shadow: 0 7px 16px rgba(46, 107, 90, .18); }
.button.primary:hover:not(:disabled) { background: var(--forest-deep); }
.button.quiet { border: 1px solid #cad9d0; background: white; }
.button.play { background: var(--peach-soft); color: #8d512d; border: 1px solid #f5c5a8; }
.button.danger { background: #f9dfd7; color: #a03a2b; border: 1px solid #f3c0b0; box-shadow: 0 7px 16px rgba(160, 58, 43, .14); }
.button.danger:hover:not(:disabled) { background: #f3cfc2; }
.backup-option { display: flex; align-items: center; gap: 8px; margin-top: 13px; font-size: 12px; font-weight: 750; color: var(--ink); cursor: pointer; }
.backup-option input { accent-color: var(--forest); }
.button.full { width: 100%; margin-top: 8px; }
.icon-button { display: grid; place-items: center; border-radius: 11px; background: var(--mint-soft); color: var(--forest); font-size: 20px; }

.editor-area { display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; }
.editor-toolbar { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.history-actions, .zoom-actions { display: flex; align-items: center; gap: 6px; }
.tool-button, .round-button { height: 34px; border: 1px solid #d3ded7; background: white; border-radius: 9px; padding: 0 10px; font-size: 12px; font-weight: 750; }
.round-button { width: 34px; padding: 0; border-radius: 50%; font-size: 20px; color: var(--forest); }
.compact-button { padding: 0 8px; }
#zoom-value { width: 48px; text-align: center; font-size: 11px; color: var(--muted); font-weight: 750; }

.palette { display: flex; gap: 7px; padding: 10px 12px; overflow-x: auto; border-bottom: 1px solid var(--line); background: #f8fbf8; scrollbar-width: thin; }
.palette-item {
  flex: 0 0 auto;
  width: 62px;
  min-height: 62px;
  display: grid;
  place-items: center;
  gap: 1px;
  padding: 5px 3px;
  border: 1px solid #d5e0d9;
  border-radius: 12px;
  background: white;
  color: var(--muted);
  cursor: pointer;
}
.palette-item:hover { border-color: var(--mint); }
.palette-item.active { border-color: var(--forest); color: var(--forest); background: var(--mint-soft); box-shadow: 0 0 0 2px rgba(46, 107, 90, .1); }
.tile-preview { display: grid; place-items: center; width: 31px; height: 31px; border-radius: 8px; color: white; font-size: 17px; font-weight: 900; font-family: ui-monospace, monospace; }
.palette-label { font-size: 9px; font-weight: 800; white-space: nowrap; }

.canvas-wrap { position: relative; min-height: 0; overflow: auto; background-color: #d9eee8; background-image: radial-gradient(rgba(46, 107, 90, .12) 1px, transparent 1px); background-size: 18px 18px; scrollbar-color: var(--mint) transparent; }
#level-canvas { display: block; margin: 24px; border-radius: 6px; box-shadow: 0 12px 30px rgba(31, 77, 64, .17); cursor: crosshair; touch-action: none; }
.canvas-help { position: sticky; left: 50%; bottom: 10px; width: max-content; max-width: calc(100% - 20px); transform: translateX(-50%); padding: 6px 10px; border-radius: 999px; background: rgba(31, 77, 64, .82); color: white; font-size: 10px; pointer-events: none; backdrop-filter: blur(7px); }
.editor-status { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; min-height: 38px; padding: 6px 12px; color: var(--muted); background: white; border-top: 1px solid var(--line); font-size: 10px; font-weight: 700; }
.editor-status > :last-child { text-align: right; }
.status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 5px; border-radius: 50%; background: var(--mint); }

.validation-badge { padding: 6px 9px; border-radius: 999px; background: var(--mint-soft); color: var(--forest); font-size: 10px; font-weight: 850; white-space: nowrap; }
.validation-badge.invalid { color: var(--danger); background: var(--danger-soft); }
.level-summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; margin-bottom: 13px; }
.summary-item { padding: 9px; border-radius: 11px; background: #f3f7f4; }
.summary-item strong { display: block; color: var(--forest); font-size: 17px; }
.summary-item span { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .08em; font-weight: 800; }
.validation-list { display: grid; gap: 7px; }
.validation-message { display: grid; grid-template-columns: 20px 1fr; gap: 7px; align-items: start; padding: 9px; border-radius: 11px; font-size: 11px; line-height: 1.4; }
.validation-message.error { color: #853f3f; background: var(--danger-soft); }
.validation-message.warning { color: #7d5c25; background: var(--warning-soft); }
.validation-message.success { color: var(--forest); background: var(--mint-soft); }
.message-icon { display: grid; place-items: center; width: 19px; height: 19px; border-radius: 50%; background: currentColor; color: white; font-size: 11px; font-weight: 900; }
.validation-message .message-icon span { color: white; }
.export-section .safety-copy code { padding: 1px 4px; border-radius: 4px; background: #edf2ee; color: var(--forest); }

.toast { position: fixed; z-index: 10; left: 50%; bottom: 22px; transform: translate(-50%, 18px); padding: 10px 15px; border-radius: 999px; background: var(--forest-deep); color: white; box-shadow: 0 12px 30px rgba(18, 48, 38, .28); font-size: 12px; font-weight: 750; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 245px minmax(390px, 1fr); height: auto; min-height: calc(100vh - 82px); }
  .check-panel { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; }
  .check-panel section { border-bottom: 0; }
  .check-panel section + section { border-left: 1px solid var(--line); }
  .editor-area { min-height: 650px; }
}

@media (max-width: 720px) {
  .topbar { padding: 10px 12px; }
  .safe-badge { display: none; }
  .workspace { display: flex; flex-direction: column; padding: 8px; }
  .settings-panel { display: grid; grid-template-columns: 1fr; }
  .editor-area { min-height: 620px; }
  .check-panel { display: block; }
  .check-panel section + section { border-left: 0; }
  .tool-button span { display: none; }
  .canvas-help { display: none; }
}
