:root {
  color-scheme: dark;
  --gold: #d6a84e;
  --gold-light: #f2d384;
  --ink: #f5eddc;
  --muted: #aaa08e;
  --panel: #211d15;
  --line: #5f4b2c;
  font-family: system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { min-width: 320px; min-height: 100%; margin: 0; background: #11100c; color: var(--ink); }
body { min-height: 100vh; background: radial-gradient(circle at 50% -20%, #493a22, #11100c 55%); }
button, input, .button { font: inherit; }
button, .button { min-height: 2.55rem; border: 1px solid #72572d; border-radius: 2px; padding: .45rem .75rem; color: #e9ddc5; background: linear-gradient(#3b3020, #251e16); cursor: pointer; }
button:hover, .button:hover, button.active { border-color: var(--gold); color: var(--gold-light); }
button:disabled { opacity: .4; cursor: default; }
.primary { border-color: #d0a04b; background: linear-gradient(#8c3d27, #5e251b); color: white; }
.danger { width: 100%; margin-top: .8rem; border-color: #75372e; }
.kicker { display: block; color: var(--gold); font-size: .65rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }

.editor-header { min-height: 5rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem 1.1rem; border-bottom: 1px solid var(--line); background: rgba(20,18,13,.93); }
.editor-header h1 { margin: .12rem 0 0; color: var(--gold-light); font: 1.55rem Georgia,serif; }
.header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .45rem; }
.button { display: inline-flex; align-items: center; text-decoration: none; }

.editor-layout { height: calc(100vh - 5rem); min-height: 34rem; display: grid; grid-template-columns: 13rem minmax(20rem,1fr) 15rem; gap: .6rem; padding: .6rem; }
.panel { min-width: 0; border: 1px solid #3e3425; background: rgba(30,27,20,.96); box-shadow: 0 .5rem 1.5rem rgba(0,0,0,.22); }
.palette, .properties { overflow-y: auto; padding: 1rem; }
.panel h2 { margin: .15rem 0 1rem; color: var(--gold-light); font: 1.25rem Georgia,serif; }
.palette > p { color: var(--muted); font-size: .77rem; line-height: 1.45; }
.palette-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .45rem; }
.palette-grid button { height: 6.4rem; display: grid; place-items: center; align-content: center; gap: .25rem; padding: .35rem; }
.palette-grid img { width: 3.8rem; height: 3.8rem; object-fit: contain; pointer-events: none; }
.palette-grid span { font-size: .72rem; pointer-events: none; }
.status { min-height: 3rem; margin-top: 1rem !important; padding: .65rem; border-left: 2px solid var(--gold); background: #17140f; }

.workspace { display: grid; grid-template-rows: auto minmax(0,1fr) auto; overflow: hidden; padding: .55rem; }
.device-bar { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem; padding: .25rem .2rem .65rem; }
.device-bar button { min-height: 2.2rem; padding: .35rem .55rem; font-size: .72rem; }
.viewport-host { position: relative; min-height: 0; display: grid; place-items: center; overflow: hidden; border: 1px dashed #4f432f; background: #0d0c09; }
.viewport-frame { position: relative; overflow: hidden; border: 2px solid #ae8542; background: #435027; box-shadow: 0 0 0 .35rem #15130f, 0 1rem 2rem #000; }
.editor-world { position: absolute; transform-origin: 0 0; background: center/100% 100% no-repeat url("../assets/battlefield.webp"); touch-action: none; user-select: none; }
.scene-object { position: absolute; transform: translate(-50%,-78%); transform-origin: 50% 78%; object-fit: contain; filter: drop-shadow(0 .3rem .25rem rgba(0,0,0,.4)); cursor: grab; touch-action: none; user-select: none; }
.scene-object.unit { transform: translate(-50%,-65%); }
.scene-object.selected { outline: 3px solid #f3d47d; outline-offset: 3px; filter: drop-shadow(0 0 .45rem #f0c85e); }
.scene-object.enemy { filter: sepia(.2) hue-rotate(120deg) saturate(.7) drop-shadow(0 .3rem .25rem rgba(0,0,0,.4)); }
.preview-hud { position: absolute; z-index: 4; top: .35rem; left: .35rem; right: .35rem; min-height: 2rem; display: flex; align-items: center; gap: .45rem; padding: .25rem .45rem; border: 1px solid rgba(230,190,99,.4); background: rgba(22,18,12,.82); pointer-events: none; }
.preview-hud span { display: grid; place-items: center; width: 1.55rem; height: 1.55rem; border: 1px solid var(--gold); border-radius: 50%; color: var(--gold-light); font-size: .45rem; }
.preview-hud strong { color: #eadcbf; font: .68rem Georgia,serif; text-transform: uppercase; }
.viewport-label { margin: .55rem 0 0; color: var(--muted); text-align: center; font-size: .72rem; }

#properties-form { display: grid; gap: .75rem; }
#properties-form label { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .5rem; color: var(--muted); font-size: .74rem; }
#properties-form input[type="text"], #properties-form input[type="number"] { width: 100%; min-width: 0; border: 1px solid #554832; padding: .5rem; color: var(--ink); background: #13110d; }
#properties-form input[type="range"] { grid-column: 1/-1; width: 100%; accent-color: var(--gold); }
#properties-form output { color: var(--gold-light); }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.field-pair label { display: block !important; }
.field-pair input { margin-top: .25rem; }
.scene-info { display: grid; grid-template-columns: 1fr auto; gap: .45rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid #413622; font-size: .72rem; }
.scene-info span { color: var(--muted); }
.scene-info strong { color: var(--gold-light); }

@media (max-width: 980px) {
  .editor-header { align-items: flex-start; }
  .editor-layout { height: auto; min-height: calc(100vh - 5rem); grid-template-columns: 10rem minmax(0,1fr); }
  .properties { grid-column: 1/-1; display: grid; grid-template-columns: 12rem minmax(0,1fr) 12rem; gap: 1rem; }
  #properties-form { grid-template-columns: repeat(3, minmax(0,1fr)); align-items: end; }
  .workspace { min-height: 34rem; }
}

@media (max-width: 650px) {
  .editor-header { display: block; }
  .header-actions { justify-content: flex-start; margin-top: .7rem; }
  .editor-layout { display: flex; flex-direction: column; padding: .35rem; }
  .palette-grid { grid-template-columns: repeat(3,1fr); }
  .palette-grid button { height: 5.2rem; }
  .palette-grid img { width: 2.8rem; height: 2.8rem; }
  .workspace { min-height: 33rem; order: -1; }
  .properties { display: block; }
}
