:root {
  color-scheme: light;
  --sky: #47acf0;
  --ink: #1d2939;
  --panel: rgba(255, 255, 255, 0.88);
  --panel-strong: #fff;
  --line: rgba(29, 41, 57, 0.16);
  --accent: #203245;
  --gold: #f4b740;
  --coral: #f36f5f;
  --green: #5cae3f;
  --page-bg: url("던바튼런.png?v=2026.05.26.16");
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100dvh;
  background:
    linear-gradient(180deg, rgba(20, 64, 98, 0.34), rgba(35, 142, 209, 0.46)),
    var(--page-bg) center / cover fixed no-repeat,
    var(--sky);
  color: var(--ink);
  font-family:
    Pretendard, "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic",
    ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  word-break: keep-all;
}

button,
input,
textarea {
  font: inherit;
}

button,
.game-link {
  min-height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  font-weight: 850;
  text-decoration: none;
  cursor: pointer;
}

button:active {
  transform: translateY(1px);
  background: #fff7d6;
}

button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

button[aria-pressed="true"] {
  border-color: rgba(18, 63, 117, 0.64);
  background: #d9ecff;
  color: #123f75;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 3px solid #123f75;
  outline-offset: 3px;
}

.editor-shell {
  width: min(100%, 1220px);
  min-height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) minmax(112px, 22dvh);
  gap: 10px;
  padding: 10px;
}

.editor-shell:has(.map-panel:not([hidden])) {
  grid-template-rows: auto auto auto auto minmax(0, 1fr) minmax(112px, 22dvh);
}

.editor-top,
.command-bar,
.tool-palette,
.viewport-band,
.output-band {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 28px rgba(31, 54, 75, 0.18);
}

.editor-top {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
}

.kicker,
.brand-link {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 900;
  color: #315170;
  text-decoration: none;
}

.brand-link:hover,
.brand-link:focus-visible {
  color: #123f75;
}

h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: 0;
}

.command-bar {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(0, 1fr);
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
}

.command-group,
.palette-group,
.selection-actions,
.map-panel-auth {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.command-main {
  justify-content: end;
}

.primary-action {
  border-color: rgba(18, 63, 117, 0.48);
  background: #123f75;
  color: #fff;
}

.play-action {
  background: #0f7a5f;
}

.danger-action {
  border-color: rgba(180, 35, 24, 0.32);
  color: #b42318;
}

.tool-palette {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px;
}

.palette-group {
  min-width: 0;
  overflow-x: auto;
  padding-bottom: 2px;
}

.group-title {
  flex: 0 0 auto;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 6px 0 2px;
  color: #315170;
  font-size: 0.82rem;
  font-weight: 950;
}

.more-menu {
  position: relative;
}

.more-menu summary {
  min-height: 38px;
  display: inline-grid;
  place-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  color: var(--ink);
  font-weight: 850;
  list-style: none;
  cursor: pointer;
}

.more-menu summary::-webkit-details-marker {
  display: none;
}

.more-menu[open] summary {
  border-color: rgba(18, 63, 117, 0.48);
  background: #d9ecff;
}

.more-menu-list {
  position: absolute;
  right: 0;
  z-index: 12;
  width: max-content;
  min-width: 188px;
  margin-top: 8px;
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 18px 42px rgba(17, 30, 45, 0.22);
}

.more-menu-list button {
  justify-content: start;
}

.toggle {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  font-weight: 850;
}

.map-status {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 4px;
  color: #315170;
  font-size: 0.82rem;
  font-weight: 850;
}

.map-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 12px 28px rgba(31, 54, 75, 0.18);
}

.map-panel[hidden] {
  display: none;
}

.map-panel-header,
.map-confirm,
.map-list-item,
.map-list-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.map-panel-header {
  justify-content: space-between;
}

.map-panel h2,
.map-panel p {
  margin: 0;
}

.map-panel h2 {
  font-size: 1.05rem;
  letter-spacing: 0;
}

.map-confirm {
  padding: 8px;
  border: 1px solid rgba(244, 183, 64, 0.55);
  border-radius: 8px;
  background: rgba(255, 247, 214, 0.9);
  font-weight: 850;
}

.map-list {
  display: grid;
  gap: 8px;
}

.map-list-item {
  justify-content: space-between;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.map-list-item.is-active {
  border-color: rgba(18, 63, 117, 0.56);
  background: #d9ecff;
}

.map-list-item strong,
.map-list-item span {
  min-width: 0;
}

.map-list-item span,
.map-empty,
.map-error,
#mapPanelStatus {
  font-size: 0.86rem;
  font-weight: 850;
  color: #315170;
}

.map-error {
  color: #b42318;
}

.viewport-band {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 360px);
  gap: 10px;
  padding: 10px;
}

canvas {
  width: 100%;
  min-width: 0;
  align-self: center;
  border: 1px solid rgba(18, 42, 68, 0.2);
  border-radius: 8px;
  background: #7bc8ff;
  cursor: grab;
  touch-action: none;
}

.map-badge {
  min-height: 28px;
  display: inline-grid;
  place-items: center;
  padding: 0 8px;
  border-radius: 999px;
  background: #d9ecff;
  color: #123f75;
  font-size: 0.78rem;
  font-weight: 950;
}

canvas.is-over-object {
  cursor: move;
}

canvas.is-dragging,
canvas.is-panning {
  cursor: grabbing;
}

canvas.is-cutting {
  cursor: crosshair;
}

.side-panel {
  min-width: 0;
  display: grid;
  align-content: start;
  gap: 12px;
}

.map-settings {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.map-settings h2 {
  margin: 0;
  font-size: 0.98rem;
  font-weight: 950;
}

.marker-shortcuts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.marker-shortcuts button {
  min-width: 0;
}

.world-width-hint {
  min-height: 1.2em;
  margin: 0;
  color: #315170;
  font-size: 0.82rem;
  font-weight: 850;
}

.camera-label {
  display: grid;
  gap: 8px;
  font-weight: 900;
}

.camera-label input {
  width: 100%;
}

.camera-hint {
  color: #315170;
  font-size: 0.78rem;
  font-weight: 850;
}

.selection-title {
  margin: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  font-weight: 900;
}

.property-grid {
  display: grid;
  gap: 8px;
}

.selection-hint {
  margin: 0;
  padding: 10px;
  border: 1px dashed rgba(29, 41, 57, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  color: #315170;
  font-size: 0.9rem;
  font-weight: 850;
}

.property-row {
  display: grid;
  grid-template-columns: 86px minmax(120px, 1fr) 78px;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 850;
}

.property-grid input {
  min-width: 0;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
}

.property-grid input[type="range"] {
  min-height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: #123f75;
}

.property-grid input[type="number"] {
  width: 100%;
}

.enemy-speed-preview {
  margin: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 247, 214, 0.88);
  color: #203245;
  font-size: 0.86rem;
  font-weight: 900;
}

.output-band {
  min-height: 0;
  padding: 10px;
}

textarea {
  width: 100%;
  height: 100%;
  min-height: 92px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ink);
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.82rem;
  line-height: 1.45;
}

.playtest-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(29, 41, 57, 0.62);
}

.map-name-dialog {
  position: fixed;
  inset: 0;
  z-index: 24;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(29, 41, 57, 0.58);
}

.map-name-dialog[hidden] {
  display: none;
}

.map-name-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 24px 60px rgba(17, 30, 45, 0.34);
}

.map-name-card h2 {
  margin: 0;
  font-size: 1.15rem;
}

.map-name-card label {
  display: grid;
  gap: 8px;
  font-weight: 900;
}

.map-name-card input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
}

.map-name-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.playtest-overlay[hidden] {
  display: none;
}

.playtest-panel {
  width: min(1180px, 100%);
  height: min(760px, 100%);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 60px rgba(17, 30, 45, 0.36);
}

.playtest-header {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.playtest-header h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0;
}

.playtest-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

#playtestFrame {
  width: 100%;
  height: 100%;
  border: 1px solid rgba(18, 42, 68, 0.2);
  border-radius: 8px;
  background: var(--sky);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 980px) {
  .editor-shell {
    grid-template-rows: auto auto auto auto minmax(160px, 24dvh);
  }

  .editor-shell:has(.map-panel:not([hidden])) {
    grid-template-rows: auto auto auto auto auto minmax(160px, 24dvh);
  }

  .viewport-band {
    grid-template-columns: 1fr;
  }

  .editor-top,
  .command-bar,
  .tool-palette {
    grid-template-columns: 1fr;
  }

  .editor-top,
  .command-group,
  .palette-group {
    flex-wrap: wrap;
  }

  .command-main {
    justify-content: start;
  }

  .command-group button,
  .command-group .more-menu,
  .command-group .more-menu summary {
    min-width: 0;
  }

  .palette-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
  }

  .palette-group .group-title {
    grid-column: 1 / -1;
  }

  .view-options {
    grid-template-columns: 1fr;
  }

  .more-menu-list {
    left: auto;
    right: 0;
    max-width: calc(100vw - 36px);
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .marker-shortcuts {
    grid-template-columns: 1fr;
  }

  .property-row {
    grid-template-columns: minmax(0, 1fr) 78px;
  }

  .property-name {
    grid-column: 1 / -1;
  }

  .playtest-overlay {
    padding: 8px;
  }

  .playtest-panel {
    height: calc(100dvh - 16px);
  }
}

@media (max-width: 640px) and (orientation: portrait) {
  body {
    overflow-x: hidden;
  }

  .editor-shell {
    grid-template-rows: auto auto auto minmax(0, 1fr) minmax(104px, 18dvh);
    gap: 6px;
    padding: 6px;
  }

  .editor-shell:has(.map-panel:not([hidden])) {
    grid-template-rows: auto auto auto auto minmax(0, 1fr) minmax(104px, 18dvh);
  }

  .editor-top {
    min-height: 42px;
    padding: 6px 8px;
    gap: 8px;
  }

  .editor-top .kicker {
    display: inline-block;
    max-width: 118px;
    font-size: 0.7rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  h1 {
    font-size: 1rem;
  }

  button,
  .game-link,
  .more-menu summary,
  .toggle {
    min-height: 36px;
    padding-inline: 10px;
    font-size: 0.9rem;
    white-space: nowrap;
  }

  .command-bar,
  .tool-palette {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 6px;
    padding: 6px;
    overflow-x: auto;
    overflow-y: visible;
    overscroll-behavior-x: contain;
    scroll-padding-inline: 6px;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
  }

  .command-group,
  .palette-group {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow: visible;
    padding-bottom: 0;
  }

  .command-main {
    justify-content: flex-start;
  }

  .map-status {
    flex: 0 0 auto;
    min-height: 36px;
    font-size: 0.78rem;
  }

  .group-title {
    min-height: 36px;
    padding-inline: 0 4px;
  }

  .view-options {
    flex: 0 0 auto;
  }

  .more-menu {
    flex: 0 0 auto;
  }

  .more-menu-list {
    position: fixed;
    top: 96px;
    right: 8px;
    left: auto;
    max-width: calc(100vw - 16px);
  }

  .viewport-band {
    padding: 6px;
  }
}
