:root {
  --void: #030201;
  --panel: rgba(12, 9, 6, .94);
  --panel2: rgba(25, 18, 11, .94);
  --gold: #c99a45;
  --gold2: #f3d38a;
  --line: rgba(212, 163, 73, .34);
  --paper: #d8bd82;
  --ink: #2b2116;
  --text: #efe1bd;
  --muted: rgba(239, 225, 189, .68);
  --danger: #b96153;
  --serif: Georgia, Cambria, "Times New Roman", serif;
  --sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  color: var(--text);
  font-family: var(--sans);
  background:
    radial-gradient(circle at 50% 0%, rgba(201,154,69,.15), transparent 34%),
    radial-gradient(circle at 18% 68%, rgba(113,54,211,.11), transparent 36%),
    linear-gradient(180deg, #080604, #020101 70%, #000);
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.map-app {
  height: 100vh;
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 300px;
  grid-template-rows: 82px minmax(0, 1fr) 36px;
  gap: 8px;
  padding: 8px;
  background-image:
    linear-gradient(90deg, rgba(201,154,69,.04) 1px, transparent 1px),
    linear-gradient(0deg, rgba(201,154,69,.035) 1px, transparent 1px);
  background-size: 88px 88px;
}

.app-topbar,
.panel,
.statusbar,
.canvas-frame {
  border: 1px solid var(--line);
  box-shadow: 0 18px 50px rgba(0,0,0,.48), inset 0 0 0 1px rgba(255,255,255,.035);
  background:
    linear-gradient(180deg, rgba(31,23,14,.96), rgba(8,7,5,.96));
}

.app-topbar {
  grid-column: 1 / -1;
  grid-row: 1;
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
  padding: 9px 13px;
  border-radius: 14px;
  position: relative;
  overflow: hidden;
}
.app-topbar::before,
.panel::before {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(243,211,138,.65), transparent);
  pointer-events: none;
}
.crest {
  width: 58px;
  height: 58px;
  border-radius: 16px;
  display: grid;
  place-items: center;
  position: relative;
  flex: 0 0 auto;
  color: #251506;
  text-decoration: none;
  background: radial-gradient(circle at 45% 25%, #ffe2a1, #bd8736 52%, #3b250f 100%);
  border: 1px solid rgba(255,232,171,.58);
  box-shadow: 0 8px 24px rgba(0,0,0,.45), inset 0 0 18px rgba(255,239,180,.25);
}
.crest-icon { position: absolute; opacity: .24; font-size: 48px; transform: rotate(45deg); }
.crest-a { font-family: var(--serif); font-weight: 900; font-size: 32px; z-index: 1; }
.title-block { min-width: 260px; flex: 0 0 auto; }
.title-block p {
  margin: 0 0 2px;
  color: rgba(243,211,138,.72);
  font-family: var(--serif);
  font-size: 11px;
  letter-spacing: .28em;
}
.title-block h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(22px, 2.4vw, 36px);
  font-weight: 700;
  letter-spacing: .075em;
  color: #f3dfac;
  text-shadow: 0 7px 24px rgba(0,0,0,.72);
  white-space: nowrap;
}
.top-actions {
  min-width: 0;
  flex: 1;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}
.top-actions button,
.tool-btn,
.ink-row button,
.grid-row button,
.file-row button,
.file-button,
.seed-row button,
.input-row button {
  min-height: 38px;
  padding: 0 13px;
  border-radius: 10px;
  color: var(--text);
  border: 1px solid rgba(201,154,69,.25);
  background: linear-gradient(180deg, rgba(50,37,20,.88), rgba(14,10,6,.92));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
}
.top-actions button:hover,
.tool-btn:hover,
.ink-row button:hover,
.grid-row button:hover,
.file-row button:hover,
.file-button:hover,
.seed-row button:hover,
.input-row button:hover {
  border-color: rgba(243,211,138,.55);
  color: #fff2c6;
  background: linear-gradient(180deg, rgba(76,52,22,.94), rgba(18,12,7,.96));
}
.top-actions .gold-action {
  color: #2b1705;
  font-weight: 800;
  background: linear-gradient(180deg, #f7cc72, #a66f20);
  border-color: rgba(255,227,150,.72);
}
.top-actions .round-action {
  width: 42px;
  padding: 0;
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
}

.panel {
  position: relative;
  min-height: 0;
  padding: 14px;
  overflow: auto;
  scrollbar-width: thin;
  border-radius: 14px;
}
.left-panel { grid-column: 1; grid-row: 2; }
.right-panel { grid-column: 3; grid-row: 2; }
.panel-title {
  margin: 0 0 14px;
  text-align: center;
  font-family: var(--serif);
  font-size: 18px;
  letter-spacing: .16em;
  color: var(--gold2);
  text-transform: uppercase;
}
.template-card,
.brush-card,
.hint-card,
.setting-block {
  border: 1px solid rgba(201,154,69,.22);
  border-radius: 13px;
  padding: 12px;
  margin-bottom: 12px;
  background: linear-gradient(180deg, rgba(0,0,0,.20), rgba(255,255,255,.025));
}
label, .setting-block h2 {
  display: block;
  margin: 0 0 8px;
  color: #dec58a;
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.setting-block h2 { margin-bottom: 10px; }
input, select {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  margin-bottom: 10px;
  color: #f5e8c8;
  border: 1px solid rgba(201,154,69,.28);
  border-radius: 9px;
  background: rgba(3,2,1,.62);
  outline: none;
}
input:focus, select:focus { border-color: rgba(243,211,138,.70); box-shadow: 0 0 0 3px rgba(201,154,69,.13); }
.seed-row, .input-row { display: grid; gap: 8px; }
.seed-row { grid-template-columns: 1fr 42px; }
.input-row { grid-template-columns: 1fr 66px; }
.seed-row input, .input-row input { margin: 0; }
.seed-row button,
.input-row button { min-height: 38px; padding: 0; }
.tool-list { display: grid; gap: 7px; margin-bottom: 12px; }
.tool-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  justify-content: flex-start;
  font-weight: 700;
}
.tool-btn span {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  color: #120b04;
  background: linear-gradient(180deg, #f0d28d, #8c6729);
}
.tool-btn.active {
  border-color: rgba(255,227,150,.72);
  box-shadow: 0 0 0 2px rgba(201,154,69,.12), inset 0 0 18px rgba(201,154,69,.10);
  color: #fff1bd;
}
.tool-btn.danger span { background: linear-gradient(180deg, #f0aaa0, #8d3e34); }
.hint-card strong { display: block; color: var(--gold2); font-family: var(--serif); letter-spacing: .08em; margin-bottom: 6px; }
.hint-card span, .mini-tips p { color: var(--muted); font-size: 13px; line-height: 1.45; }

.canvas-stage {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  min-height: 0;
  position: relative;
  display: grid;
  place-items: center;
  overflow: auto;
  border-radius: 14px;
  background:
    radial-gradient(circle at center, rgba(201,154,69,.08), transparent 55%),
    rgba(0,0,0,.26);
}
.canvas-frame {
  position: relative;
  border-radius: 12px;
  padding: 10px;
  transform: scale(var(--zoom, 1));
  transform-origin: center center;
  transition: transform .12s ease;
}
#mapCanvas {
  display: block;
  width: min(100%, 1120px);
  max-width: calc(100vw - 590px);
  height: auto;
  aspect-ratio: 4 / 3;
  border-radius: 7px;
  border: 1px solid rgba(35,24,10,.9);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.10), 0 18px 70px rgba(0,0,0,.62);
  cursor: crosshair;
  touch-action: none;
}
.canvas-toast {
  position: absolute;
  left: 18px;
  bottom: 18px;
  max-width: 360px;
  padding: 10px 13px;
  border: 1px solid rgba(201,154,69,.3);
  border-radius: 10px;
  color: #f5e8c8;
  background: rgba(7,5,3,.78);
  box-shadow: 0 12px 30px rgba(0,0,0,.4);
  pointer-events: none;
  opacity: .94;
}

.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.swatch {
  height: 42px;
  border-radius: 8px;
  border: 1px solid rgba(201,154,69,.28);
  box-shadow: inset 0 0 14px rgba(0,0,0,.18);
}
.swatch.active,
.ink-row button.active,
.grid-row button.active {
  outline: 2px solid rgba(255,214,121,.72);
  border-color: rgba(255,214,121,.88);
}
.p-classic { background: #d8bd82; }
.p-ivory { background: #ead9a6; }
.p-sand { background: #c79b5f; }
.p-ember { background: #aa7540; }
.p-night { background: #3a3027; }
.ink-row, .grid-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.grid-row { grid-template-columns: repeat(4, 1fr); }
.ink-row button, .grid-row button { min-height: 36px; padding: 0 8px; font-size: 12px; }
.two-col { display: grid; grid-template-columns: 1fr; gap: 10px; }
.two-col label { margin: 0; }
input[type="range"] { padding: 0; accent-color: #c99a45; background: transparent; border: 0; height: 26px; margin: 4px 0 0; }
.layer-list { display: grid; gap: 7px; }
.layer-list label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  padding: 8px 10px;
  border-radius: 9px;
  border: 1px solid rgba(201,154,69,.18);
  background: rgba(0,0,0,.18);
  font-family: var(--sans);
  letter-spacing: 0;
  text-transform: none;
  color: var(--text);
}
.layer-list input { width: auto; height: auto; margin: 0; accent-color: #c99a45; }
.file-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.file-row button, .file-button { display: grid; place-items: center; text-align: center; text-decoration: none; margin: 0; font-family: var(--sans); text-transform: none; letter-spacing: 0; }
.file-button input { display: none; }

.statusbar {
  grid-column: 1 / -1;
  grid-row: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
  padding: 0 14px;
  border-radius: 12px;
  color: rgba(239,225,189,.75);
  font-size: 13px;
}
.statusbar span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 1180px) {
  .map-app { grid-template-columns: 224px minmax(0, 1fr) 254px; }
  .title-block { min-width: 210px; }
  .top-actions { gap: 5px; }
  .top-actions button { padding: 0 9px; font-size: 12px; }
  #mapCanvas { max-width: calc(100vw - 520px); }
}

@media (max-width: 880px) {
  html, body { overflow: auto; }
  .map-app {
    height: auto;
    min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(420px, 65vh) auto auto;
    overflow: visible;
  }
  .app-topbar, .left-panel, .right-panel, .canvas-stage, .statusbar { grid-column: 1; }
  .app-topbar { grid-row: 1; flex-wrap: wrap; }
  .title-block { min-width: 0; flex: 1; }
  .title-block h1 { white-space: normal; font-size: 22px; }
  .top-actions { justify-content: flex-start; flex-wrap: wrap; }
  .left-panel { grid-row: 2; max-height: none; }
  .canvas-stage { grid-row: 3; overflow: auto; }
  .right-panel { grid-row: 4; }
  .statusbar { grid-row: 5; }
  .tool-list { grid-template-columns: repeat(2, 1fr); }
  #mapCanvas { width: min(100%, 760px); max-width: calc(100vw - 50px); }
}


/* V199 polish: clearer interaction states */
.tool-btn[data-tool="eraser"].active {
  border-color: rgba(255,128,100,.82);
  box-shadow: inset 0 0 0 1px rgba(255,128,100,.25), 0 0 18px rgba(185,97,83,.18);
}
.canvas-frame::after {
  content: "Drag to draw · Eraser removes generated + custom pieces";
  position: absolute;
  right: 14px;
  top: 14px;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid rgba(201,154,69,.25);
  background: rgba(7,5,3,.58);
  color: rgba(239,225,189,.72);
  font-size: 12px;
  pointer-events: none;
}
@media (max-width: 880px) {
  .canvas-frame::after { display: none; }
  .tool-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel { padding: 10px; }
}
