:root {
  --ink: #f5f1df;
  --muted: #c9c0a7;
  --panel: rgba(16, 20, 17, 0.92);
  --line: rgba(245, 241, 223, 0.16);
  --accent: #d6a64a;
  --blue: #6bbcff;
  --good: #56dc82;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #132118;
  color: var(--ink);
  font-family: Dotum, "돋움", "Malgun Gothic", sans-serif;
}

#worldEditorCanvas {
  position: fixed;
  inset: 0;
  display: block;
  width: 100vw;
  height: 100vh;
  outline: none;
  touch-action: none;
}

.world-editor-panel {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 5;
  width: min(320px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  overflow-x: hidden;
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(12px);
}

.editor-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.editor-head span,
label span,
.selected-card > span,
.editor-status {
  color: var(--muted);
  font-size: 12px;
}

.editor-head h1 {
  margin: 2px 0 0;
  font-size: 20px;
  letter-spacing: 0;
}

.editor-head a,
button,
input,
select,
textarea {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(245, 241, 223, 0.08);
  color: var(--ink);
  font: inherit;
}

.editor-head a {
  padding: 8px 10px;
  text-decoration: none;
}

.control-section {
  display: grid;
  gap: 9px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.segmented,
.button-row,
.two-col {
  display: grid;
  gap: 8px;
}

.segmented {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.segmented button {
  padding-right: 6px;
  padding-left: 6px;
  font-size: 13px;
  white-space: nowrap;
}

.button-row,
.two-col {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

label {
  display: grid;
  gap: 5px;
}

input,
button,
select,
textarea {
  min-width: 0;
  min-height: 36px;
  padding: 8px 10px;
}

button {
  cursor: pointer;
}

select option {
  background: #161a14;
  color: var(--ink);
}

button:hover,
.editor-head a:hover,
button.active {
  border-color: rgba(214, 166, 74, 0.8);
  background: rgba(214, 166, 74, 0.18);
}

button:disabled {
  cursor: default;
  opacity: 0.42;
}

button.dirty {
  border-color: rgba(86, 220, 130, 0.82);
  background: rgba(86, 220, 130, 0.16);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-title strong {
  font-size: 14px;
}

.change-state {
  flex: none;
  color: var(--muted);
  font-size: 12px;
}

.change-state.dirty {
  color: var(--good);
}

.change-detail {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 11px;
}

.contract-grid {
  display: grid;
  grid-template-columns: 68px minmax(0, 1fr);
  gap: 4px 8px;
  padding: 8px;
  border: 1px solid rgba(245, 241, 223, 0.1);
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.16);
}

.contract-grid span,
.contract-grid strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}

.contract-grid span {
  color: var(--muted);
}

.contract-grid strong.warning {
  color: var(--accent);
}

.contract-grid strong.error {
  color: #ff6b6b;
}

.validation-report {
  display: grid;
  gap: 5px;
  padding: 8px;
  border: 1px solid rgba(86, 220, 130, 0.28);
  border-radius: 7px;
  background: rgba(86, 220, 130, 0.08);
}

.validation-report.warning {
  border-color: rgba(214, 166, 74, 0.38);
  background: rgba(214, 166, 74, 0.08);
}

.validation-report.error {
  border-color: rgba(255, 107, 107, 0.42);
  background: rgba(255, 107, 107, 0.08);
}

.validation-report strong {
  font-size: 12px;
}

.validation-report span {
  color: var(--muted);
  font-size: 11px;
}

.validation-report ul {
  display: grid;
  gap: 3px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.validation-report li {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-size: 11px;
}

.validation-report li button {
  width: 100%;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.validation-report li button:focus-visible {
  outline: 1px solid currentColor;
  outline-offset: 2px;
}

.validation-report li button:disabled {
  cursor: default;
  opacity: 0.7;
}

.validation-report li.warning {
  color: var(--accent);
}

.validation-report li.error {
  color: #ff8b8b;
}

.section-title button {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.build-section {
  position: fixed;
  left: calc((100vw - 350px) / 2);
  right: auto;
  bottom: 18px;
  z-index: 6;
  display: grid;
  gap: 10px;
  width: min(760px, calc(100vw - 390px));
  max-height: min(48vh, 420px);
  padding: 12px;
  overflow-y: auto;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 20, 17, 0.94);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
  backdrop-filter: blur(12px);
}

.selection-action-strip,
.ad-palette,
.building-shell-editor {
  position: fixed;
  left: 14px;
  right: 350px;
  z-index: 6;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 20, 17, 0.92);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(12px);
}

.selection-action-strip {
  bottom: 14px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px;
}

.selection-action-strip strong {
  min-width: 0;
  margin-right: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.selection-action-strip button,
.ad-palette button {
  min-height: 32px;
  padding: 6px 10px;
}

.ad-palette {
  bottom: 72px;
  display: grid;
  gap: 10px;
  padding: 12px;
}

.building-shell-editor {
  bottom: 72px;
  display: grid;
  grid-template-columns: minmax(180px, 280px) auto;
  align-items: end;
  gap: 10px;
  padding: 10px;
}

.building-shell-editor label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
}

.building-shell-color-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.building-shell-color-button {
  width: 32px;
  min-height: 32px;
  padding: 0;
  border-color: rgba(245, 241, 223, 0.24);
  border-radius: 6px;
}

.building-shell-color-button.active {
  border-color: rgba(255, 231, 146, 0.96);
  box-shadow: 0 0 0 2px rgba(255, 231, 146, 0.16);
}

.ad-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(112px, 1fr));
  gap: 8px;
}

.ad-card {
  display: grid;
  gap: 7px;
  min-height: 94px;
  padding: 8px;
  text-align: left;
}

.ad-card.active {
  border-color: rgba(107, 188, 255, 0.9);
  background: rgba(107, 188, 255, 0.14);
}

.ad-preview {
  display: grid;
  align-content: center;
  gap: 2px;
  min-height: 48px;
  padding: 7px;
  border: 1px solid rgba(245, 241, 223, 0.18);
  border-radius: 5px;
  overflow: hidden;
}

.ad-preview b {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: Arial, sans-serif;
  font-size: 13px;
  font-style: italic;
}

.ad-preview small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: inherit;
  font-family: Arial, sans-serif;
  font-size: 9px;
}

.ad-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.build-grid {
  display: grid;
  gap: 11px;
}

.build-group {
  display: grid;
  gap: 7px;
}

.build-group summary {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  font-weight: 700;
  list-style: none;
}

.build-group summary::-webkit-details-marker {
  display: none;
}

.build-group summary::before {
  content: "▸";
  color: var(--accent);
}

.build-group[open] summary::before {
  content: "▾";
}

.build-group summary span {
  display: inline-grid;
  min-width: 20px;
  min-height: 20px;
  place-items: center;
  border: 1px solid rgba(245, 241, 223, 0.14);
  border-radius: 999px;
  color: var(--ink);
  font-size: 10px;
}

.build-group:not([open]) .build-card-grid {
  display: none;
}

.build-card-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(92px, 1fr));
  gap: 8px;
}

.build-card {
  display: grid;
  grid-template-columns: 20px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px;
  text-align: left;
}

.build-card.active {
  border-color: rgba(86, 220, 130, 0.95);
  background: rgba(86, 220, 130, 0.16);
}

.build-swatch {
  width: 18px;
  height: 18px;
  border: 1px solid rgba(245, 241, 223, 0.32);
  border-radius: 4px;
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.12);
}

.build-copy {
  display: grid;
  gap: 2px;
}

.build-copy strong,
.build-copy span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.build-copy strong {
  font-size: 13px;
}

.build-copy span {
  color: var(--muted);
  font-size: 11px;
}

.build-active-strip {
  position: fixed;
  left: 14px;
  bottom: 14px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: min(520px, calc(100vw - 360px));
  padding: 9px;
  border: 1px solid rgba(86, 220, 130, 0.4);
  border-radius: 8px;
  background: rgba(16, 20, 17, 0.9);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.28);
}

.build-active-strip strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.build-active-strip button {
  min-height: 32px;
  padding: 6px 10px;
  white-space: nowrap;
}

.check-row {
  display: flex;
  align-items: center;
}

.check-row input {
  min-height: 0;
  width: auto;
  accent-color: var(--blue);
}

.selected-card strong {
  font-size: 15px;
}

.advanced-section summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

.advanced-section textarea {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  white-space: pre;
  color: #dbe7d8;
  font-family: Consolas, "Courier New", monospace;
  font-size: 11px;
  line-height: 1.45;
}

.editor-status {
  line-height: 1.5;
}

@media (max-width: 760px) {
  .world-editor-panel {
    left: 10px;
    right: 10px;
    top: auto;
    bottom: 10px;
    width: auto;
    max-height: 46vh;
  }

  .build-section {
    left: 10px;
    right: 10px;
    bottom: calc(46vh + 26px);
    width: auto;
    max-height: min(38vh, 340px);
    transform: none;
  }

  .build-card-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .build-active-strip {
    left: 10px;
    right: 10px;
    bottom: calc(46vh + 18px);
    max-width: none;
  }

  .selection-action-strip {
    left: 10px;
    right: 10px;
    bottom: calc(46vh + 18px);
  }

  .ad-palette {
    left: 10px;
    right: 10px;
    bottom: calc(46vh + 76px);
  }

  .building-shell-editor {
    left: 10px;
    right: 10px;
    bottom: calc(46vh + 76px);
    grid-template-columns: 1fr;
  }

  .ad-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
