/* ============================================================
   Mapart Creator — "Kartograph-Werkstatt"
   Dunkle Arbeitsfläche, damit das farbige Mapart wie ein
   Kunstwerk an der Wand hängt. Akzentfarbe: Lila (#a855f7), passend zum Target-Cursor.
   ============================================================ */

:root {
  --bg:        #101218;
  --bg-deep:   #0b0d12;
  --panel:     #171a22;
  --panel-2:   #1e222c;
  --line:      #2a2f3b;
  --line-2:    #3a4150;
  --text:      #e9ecf3;
  --muted:     #9aa2b2;
  --faint:     #6b7280;
  --accent:    #a855f7;   /* Cursor-Lila */
  --accent-2:  #c68cff;
  --accent-dim:#46226b;
  --ink:       #12061f;   /* text auf accent */
  --parch:     #d8c39a;   /* pergament, sparsam */
  --danger:    #e8785a;
  --radius:    12px;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", "SF Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body {
  background:
    radial-gradient(1200px 700px at 82% -8%, rgba(168,85,247,.10), transparent 60%),
    radial-gradient(900px 600px at 8% 4%, rgba(80,120,200,.07), transparent 55%),
    var(--bg);
  min-height: 100vh;
}

.grain {
  position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .035;
  background-image: repeating-linear-gradient(0deg, #fff 0, #fff 1px, transparent 1px, transparent 3px);
  mix-blend-mode: overlay;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); font-size: .86em; background: var(--bg-deep); padding: .1em .4em; border-radius: 5px; color: var(--parch); }
kbd { font-family: var(--mono); font-size: .78em; background: var(--panel-2); border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 5px; padding: .05em .4em; }

/* ---------- Masthead ---------- */
.masthead {
  position: relative; z-index: 1;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(23,26,34,.6), rgba(16,18,24,.2));
  backdrop-filter: blur(6px);
}
.mast-inner {
  max-width: 1240px; margin: 0 auto; padding: 16px 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 6px; flex: none;
  background:
    conic-gradient(from 45deg, #a855f7 0 25%, #7c33cc 0 50%, #c68cff 0 75%, #8f42e0 0 100%);
  box-shadow: 0 0 0 1px rgba(255,255,255,.08), 0 6px 16px rgba(168,85,247,.28);
  image-rendering: pixelated;
}
.brand-txt h1 {
  margin: 0; font-family: var(--mono); font-size: 19px; font-weight: 700;
  letter-spacing: -.02em; text-transform: uppercase;
}
.brand-txt h1 span { color: var(--accent); margin-left: 2px; }
.brand-sub { margin: 1px 0 0; font-size: 12px; color: var(--muted); font-family: var(--mono); letter-spacing: .01em; }
.mast-link { font-size: 13px; color: var(--muted); }
.mast-link:hover { color: var(--text); }

.palette-strip {
  display: flex; height: 8px; width: 100%;
  border-top: 1px solid rgba(255,255,255,.04);
}
.palette-strip span { flex: 1 1 auto; height: 100%; }

/* ---------- Workspace ---------- */
.workspace {
  position: relative; z-index: 1;
  max-width: 1240px; margin: 0 auto; padding: 26px 22px;
  display: grid; grid-template-columns: minmax(320px, 400px) 1fr; gap: 22px; align-items: start;
}
@media (max-width: 900px) {
  .workspace { grid-template-columns: 1fr; }
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 18px;
  margin-bottom: 14px;
}
.controls .card:last-child { margin-bottom: 0; }

.field-label {
  display: block; font-family: var(--mono); font-size: 11px; letter-spacing: .14em;
  text-transform: uppercase; color: var(--faint); margin: 0 0 12px;
}
.field-label::first-letter { color: var(--accent); }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 1.5px dashed var(--line-2); border-radius: 10px;
  min-height: 132px; display: grid; place-items: center; cursor: pointer;
  transition: border-color .15s, background .15s; overflow: hidden; position: relative;
  background: var(--bg-deep);
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); background: #15101d; outline: none; }
.dropzone.drag { border-color: var(--accent); background: #181022; }
.dz-empty { text-align: center; padding: 18px; color: var(--muted); }
.dz-icon { font-size: 26px; color: var(--accent); display: block; margin-bottom: 6px; }
.dz-empty p { margin: 2px 0; font-size: 13.5px; }
.dz-empty strong { color: var(--text); }
.dz-hint { font-size: 11.5px !important; color: var(--faint); }
.dz-thumb { max-width: 100%; max-height: 200px; display: block; image-rendering: auto; }
.src-meta { margin: 8px 2px 0; font-size: 12px; color: var(--faint); font-family: var(--mono); min-height: 14px; }

/* ---------- Presets & Dimensions ---------- */
.preset-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; margin-bottom: 12px; }
.preset {
  font-family: var(--mono); font-size: 13px; padding: 9px 0; border-radius: 8px;
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line); cursor: pointer;
  transition: .12s;
}
.preset:hover { border-color: var(--line-2); }
.preset.active { background: var(--accent); color: var(--ink); border-color: var(--accent); font-weight: 700; }

.dim-row { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.num-field { display: flex; flex-direction: column; gap: 4px; }
.num-field label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); }
.num-field input {
  width: 62px; font-family: var(--mono); font-size: 15px; padding: 7px 8px;
  background: var(--bg-deep); border: 1px solid var(--line-2); border-radius: 7px; color: var(--text);
}
.times { color: var(--faint); padding-bottom: 8px; }
.dim-out { margin-left: auto; font-family: var(--mono); font-size: 12px; color: var(--accent-2); padding-bottom: 7px; }

/* ---------- Segmented controls ---------- */
.seg { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.seg-label { font-size: 11.5px; color: var(--muted); width: 74px; flex: none; }
.seg-btns { display: inline-flex; background: var(--bg-deep); border: 1px solid var(--line); border-radius: 8px; padding: 3px; gap: 2px; flex: 1; }
.seg-btns button {
  flex: 1; font-family: var(--sans); font-size: 12.5px; padding: 6px 8px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer; transition: .12s; white-space: nowrap;
}
.seg-btns button:hover { color: var(--text); }
.seg-btns button.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-2); }
.seg-btns button.active[data-mode], .seg-btns button.active[data-dither] { color: var(--accent-2); }

.mode-note { margin: 10px 0 0; font-size: 12px; color: var(--faint); line-height: 1.45; }

.check { display: flex; gap: 9px; align-items: flex-start; margin-top: 14px; font-size: 12.5px; color: var(--muted); cursor: pointer; }
.check input { margin-top: 2px; accent-color: var(--accent); width: 15px; height: 15px; flex: none; }
.check em { color: var(--faint); font-style: normal; }
.check.tiny { margin: 0; font-size: 12px; }

/* ---------- Palette panel ---------- */
.pal-toggle { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: 0; cursor: pointer; margin-bottom: 0; padding: 0; }
.pal-count { color: var(--accent-2); font-size: 11px; }
.pal-toggle .chev { margin-left: auto; transition: transform .15s; color: var(--muted); }
.pal-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.pal-actions { display: flex; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.mini { font-size: 11.5px; font-family: var(--mono); padding: 4px 9px; border-radius: 6px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); cursor: pointer; }
.mini:hover { border-color: var(--line-2); }
.pal-hint { font-size: 11px; color: var(--faint); flex: 1 1 100%; }
.pal-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(30px, 1fr)); gap: 6px; margin-top: 12px; }
.sw {
  aspect-ratio: 1; border-radius: 6px; cursor: pointer; position: relative;
  border: 1px solid rgba(0,0,0,.35); box-shadow: inset 0 0 0 1px rgba(255,255,255,.05);
  transition: transform .1s;
}
.sw:hover { transform: scale(1.08); z-index: 2; }
.sw.off { opacity: .25; filter: grayscale(.7); }
.sw.off::after { content: ""; position: absolute; inset: 0; background: linear-gradient(135deg, transparent 44%, rgba(255,255,255,.7) 45%, rgba(255,255,255,.7) 55%, transparent 56%); border-radius: 6px; }

/* ---------- Preview ---------- */
.preview { min-width: 0; }
.preview-frame {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 14px;
}
.canvas-wrap {
  position: relative; background:
    repeating-conic-gradient(#161922 0% 25%, #12141b 0% 50%) 50% / 22px 22px;
  border-radius: 8px; overflow: hidden; display: grid; place-items: center;
  aspect-ratio: 1 / 1; border: 1px solid var(--line);
}
#previewCanvas {
  image-rendering: pixelated; width: 100%; height: 100%; object-fit: contain; display: block;
}
#previewCanvas.hidden { display: none; }
.grid-overlay { position: absolute; inset: 0; pointer-events: none; }
.grid-overlay .gl {
  position: absolute; background: rgba(216,195,154,.35);
}
.grid-overlay .gl.v { top: 0; bottom: 0; width: 1px; }
.grid-overlay .gl.h { left: 0; right: 0; height: 1px; }
.grid-overlay.off { display: none; }

.preview-empty {
  position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px;
  color: var(--faint); text-align: center; padding: 20px;
}
.preview-empty span { font-size: 44px; color: var(--line-2); }
.preview-empty p { margin: 0; font-size: 13.5px; max-width: 240px; }

.frame-bar { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; gap: 12px; }
.stat-inline { font-family: var(--mono); font-size: 12px; color: var(--muted); text-align: right; }
.stat-inline b { color: var(--accent-2); font-weight: 600; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
@media (max-width: 520px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 13px; }
.stat-k { display: block; font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--faint); margin-bottom: 5px; }
.stat-v { font-family: var(--mono); font-size: 18px; font-weight: 600; color: var(--text); }

/* ---------- Export ---------- */
.export { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.name-row { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.name-row label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); }
.name-row input {
  flex: 1; font-family: var(--mono); font-size: 14px; padding: 8px 10px; background: var(--bg-deep);
  border: 1px solid var(--line-2); border-radius: 7px; color: var(--text);
}
.export-btns { display: grid; grid-template-columns: repeat(2, 1fr); gap: 9px; }
@media (min-width: 560px) { .export-btns { grid-template-columns: repeat(4, 1fr); } }
.btn {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 11px 13px; border-radius: 9px; cursor: pointer; text-align: left;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text); transition: .12s;
}
.btn:hover { border-color: var(--line-2); transform: translateY(-1px); }
.btn strong { font-family: var(--mono); font-size: 14px; }
.btn em { font-style: normal; font-size: 11px; color: var(--faint); }
.btn.primary { background: linear-gradient(180deg, #b571f9, #8f42e0); border-color: #8f42e0; color: var(--ink); }
.btn.primary em { color: rgba(18,6,31,.72); }
.btn.primary:hover { box-shadow: 0 8px 22px rgba(168,85,247,.32); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.export-msg { margin: 12px 2px 0; font-size: 12.5px; font-family: var(--mono); min-height: 16px; }
.export-msg.ok { color: var(--accent-2); }
.export-msg.warn { color: var(--parch); }
.export-msg.err { color: var(--danger); }

/* ---------- Materials ---------- */
.materials { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.mat-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; font-family: var(--mono); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.mat-total { color: var(--accent-2); }
.mat-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 16px; }
.mat-list li { display: flex; align-items: center; gap: 9px; padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.mat-sw { width: 15px; height: 15px; border-radius: 4px; flex: none; border: 1px solid rgba(0,0,0,.4); box-shadow: inset 0 0 0 1px rgba(255,255,255,.06); }
.mat-name { flex: 1; color: var(--text); }
.mat-cnt { font-family: var(--mono); color: var(--muted); font-size: 12.5px; }
.mat-stack { color: var(--faint); font-size: 11px; font-family: var(--mono); margin-left: 6px; }

/* ---------- How-to ---------- */
.howto { max-width: 1240px; margin: 24px auto 0; padding: 30px 22px; border-top: 1px solid var(--line); position: relative; z-index: 1; }
.howto h2 { font-family: var(--mono); font-size: 15px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 0 0 20px; }
.howto-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; }
.howto article { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.howto h3 { margin: 0 0 12px; font-size: 15px; }
.howto h3 span { color: var(--accent); font-size: 12px; font-weight: 400; }
.howto ol { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13.5px; }
.howto li { margin-bottom: 7px; }

.foot { max-width: 1240px; margin: 0 auto; padding: 26px 22px 40px; position: relative; z-index: 1; }
.foot p { margin: 0; font-size: 12px; color: var(--faint); }

/* ---------- Zuschneiden ---------- */
.drop-actions { display: flex; gap: 8px; margin-top: 10px; }

.crop-modal {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background: rgba(6, 9, 6, .74); backdrop-filter: blur(6px);
}
.crop-modal[hidden] { display: none; }
.crop-dialog {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6); width: min(600px, 100%);
  padding: 18px 18px 16px; animation: cropIn .2s ease;
}
@keyframes cropIn { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
.crop-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.crop-head h3 { margin: 0; font-size: 16px; }
.crop-x { background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 14px; }
.crop-x:hover { color: var(--text); border-color: var(--line-2); }
.crop-stage-wrap { display: flex; justify-content: center; background: var(--bg-deep); border: 1px solid var(--line); border-radius: 10px; padding: 16px; overflow: hidden; }
.crop-stage { position: relative; touch-action: none; user-select: none; line-height: 0; }
.crop-stage img { display: block; width: 100%; height: 100%; -webkit-user-drag: none; user-select: none; }
.crop-box {
  position: absolute; cursor: move;
  border: 1.5px solid var(--accent-2);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .55);
}
.ch {
  position: absolute; width: 12px; height: 12px; background: var(--accent-2);
  border: 1px solid var(--ink); border-radius: 2px; z-index: 2;
}
.ch[data-h="nw"] { left: -7px; top: -7px; cursor: nwse-resize; }
.ch[data-h="ne"] { right: -7px; top: -7px; cursor: nesw-resize; }
.ch[data-h="sw"] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.ch[data-h="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.ch[data-h="n"] { left: 50%; top: -7px; transform: translateX(-50%); cursor: ns-resize; }
.ch[data-h="s"] { left: 50%; bottom: -7px; transform: translateX(-50%); cursor: ns-resize; }
.ch[data-h="w"] { left: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.ch[data-h="e"] { right: -7px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.crop-box.locked .ch[data-h="n"], .crop-box.locked .ch[data-h="s"],
.crop-box.locked .ch[data-h="w"], .crop-box.locked .ch[data-h="e"] { display: none; }
.crop-foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.crop-dims { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.crop-actions { display: flex; gap: 8px; margin-left: auto; }
.crop-btn { font-size: 13px; font-weight: 600; padding: 8px 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2); color: var(--text); cursor: pointer; }
.crop-btn:hover { border-color: var(--line-2); }
.crop-btn.primary { background: linear-gradient(180deg, #b571f9, #8f42e0); border-color: #8f42e0; color: var(--ink); }
.crop-btn.primary:hover { box-shadow: 0 8px 22px rgba(168, 85, 247, .32); }

/* ---------- Tutorial ---------- */
.tutorial { max-width: 900px; margin: 6px auto 0; padding: 34px 22px 8px; position: relative; z-index: 1; }
.tut-head { margin-bottom: 22px; }
.tut-eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--accent); }
.tutorial h2 { margin: 8px 0 6px; font-size: 27px; letter-spacing: -.02em; line-height: 1.15; }
.tut-intro { margin: 0; color: var(--muted); font-size: 14.5px; }
.tut-steps { list-style: none; margin: 0; padding: 0; }
.tut-steps li { display: flex; gap: 18px; padding: 16px 0; border-bottom: 1px solid var(--line); }
.tut-steps li:last-child { border-bottom: 0; }
.tut-steps li.key {
  background: linear-gradient(90deg, rgba(168,85,247,.08), rgba(168,85,247,.01) 70%, transparent);
  border-radius: 12px; border-bottom: 0; padding: 16px 16px 16px 14px; margin: 6px -16px 6px -14px;
  box-shadow: inset 2px 0 0 var(--accent);
}
.tut-num {
  flex: none; width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center;
  font-family: var(--mono); font-size: 17px; font-weight: 700; color: var(--ink);
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  box-shadow: 0 6px 16px rgba(168,85,247,.22);
}
.tut-txt { min-width: 0; }
.tut-txt h3 { margin: 7px 0 5px; font-size: 16px; display: flex; align-items: center; gap: 10px; }
.tut-txt p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.62; }
.tut-txt strong { color: var(--text); font-weight: 600; }
.tut-badge {
  font-family: var(--mono); font-size: 9.5px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--ink); background: var(--accent); padding: 2px 7px; border-radius: 5px; font-weight: 700;
}
.tut-tip {
  margin: 20px 0 0; padding: 14px 16px; border-radius: 10px; font-size: 13.5px; color: var(--muted);
  background: var(--panel); border: 1px solid var(--line);
}
.tut-tip strong { color: var(--accent-2); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
