:root {
  --bg: #071018;
  --bg-raise: #102033;
  --ink: #e7f6ff;
  --muted: #93b4c9;
  --cyan: #3ef0ff;
  --amber: #ffb703;
  --magenta: #c084fc;
  --danger: #ff5d73;
  --ok: #5ee0a0;
  --line: rgba(62, 240, 255, 0.28);
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(192, 132, 252, 0.16), transparent 50%),
    radial-gradient(900px 500px at 110% 0%, rgba(62, 240, 255, 0.12), transparent 46%),
    var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, sans-serif;
}

body {
  min-height: 100vh;
  overscroll-behavior: none;
}

button, input, select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #163044;
  padding: 0.7rem 1rem;
  min-height: 44px;
}

button:hover, button:focus-visible {
  border-color: var(--cyan);
  outline: none;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.primary { background: #0f6e78; }
.danger { background: #6d2433; }
.ghost { background: transparent; }

#topbar, .hud {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  padding: 0.75rem 1rem;
}

#topbar h1, .hud h2 {
  margin: 0;
  font-size: clamp(1.05rem, 2vw, 1.45rem);
  letter-spacing: 0.02em;
}

.lang {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
}

select, input[type="text"], input[type="number"] {
  background: #0c1824;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.55rem 0.7rem;
  min-height: 44px;
}

#app { max-width: 1180px; margin: 0 auto; padding-bottom: 2rem; }

.panel {
  margin: 0 1rem;
  padding: 1rem;
  background: rgba(16, 32, 51, 0.88);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.lede, .help, .hint, .status {
  color: var(--muted);
  line-height: 1.45;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.8rem;
  margin-top: 1rem;
}

.card {
  text-align: left;
  background: #0d1b2a;
  padding: 0.9rem;
}

.card strong { display: block; color: var(--cyan); margin-bottom: 0.25rem; }

.hud {
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(7, 16, 24, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.hud-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.8rem;
  align-items: center;
}

.stat {
  background: #0d1b2a;
  border-radius: 999px;
  padding: 0.25rem 0.7rem;
  border: 1px solid transparent;
}

.stat.warn {
  color: var(--danger);
  border-color: var(--danger);
  animation: pulse 0.8s ease-in-out infinite;
}

.banner {
  flex: 1 1 100%;
  color: var(--amber);
  margin: 0;
}

.stage {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px;
}

.board-wrap {
  position: relative;
  flex: 0 0 auto;
  max-width: 100%;
}

canvas {
  display: block;
  width: min(480px, 100%);
  height: auto;
  background: #08131e;
  border-radius: 12px;
  border: 1px solid var(--line);
  image-rendering: pixelated;
  touch-action: none;
}

#minimap {
  width: 132px;
  height: 132px;
  image-rendering: pixelated;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.8rem;
  background: linear-gradient(transparent, rgba(4, 8, 14, 0.88) 42%);
  border-radius: 12px;
}

.overlay h3 { margin: 0; }

.overlay-actions, .row-actions, .pager {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.touch-panel {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 76px 76px 76px;
  grid-template-areas:
    ". up ."
    "left down right"
    "dig dig dig";
  gap: 8px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(8, 16, 28, 0.28);
  touch-action: none;
  user-select: none;
}

.touch-panel .up { grid-area: up; }
.touch-panel .left { grid-area: left; }
.touch-panel .down { grid-area: down; }
.touch-panel .right { grid-area: right; }
.touch-panel .dig { grid-area: dig; }

.touch-panel button {
  min-height: 68px;
  min-width: 68px;
  background: rgba(64, 196, 255, 0.45);
  border-color: rgba(180, 240, 255, 0.35);
  font-weight: 700;
}

.touch-panel button.pressed {
  background: rgba(64, 196, 255, 0.85);
}

.editor-layout, .gallery-layout {
  display: grid;
  grid-template-columns: minmax(280px, 480px) minmax(260px, 1fr);
  gap: 1rem;
  padding: 0 1rem 1rem;
  align-items: start;
}

.editor-side, .stack {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.palette, .room-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.palette button, .room-switch button {
  min-height: 40px;
  padding: 0.4rem 0.55rem;
  font-size: 0.86rem;
}

.palette button.active, .room-switch button.active {
  border-color: var(--amber);
  color: var(--amber);
}

label.field { display: flex; flex-direction: column; gap: 0.25rem; color: var(--muted); }

.list { display: flex; flex-direction: column; gap: 0.6rem; }

.fase-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.4rem 0.8rem;
  padding: 0.8rem;
  border-radius: 14px;
  background: #0d1b2a;
  border: 1px solid var(--line);
}

.fase-card p { margin: 0.15rem 0; color: var(--muted); }

#gallery-play { margin-top: 0.8rem; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 12, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 5;
}

.modal-card {
  width: min(440px, 100%);
  background: var(--bg-raise);
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 1rem;
  box-shadow: var(--shadow);
}

.modal-card h3 { margin-top: 0; }

#screen-duplicate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

#screen-duplicate .panel { max-width: 520px; }

.status.ok { color: var(--ok); }
.status.bad { color: var(--danger); }

@keyframes pulse {
  50% { transform: scale(1.04); }
}

@media (max-width: 900px), (orientation: portrait) {
  .stage { flex-direction: column; }
  .editor-layout, .gallery-layout { grid-template-columns: 1fr; }
  .touch-panel { margin-bottom: 0.5rem; }
}
