* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { background: #F6E7D8; }
main { height: 100%; height: 100dvh; display: flex; flex-direction: column; }
canvas { display: block; width: 100%; flex: 1 1 0; min-height: 0; }
/* Keep multitouch gestures on the game surface and controls in the game. */
#palette, .controls, .controls button { touch-action: none; }
.controls { flex: none; display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 12px 16px max(12px, env(safe-area-inset-bottom)); background: #F6E7D8; }
.controls button { min-height: 112px; }
button { min-height: 52px; border: 1px solid #e5d7d1; border-radius: 10px; background: #fff; color: #874356; font: 28px/1 system-ui, sans-serif; cursor: pointer; touch-action: manipulation; }
button:active { background: #f6e7d8; }
button:focus-visible { outline: 3px solid #874356; outline-offset: 2px; }

button.tall { grid-row: span 2; }

.debug-toggle { position: absolute; z-index: 2; top: max(12px, env(safe-area-inset-top)); right: 12px; width: 44px; min-height: 44px; border-radius: 10px; font-size: 23px; box-shadow: 0 2px 10px #87435620; }
.debug-panel { position: absolute; z-index: 3; top: max(12px, env(safe-area-inset-top)); right: 12px; width: min(390px, calc(100vw - 24px)); max-height: min(75dvh, 720px); overflow-y: auto; overscroll-behavior: contain; padding: 16px; border: 1px solid #dfc9c9; border-radius: 14px; background: rgb(255 250 246 / var(--panel-opacity, 0.2)); color: #57313c; font: 14px/1.4 system-ui, sans-serif; box-shadow: 0 10px 35px #57313c38; }
.debug-panel[hidden] { display: none; }
.debug-header { display: flex; align-items: start; justify-content: space-between; gap: 12px; position: sticky; top: -16px; padding: 0 0 10px; background: rgb(255 250 246 / var(--panel-opacity, 0.2)); z-index: 1; }
.debug-header h1 { font-size: 18px; margin: 0; }
.debug-header p { margin: 3px 0 0; font-size: 12px; color: #80646a; }
.debug-close { width: 36px; min-height: 36px; font-size: 24px; }
.debug-group h2 { font-size: 14px; margin: 14px 0 5px; color: #874356; }
.debug-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid #f0e5e1; }
.debug-value { font-variant-numeric: tabular-nums; text-align: right; overflow-wrap: anywhere; }
.debug-help { display: contents; }
.debug-help summary { list-style: none; display: grid; place-items: center; width: 25px; height: 25px; border: 1px solid #d7bdc3; border-radius: 50%; color: #874356; cursor: pointer; font-weight: 600; }
.debug-help summary::-webkit-details-marker { display: none; }
.debug-help p { grid-column: 1 / -1; margin: 0 0 3px; color: #72565c; font-size: 13px; }

.debug-opacity { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-top: 4px; }
.debug-opacity output { font-size: 12px; font-weight: 400; color: #80646a; }
.debug-opacity-slider { display: block; width: 100%; margin: 8px 0 12px; accent-color: #874356; }

.debug-input { width: 94px; min-width: 0; min-height: 34px; padding: 4px 6px; border: 1px solid #d7bdc3; border-radius: 7px; background: #fff; color: #57313c; font: inherit; text-align: right; }
.debug-input[type="color"] { width: 50px; padding: 2px; justify-self: end; }
.debug-input[aria-invalid="true"] { border-color: #c03045; outline: 1px solid #c03045; }

.debug-slider { width: min(155px, 42vw); display: flex; align-items: center; gap: 6px; }
.debug-slider input[type="range"] { width: 100%; min-width: 0; min-height: 32px; padding: 0; border: 0; background: transparent; accent-color: #874356; }
.debug-slider output { min-width: 2.7em; text-align: right; font-variant-numeric: tabular-nums; font-size: 12px; }
.debug-fine { grid-column: 2; display: flex; justify-content: flex-end; gap: 6px; }
.debug-fine button { width: 44px; min-height: 40px; padding: 0; border-radius: 7px; font: 600 20px system-ui, sans-serif; }

.preset-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 6px 0 12px; font-weight: 600; }
.preset-button { min-height: 34px; padding: 4px 12px; border-radius: 7px; font: 500 13px system-ui, sans-serif; }

.editor-tabs { display: flex; gap: 8px; margin: 0 0 12px; }
.editor-tab, .level-actions button { flex: 1; min-height: 36px; padding: 5px 10px; border-radius: 7px; font: 600 13px system-ui, sans-serif; }
.editor-tab[aria-selected="true"] { background: #874356; color: #fff; border-color: #874356; }
.level-note { margin: 9px 0; font-size: 12px; color: #72565c; }
.level-map-scroll { overflow-x: auto; border: 1px solid #ddc4c8; border-radius: 8px; background: #f6e7d8; overscroll-behavior-x: contain; }
#level-map { display: block; height: 210px; max-width: none; }
#level-map .level-shape { cursor: pointer; }
#level-map text { font: 11px system-ui, sans-serif; fill: #57313c; pointer-events: none; }
.level-actions { display: flex; margin-top: 10px; }
.level-group { margin: 10px 0; padding: 9px; border: 1px solid #e2d0d2; border-radius: 8px; background: rgb(255 255 255 / 0.35); }
.level-group > summary { color: #874356; font-weight: 700; cursor: pointer; }
.level-stage { display: grid; grid-template-columns: 1fr minmax(0, 170px); align-items: center; gap: 8px; margin: 10px 0; font-size: 13px; }
.level-stage select, .level-fields input { width: 100%; min-width: 0; padding: 5px; border: 1px solid #d7bdc3; border-radius: 6px; background: white; color: #57313c; font: 14px system-ui, sans-serif; }
.level-item { padding: 9px 0; border-top: 1px solid #eadcda; }
.level-item-title { display: flex; justify-content: space-between; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; }
.level-item-title label { font-size: 12px; font-weight: 400; }
.level-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; margin-top: 6px; }
.level-fields label { min-width: 0; font-size: 11px; color: #72565c; }
.level-fields input { display: block; margin-top: 3px; }
.level-fields input:disabled { opacity: 0.55; }
.level-fields input[aria-invalid="true"] { border-color: #c03045; outline: 1px solid #c03045; }
.level-small-button { min-height: 30px; padding: 3px 9px; margin-top: 7px; border-radius: 6px; font: 500 12px system-ui, sans-serif; }

.original-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.original-fields label { color: #72565c; font-size: 11px; }
.original-fields input { display: block; width: 100%; min-width: 0; margin-top: 3px; padding: 5px; border: 1px solid #d7bdc3; border-radius: 6px; background: white; color: #57313c; font: 14px system-ui, sans-serif; }
.original-fields input[aria-invalid="true"] { border-color: #c03045; outline: 1px solid #c03045; }

.level-transform { margin: 10px 0; }
.level-selected { margin: 0 0 6px; font-size: 13px; font-weight: 650; color: #874356; }
.level-transform-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin-top: 6px; }
.level-transform-row button { min-height: 40px; padding: 3px; border-radius: 7px; font: 600 17px system-ui, sans-serif; }
.level-transform-row button:disabled { opacity: 0.35; cursor: default; }
.level-select { min-height: 32px; padding: 4px 8px; border-radius: 6px; font: 600 13px system-ui, sans-serif; text-align: left; }

#level-map .level-shape { touch-action: none; }
.server-save { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin: 0 0 10px; }
.server-save button { min-height: 34px; padding: 4px 10px; border-radius: 7px; font: 600 13px system-ui, sans-serif; }
.server-save a { color: #874356; font-size: 12px; }
.server-save span { flex-basis: 100%; font-size: 12px; color: #72565c; overflow-wrap: anywhere; }
.server-save span:empty { display: none; }

button, button * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
