@import url("https://fonts.googleapis.com/css2?family=Electrolize&family=Roboto:wght@400;700&display=swap");

:root {
  color-scheme: light;
  --castle-purple: #765081;
  --castle-gold: #a57130;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: #f1dfbd;
  color: #493149;
  font-family: "Electrolize", "Roboto", sans-serif;
}

#castleViewport {
  position: relative;
  width: min(676px, 100vw);
  aspect-ratio: 676 / 384;
  isolation: isolate;
}

#stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #302932;
  touch-action: manipulation;
}

#castleBackground {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  user-select: none;
  pointer-events: none;
}

#stage canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  pointer-events: none;
}

#iso_floor,
#iso_floor2 {
  z-index: 10;
}
#iso_item {
  z-index: 20;
}
#iso_mouse {
  z-index: 25;
}
#stage #iso_m2t {
  visibility: hidden;
}

.stage-audio-dock {
  position: absolute;
  z-index: 10000;
  top: 10px;
  left: 10px;
  right: 10px;
  height: 52px;
  border-radius: 18px;
  overflow: hidden;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}

.hud-audio-visible .stage-audio-dock {
  visibility: visible;
  opacity: 1;
  pointer-events: auto;
}

.stage-audio-dock iframe {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
}

#castleViewport .hud-wrap {
  position: absolute;
  left: 10px;
  bottom: 10px;
  width: calc(100% - 20px);
  transform: none;
}

#castleViewport .hud-bar--tight {
  --hud-bg: #f4e6c9;
  --hud-tint: rgba(173, 135, 193, 0.08);
  --hud-border: rgba(159, 109, 52, 0.48);
  background:
    linear-gradient(90deg, rgba(255, 248, 229, 0.74), rgba(253, 238, 211, 0.62), rgba(255, 248, 229, 0.74)),
    url("../../hud/castle-light/castle-light-floral-bg.png?v=20261004-light") center / cover no-repeat;
}

#castleViewport .hud-page-backdrop {
  position: absolute;
  inset: 68px 10px 72px;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  transform: none;
}

#levelStatus {
  position: absolute;
  z-index: 11000;
  top: 65px;
  left: 10px;
  right: 10px;
  margin: 0;
  padding: 7px 10px;
  border: 1px solid rgba(234, 195, 110, 0.4);
  border-radius: 8px;
  background: rgba(255, 247, 231, 0.96);
  font:
    12px/1.4 "Roboto",
    sans-serif;
}

.tile-editor-help {
  margin: 5px 2px 0;
  color: #796480;
  font-size: 9px;
  line-height: 1.5;
}

#tileDebug,
#tileDebug * {
  box-sizing: border-box;
}
.tile-editor-head {
  cursor: move;
  touch-action: none;
}

@media (max-width: 480px) {
  #castleViewport .hud-left,
  #castleViewport .hud-right {
    min-width: 0;
  }
  #castleViewport .hud-group {
    gap: 4px;
  }
  #castleViewport .hud-label {
    display: none;
  }
  #castleViewport .hud-btn,
  #castleViewport .hud-chip {
    padding: 0 8px;
  }
}

/* =========================
     Light Castle live tile editor
     Press I to show or hide it.
  ========================== */
#tileEditorToggle {
  position: absolute;
  right: 10px;
  top: 10px;
  z-index: 10001;
  box-sizing: border-box;
  width: 32px;
  height: 32px;
  padding: 7px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(172, 118, 56, 0.5);
  border-radius: 10px;
  color: #513954;
  background: rgba(255, 247, 230, 0.96);
  box-shadow: 0 3px 9px rgba(63, 34, 45, 0.18);
  cursor: pointer;
}
.hud-audio-visible #tileEditorToggle {
  top: calc(var(--dock-top, 10px) + var(--dock-h, 52px) + 10px);
}
#tileEditorToggle svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#tileEditorToggle:hover,
#tileEditorToggle:focus-visible {
  border-color: rgba(172, 118, 56, 0.74);
  background: #f4e2be;
  outline: 2px solid #a77536;
  outline-offset: 2px;
}
body.tile-editor-open #tileEditorToggle {
  display: none;
}

#tileDebug {
  position: fixed;
  left: 686px;
  top: 8px;
  z-index: 9998;
  width: 240px;
  height: 376px;
  padding: 8px;
  overflow: hidden;
  border: 1px solid rgba(172, 118, 56, 0.3);
  border-radius: 15px;
  color: #513954;
  background:
    radial-gradient(circle at 100% 0, rgba(141, 77, 255, 0.18), transparent 42%),
    linear-gradient(155deg, rgba(255, 244, 225, 0.97), rgba(235, 216, 185, 0.98));
  box-shadow:
    0 16px 40px rgba(0, 0, 0, 0.48),
    0 0 24px rgba(172, 118, 56, 0.1);
  font:
    11px/1.25 "Electrolize",
    "Roboto",
    sans-serif;
  backdrop-filter: blur(12px) saturate(130%);
  -webkit-backdrop-filter: blur(12px) saturate(130%);
  display: none;
  pointer-events: auto;
  user-select: none;
}
#tileDebug.is-on {
  display: block;
}

.tile-editor-head {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 28px;
  padding-bottom: 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.tile-editor-logo {
  width: 23px;
  height: 23px;
  position: relative;
  flex: 0 0 23px;
}
.tile-editor-logo::before,
.tile-editor-logo::after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  transform: rotate(45deg);
  border: 1px solid rgba(172, 118, 56, 0.85);
  background: rgba(172, 118, 56, 0.14);
  box-shadow: 0 0 10px rgba(172, 118, 56, 0.35);
}
.tile-editor-logo::before {
  left: 1px;
  top: 5px;
}
.tile-editor-logo::after {
  right: 1px;
  top: 5px;
  border-color: #c47cff;
  background: rgba(196, 124, 255, 0.14);
}
.tile-editor-title {
  min-width: 0;
  flex: 1;
}
.tile-editor-title strong {
  display: block;
  color: #513954;
  font-size: 11px;
  line-height: 1.05;
  letter-spacing: 0.65px;
}
.tile-editor-title small {
  display: block;
  margin-top: 3px;
  color: rgba(110, 72, 121, 0.9);
  font-size: 8px;
  letter-spacing: 0.55px;
}
.tile-editor-close {
  width: 25px;
  height: 25px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  color: rgba(81, 57, 84, 0.86);
  background: rgba(255, 255, 255, 0.055);
  font:
    18px/1 system-ui,
    sans-serif;
  cursor: pointer;
}
.tile-editor-close:hover {
  color: #493149;
  background: rgba(255, 255, 255, 0.12);
}

.tile-editor-readout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 6px 0;
}
.tile-editor-value {
  min-width: 0;
  height: 34px;
  padding: 4px 7px;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
}
.tile-editor-value span {
  display: block;
  color: rgba(81, 57, 84, 0.78);
  font-size: 8px;
  letter-spacing: 0.65px;
}
.tile-editor-value b {
  display: block;
  margin-top: 3px;
  overflow: hidden;
  color: #493149;
  font-size: 11px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#dbgTargetTile {
  color: #a77536;
}

.tile-editor-section-title {
  display: flex;
  justify-content: space-between;
  margin: 5px 1px 3px;
  color: rgba(81, 57, 84, 0.82);
  font-size: 8px;
  letter-spacing: 0.7px;
}
.tile-editor-section-title em {
  color: rgba(172, 118, 56, 0.66);
  font-style: normal;
}
.tile-editor-tools {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}
.tile-editor-tool,
.tile-editor-action,
.tile-editor-floor {
  min-width: 0;
  height: 25px;
  padding: 0 7px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 8px;
  color: rgba(81, 57, 84, 0.94);
  background: rgba(255, 255, 255, 0.045);
  font:
    700 8px/1 "Electrolize",
    "Roboto",
    sans-serif;
  letter-spacing: 0.42px;
  cursor: pointer;
}
.tile-editor-tool::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 6px;
  vertical-align: -1px;
  transform: rotate(45deg);
  border: 1px solid currentColor;
}
.tile-editor-tool[data-editor-tool="walkable"] {
  color: #257449;
}
.tile-editor-tool[data-editor-tool="blocked"] {
  color: #a13f47;
}
.tile-editor-tool[data-editor-tool="spawn"] {
  color: #956024;
}
.tile-editor-tool[data-editor-tool="exit"] {
  color: #754280;
}
.tile-editor-tool:hover,
.tile-editor-action:hover,
.tile-editor-floor:hover {
  background: rgba(255, 255, 255, 0.09);
  color: #493149;
}
.tile-editor-tool.is-active {
  border-color: currentColor;
  background: rgba(172, 118, 56, 0.1);
  box-shadow:
    0 0 12px rgba(172, 118, 56, 0.09),
    inset 0 0 0 1px rgba(255, 255, 255, 0.035);
}

.tile-editor-floor-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}
.tile-editor-floor {
  position: relative;
  text-align: left;
  padding-left: 33px;
}
.tile-editor-floor::before {
  content: "";
  position: absolute;
  left: 8px;
  top: 5px;
  width: 17px;
  height: 10px;
  transform: skewY(-26deg);
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: #244b43;
}
.tile-editor-floor[data-floor="1"]::before {
  background: #4b315f;
}
.tile-editor-floor.is-active {
  border-color: rgba(112, 245, 174, 0.72);
  color: #493149;
  background: rgba(112, 245, 174, 0.08);
}

.tile-editor-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}
.tile-editor-action {
  padding: 0 3px;
}
.tile-editor-action.is-active {
  color: #956024;
  border-color: rgba(172, 118, 56, 0.46);
  background: rgba(172, 118, 56, 0.09);
}
.tile-editor-action:disabled {
  opacity: 0.28;
  cursor: default;
}
.tile-editor-export {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 5px;
}
.tile-editor-export .tile-editor-action:first-child {
  color: #051014;
  border-color: #a57130;
  background: linear-gradient(180deg, #f1d59c, #d3ab62);
}
.tile-editor-export .tile-editor-action:first-child:hover {
  filter: brightness(1.08);
}

.tile-editor-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 20px;
  margin-top: 5px;
  padding: 0 2px;
  color: rgba(81, 57, 84, 0.76);
  font-size: 8px;
  letter-spacing: 0.35px;
}
#tileEditorStatus {
  min-width: 0;
  overflow: hidden;
  color: rgba(37, 116, 73, 0.95);
  text-overflow: ellipsis;
  white-space: nowrap;
}
#tileEditorStats {
  white-space: nowrap;
}

#tileEditorGrid {
  position: absolute;
  inset: 0;
  z-index: 9994;
  width: 100%;
  height: 100%;
  display: none;
  overflow: visible;
  pointer-events: none;
}
body.tile-editor-open #tileEditorGrid {
  display: block;
}
#tileEditorGridCells polygon {
  vector-effect: non-scaling-stroke;
  fill: rgba(255, 255, 255, 0.018);
  stroke: rgba(184, 235, 240, 0.15);
  stroke-width: 0.55;
}
#tileEditorGridCells polygon.is-walkable {
  fill: rgba(70, 241, 157, 0.15);
  stroke: rgba(92, 255, 177, 0.55);
}
#tileEditorGridCells polygon.is-blocked {
  fill: rgba(255, 74, 91, 0.018);
}
#tileEditorGridCells polygon.is-spawn {
  fill: rgba(172, 118, 56, 0.42);
  stroke: #67eaff;
  stroke-width: 1.3;
}
#tileEditorGridCells polygon.is-exit {
  fill: rgba(229, 92, 255, 0.42);
  stroke: #f2a1ff;
  stroke-width: 1.3;
}
#tileEditorGrid.grid-off
  #tileEditorGridCells
  polygon:not(.is-walkable):not(.is-spawn):not(.is-exit) {
  opacity: 0;
}

#tileDebugMarker,
#tileMiniMarker {
  position: absolute;
  width: 24px;
  height: 12px;
  margin-left: -12px;
  margin-top: -6px;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  pointer-events: none;
  z-index: 9996;
  display: none;
}
#tileDebugMarker {
  background: rgba(255, 224, 101, 0.34);
  filter: drop-shadow(0 0 4px rgba(255, 224, 101, 0.95));
}
#tileMiniMarker {
  width: 14px;
  height: 14px;
  margin-left: -7px;
  margin-top: -16px;
  border-radius: 50%;
  clip-path: none;
  border: 2px solid #fff;
  background: #a77536;
  box-shadow: 0 0 10px #a77536;
}

body.tile-editor-open #stage {
  cursor: crosshair;
  touch-action: none;
}

@media (max-width: 950px) {
  #tileDebug {
    left: auto;
    right: 8px;
  }
}

#tileEditorGridCells polygon.is-floor-b:not(.is-spawn):not(.is-exit) {
  fill: rgba(183, 106, 245, 0.22);
}
