:root {
  color: #1c1915;
  background: #f3efe6;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
}

header {
  display: flex;
  align-items: end;
  padding: 16px 20px 8px;
}

h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

header p {
  margin: 4px 0 0;
  color: #5c564c;
}

main {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 12px;
  height: calc(100vh - 78px);
  padding: 8px 16px 16px;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  min-height: 0;
}

.view-tools button {
  border: 1px solid #c9c1b3;
  background: #fffdf8;
  color: inherit;
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.view-tools button.active {
  background: #173f34;
  color: #f3efe6;
  border-color: #173f34;
}

.map-frame {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

#map {
  min-width: 0;
  min-height: 0;
  height: 100%;
  border-radius: 12px;
  background: #d9d3c7;
  overflow: hidden;
}

#map-menu {
  position: absolute;
  z-index: 5;
  display: grid;
  min-width: 132px;
  padding: 6px;
  border: 1px solid #c9c1b3;
  border-radius: 10px;
  background: #fffdf8;
  box-shadow: 0 8px 24px rgba(28, 25, 21, 0.16);
}

#map-menu[hidden] { display: none; }

#map-menu button {
  border: 0;
  background: transparent;
  color: inherit;
  border-radius: 6px;
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
}

#map-menu button:hover { background: #efe8dc; }

#preview {
  position: relative;
  flex: 1 1 58%;
  min-height: 240px;
  border-radius: 12px;
  background: #e4ddd0;
  overflow: hidden;
}

aside {
  flex: 1 1 42%;
  min-height: 0;
  overflow: auto;
  padding-right: 4px;
}

fieldset {
  border: 0;
  margin: 0 0 14px;
  padding: 0;
}

legend {
  font-size: 13px;
  margin-bottom: 8px;
}

.shapes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

button, a {
  font: inherit;
}

.shapes button,
#generate,
.downloads a {
  border: 1px solid #c9c1b3;
  background: #fffdf8;
  color: inherit;
  border-radius: 8px;
  padding: 8px 10px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.shapes button.active {
  background: #173f34;
  color: #f3efe6;
  border-color: #173f34;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 14px;
}

label span {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  color: #5c564c;
}

input[type="number"] {
  width: 88px;
  font: inherit;
  padding: 4px 6px;
  border: 1px solid #c9c1b3;
  border-radius: 6px;
  background: #fffdf8;
}

.hint, .fineprint, #status {
  color: #5c564c;
  font-size: 13px;
  line-height: 1.45;
}

#generate {
  width: 100%;
  background: #0f6e56;
  color: #f6f3ec;
  border-color: #0f6e56;
  padding: 10px 12px;
}

#generate:disabled {
  opacity: 0.55;
  cursor: wait;
}

.warning {
  background: #fff4d8;
  border: 1px solid #e2c98a;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
}

dl {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 4px 8px;
  margin: 12px 0;
  font-size: 13px;
}

dt { color: #5c564c; }
dd { margin: 0; }

.downloads {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

#preview canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

#preview-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 24px;
  text-align: center;
  color: #5c564c;
  font-size: 14px;
  pointer-events: none;
}

#preview-empty[hidden] {
  display: none;
}

.view-tools {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.fineprint {
  word-break: break-word;
}

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
    height: auto;
  }

  .map-frame { height: 62vh; }
  #preview { height: 46vh; flex: none; }
}
