/* One control panel owns every map setting; the map owns only its preview and status. */
:root{color-scheme:dark;--bg:#24190f;--panel:var(--cc-steel);--line:#61717a;--text:#f4ebd8;--muted:#d0d5cf;--accent:var(--cc-gold);--cell-size:64px}
*{box-sizing:border-box}
body{margin:0;color:var(--text);font:15px/1.5 var(--font-ui);background:repeating-linear-gradient(97deg,#ffffff04 0 2px,#00000008 2px 5px,transparent 5px 12px),radial-gradient(ellipse at 50% 20%,#413022,#21170f 85%)}
[hidden]{display:none!important}
h1,h2{font-family:var(--font-heading)}
h2{font-size:22px;line-height:1.15;font-weight:800;letter-spacing:.5px;text-transform:uppercase;color:#f7eedb;margin:0 0 12px}
p{white-space:pre-line;line-height:1.5}
button,input,select,textarea{font:inherit;border:1px solid var(--line);border-radius:4px;padding:9px}
button{cursor:pointer;min-height:44px;font-weight:650;color:#eadfc9;background:linear-gradient(#354651,#25343e);box-shadow:0 2px 0 #0e161c}
button:hover:not(:disabled){background:#435561;border-color:#e8b041}
button:disabled{opacity:.5;cursor:default;box-shadow:none}
button.primary{border-color:#78321d;border-top-color:#df8454;background:linear-gradient(#c95b32,#a94022);color:#fff5dd;box-shadow:inset 0 1px #ed9d6766,0 3px 0 #602712}
button.primary:hover:not(:disabled){background:#d56539}
label{display:flex;flex-direction:column;gap:4px;min-width:0}
label>span{font-size:12px;font-weight:700;letter-spacing:.8px;text-transform:uppercase;color:#d2c6b1}
input,select,textarea{width:100%;min-width:0;min-height:44px;border-color:var(--cc-line);background:var(--cc-paper-texture),linear-gradient(#f7eedb,#e7d8b9);color:var(--cc-ink);box-shadow:inset 0 1px #fff8e6}
textarea{resize:vertical}
select{appearance:none;padding-right:32px;background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%235a4a3a' stroke-width='2'/%3E%3C/svg%3E"),var(--cc-paper-texture),linear-gradient(#f7eedb,#e7d8b9);background-position:right 11px center,0 0,0 0;background-repeat:no-repeat}
select option{background:#efe4cc;color:#2b2117}
input[type=checkbox]{width:18px;height:18px;min-height:18px;accent-color:#c95b32;box-shadow:none}
.check{flex-direction:row;align-items:center;gap:8px;min-height:44px}
:focus-visible{outline:3px solid #ffb354;outline-offset:3px}

/* Shared envelope and command-centre typography. */
header.editor-topbar{max-width:1600px;width:calc(100% - 24px);margin:auto;display:flex;align-items:center;justify-content:space-between;gap:16px;min-height:76px;padding:12px 24px;border:1px solid #56616a;border-bottom:3px solid #0c1116;border-radius:0 0 6px 6px;background:var(--cc-rivets),linear-gradient(#2e3b46,#172027);box-shadow:inset 0 1px #63707a,0 5px 16px #0005}
.editor-brand{display:flex;align-items:center;gap:12px;min-width:0}
.editor-brand .logo-star{font-size:30px;line-height:1;color:#ff9f56}
.editor-brand .brand-name{font:900 30px/1 var(--font-heading);letter-spacing:.5px;color:#f7eedb;white-space:nowrap}
.editor-brand .brand-name b{font-weight:900;color:#ffad63}
.editor-brand .brand-sep{align-self:stretch;width:1px;margin:4px 2px;background:#5b6c74}
header.editor-topbar h1{margin:0;font:800 26px/1 var(--font-heading);letter-spacing:.5px;text-transform:uppercase;color:var(--cc-gold);white-space:nowrap}
.editor-header-tools{display:flex;align-items:center;gap:10px;margin-left:auto}
header.editor-topbar .tool-button,header.editor-topbar select{height:44px;min-height:44px;margin:0;font:600 14px/1.2 var(--font-ui)}
header.editor-topbar .tool-button{display:inline-flex;align-items:center;justify-content:center;gap:8px;padding:0 14px;border:1px solid #66717a;border-radius:4px;background:linear-gradient(#384854,#23313c);color:#f7eedb;text-decoration:none;white-space:nowrap;box-shadow:0 2px 0 #0e161c}
header.editor-topbar .tool-button:hover{border-color:#e8b041;background:#435561}
header.editor-topbar select{width:auto;min-width:128px;padding:0 34px 0 12px}
#feedback-editor-open .feedback-icon{display:none;flex:none}
main,#test-panel{max-width:1600px;width:calc(100% - 24px);margin:auto;padding:20px 0}
.intro{margin:0 0 8px;color:var(--muted)}
.editor-guide{margin:0 0 12px}
.editor-guide>summary{cursor:pointer;min-height:44px;display:flex;align-items:center;font-weight:700;color:var(--accent)}
.steps{display:flex;gap:12px;list-style:none;padding:0;margin:8px 0 16px;counter-reset:step}
.steps li{display:flex;align-items:flex-start;gap:10px;flex:1;padding:12px 14px;border:1px solid #56616a;border-radius:6px;background:var(--panel);color:#e6dcc6;counter-increment:step}
.steps li::before{content:counter(step);flex:none;display:grid;place-items:center;width:26px;height:26px;border-radius:50%;background:#a84326;color:#fff5dd;font:800 15px/1 var(--font-heading)}

/* A single scroll area for settings, with Undo/Test outside that scroll area. */
.workspace{display:grid;grid-template-columns:clamp(320px,28vw,390px) minmax(0,1fr);gap:16px;align-items:start}
.editor-controls,.map-panel{min-width:0;border:1px solid #56616a;border-bottom:3px solid #0d141a;border-radius:6px;background:linear-gradient(#293741,#172027);box-shadow:0 4px 12px #0004}
.editor-controls{position:sticky;top:12px;display:flex;flex-direction:column;max-height:calc(100dvh - 24px)}
.editor-controls>h2{flex:none;margin:0;padding:14px 12px;border-bottom:1px solid #56616a}
.editor-sections{flex:1;min-height:0;overflow:auto;overscroll-behavior:contain;scrollbar-width:thin;scroll-padding:12px}
.editor-sections>details{margin:0;padding:0;border:0;border-bottom:1px solid #56616a}
.editor-sections>details>summary{cursor:pointer;list-style:none;display:flex;align-items:center;gap:8px;min-height:48px;padding:10px 12px;color:#f0c46b;font:800 17px/1.3 var(--font-heading);letter-spacing:.5px;text-transform:uppercase}
.editor-sections>details>summary::-webkit-details-marker{display:none}
.editor-sections>details>summary::before{content:"▸";flex:none;font-size:15px}
.editor-sections>details[open]>summary::before{transform:rotate(90deg)}
.editor-sections>details>summary:hover{background:#435561}
.palette-panel,.toolbar,.view-options,.validation-body{padding:0 12px 12px}
.palette-panel,.view-options{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;align-items:end}
.palette-panel label>span,.view-options label>span{min-height:2.8em;line-height:1.4}
.palette-panel p,.notice,.generator-note,.validation-body p{margin:4px 0;color:var(--muted);font-size:13px}
.palette-panel>p,.palette{grid-column:1/-1}
.palette{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:7px;margin:4px 0}
.palette button{min-width:0;display:flex;flex-direction:column;align-items:center;gap:5px;padding:5px;font-size:11px;font-weight:600;color:var(--cc-ink);border-color:var(--cc-line);background:var(--cc-paper-texture),linear-gradient(#f7eedb,#e7d8b9)}
.palette canvas{width:52px;height:52px;max-width:100%}
.palette span{overflow-wrap:anywhere}
.palette button:hover:not(:disabled){background:#f5e5c6;color:#2b2117}
.palette button[aria-pressed=true]{background:#f5dba0;border-color:#f3b75e;box-shadow:inset 0 0 0 2px #875223,0 0 0 2px #f3b75e}
.toolbar{display:grid;gap:12px}
.dimension-tools,.template-tools,.file-actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px;align-items:end}
.generator-note,.template-tools label{grid-column:1/-1}
.random-controls{grid-column:1/-1;display:grid;gap:8px;padding-top:8px;border-top:1px solid var(--line)}
.random-controls label,.random-map-code{display:grid;gap:4px;min-width:0}
#random-test-tools:not([hidden]){display:grid;gap:6px;margin:6px 0}
.random-test-info{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:6px 12px}
.random-map-code{grid-template-columns:auto minmax(0,17ch);align-items:center}
.random-map-code input{min-width:0}
.dimension-tools button,.template-tools button,.file-actions button{min-width:0;width:100%;padding:8px;white-space:normal}
.template-tools button{grid-column:1/-1}
.mission-options>label,.mission-options>.hold-options>label{margin:0 12px 12px}
/* Réglages du siège : affichés seulement en mode Siège, alignés sur les autres champs. */
.hold-options:not([hidden]){display:contents}
/* Aides glissées entre les champs : même retrait que les champs, jamais collées au bord. */
.mission-options>p{margin:-4px 12px 12px;color:var(--muted);font-size:13px;line-height:1.4}
.editor-handicap{min-width:0;margin:0 12px 12px;padding:0;border:0}
.editor-handicap legend{padding:0;font-weight:700}
.editor-handicap-fields{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:6px;margin-top:6px}
.editor-handicap-fields label{min-width:0;justify-content:space-between}
.editor-handicap-fields input{box-sizing:border-box;width:100%;min-width:0;min-height:44px}
#editor-custom-rules #handicap-error{color:#ffb5a2}
#problems{padding-left:20px;font-size:13px}
#problems .error{color:#ffb5a2}
#problems .warning{color:#f5d085}

/* The preview contains no configuration controls. Map cells remain square. */
.map-panel{position:sticky;top:12px;padding:16px}
.map-heading,.test-header{display:flex;justify-content:space-between;align-items:center;gap:12px}
.map-heading{padding-bottom:12px;border-bottom:1px solid #56616a;margin-bottom:12px}
.map-heading h2{margin:0;overflow-wrap:anywhere}
#dimensions{flex:none;font-variant-numeric:tabular-nums}
.playability{display:flex;align-items:baseline;flex-wrap:wrap;gap:4px 12px;margin:0 0 12px;padding:10px 12px;border:1px solid #576763;border-left:4px solid #7aac7b;border-radius:4px;background:#1b2b28}
.playability strong{font:800 16px/1.3 var(--font-heading);color:#b7d7a4}
.playability span{font-size:13px;color:#e1ddcb}
.playability[data-state=incomplete]{background:#30281d;border-color:#85704a;border-left-color:#ddb267}
.playability[data-state=incomplete] strong{color:#f2cf8a}
.map-scroll{display:flex;overflow:auto;max-height:70dvh;border:1px solid #637589;border-radius:4px}
/* Petite carte sur grand écran : la grille se centre au lieu de laisser une bande vide à droite. */
.map-scroll>#grid{margin:auto}
#grid{display:grid;width:max-content;gap:0;padding:0;background-color:#182a3c;background-repeat:no-repeat}
.cell{position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;width:var(--cell-size);height:var(--cell-size);min-height:var(--cell-size);padding:2px;border:1px solid #15273855;border-radius:0;background:transparent;color:white;font-size:12px;text-shadow:0 1px 3px #000;box-shadow:none;touch-action:manipulation}
.cell:hover:not(:disabled){background:transparent;box-shadow:inset 0 0 0 3px #ffdd87}
.cell:focus-visible{outline-offset:-4px}
.cell .coord{position:absolute;left:3px;top:1px;font-size:9px;background:#102134b0;color:#fff;border-radius:3px;padding:0 2px}
.cell .model-label{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%)}
.cell.red{box-shadow:inset 0 -3px #ed663f}
.cell.blue{box-shadow:inset 0 -3px #4086bd}
.cell.neutral{box-shadow:inset 0 -3px #8d9a9b}
.map-status{display:flex;flex-wrap:wrap;gap:4px 16px;padding:10px 0 0;color:var(--muted);font-size:13px}
.map-status p{margin:0}
#test-panel iframe{width:100%;height:80dvh;border:1px solid var(--line);background:#101c2a}
#test-panel>p{color:var(--muted)}

@media(max-width:1599px){#feedback-editor-open{width:44px;padding:0}#feedback-editor-open .feedback-icon{display:block}#feedback-editor-open .feedback-label{display:none}}
@media(max-width:800px){
 header.editor-topbar{flex-wrap:wrap;width:calc(100% - 16px);padding:10px 12px;gap:10px}
 .editor-brand{flex:1 1 100%;gap:8px}
 .editor-brand .logo-star{font-size:24px}
 .editor-brand .brand-name{font-size:24px}
 header.editor-topbar h1{font-size:21px}
 .editor-header-tools{flex:1 1 100%;margin-left:0}
 .editor-header-tools .home-link{flex:1}
 header.editor-topbar select{min-width:116px}
 main,#test-panel{width:calc(100% - 16px);padding-top:14px}
 .workspace{grid-template-columns:minmax(0,1fr);gap:12px}
 .editor-controls,.map-panel{position:static}
 .editor-controls{max-height:none}
 .editor-sections{overflow:visible}
 .palette{display:flex;overflow-x:auto;gap:8px;padding:3px;margin:1px -3px;scrollbar-width:thin}
 .palette button{flex:0 0 84px}
 .palette canvas{width:60px;height:60px}
 .map-panel{padding:12px}
 .map-scroll{max-height:50dvh}
 .map-heading h2{font-size:20px}
 .steps{flex-direction:column;gap:6px}
 .steps li{padding:8px 10px}
}
@media(max-width:480px){
 .editor-brand{gap:8px}
 .editor-brand .logo-star{display:none}
 .editor-brand .brand-name{font-size:21px}
 header.editor-topbar h1{min-width:0;white-space:normal;font-size:19px}
 .editor-header-tools{gap:6px}
 header.editor-topbar .home-link{padding:0 8px;font-size:13px;white-space:normal;text-align:center}
 header.editor-topbar select{min-width:106px;padding-left:8px}
}
/* Phone in landscape: the test game takes the whole screen, with only the Return row above it,
   so the confirmation and the end-turn button stay reachable without scrolling the editor page. */
@media(orientation:landscape) and (max-height:520px){
 #test-panel:not([hidden]){position:fixed;inset:0;z-index:20;display:flex;flex-direction:column;gap:6px;width:auto;max-width:none;margin:0;padding:6px 8px;background:#21170f}
 #test-panel .test-header h2{margin:0;font-size:18px}
 #test-panel>p{display:none}
 #test-panel iframe{flex:1;height:auto;min-height:0}
}
/* Compact authored weather calendar: all controls remain within the mission column on phones. */
.weather-row{display:grid;grid-template-columns:minmax(62px,1fr) minmax(100px,2fr) 44px;gap:8px;align-items:end;margin-block:8px}
.weather-row label{min-width:0;margin:0}.weather-row input,.weather-row select{min-width:0;width:100%}
.weather-row button{min-width:44px;min-height:44px;padding:4px}

#editor-restrictions .restriction-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:0 8px;padding:0 12px 8px}
#editor-restrictions .restriction-check{flex-direction:row;align-items:center;gap:7px;min-height:44px}
#editor-restrictions .restriction-check input{flex:none;margin:0}
#editor-restrictions .restriction-check span{min-width:0;overflow-wrap:anywhere}

.palette-panel label:has(#layer){grid-column:1/-1}
.palette-panel label:has(#layer) .seg-group{display:grid;grid-auto-flow:row;grid-template-columns:repeat(2,minmax(0,1fr));grid-template-rows:repeat(2,auto);gap:6px}
.palette-panel label:has(#layer) .seg-group button{min-height:44px;white-space:normal}
.palette-panel label:has(#layer) .seg-group button[aria-pressed=true],.palette-panel label:has(#layer) .seg-group button[aria-pressed=true]:hover{background:#20364b;color:#fff5dd}
