:root {
  color-scheme: dark;
  --bg-top: #06141d;
  --bg-bottom: #102c36;
  --panel-bg: rgba(8, 20, 28, 0.88);
  --panel-border: rgba(126, 232, 124, 0.45);
  --text-main: #f5fffa;
  --text-dim: #a3c6bc;
  --accent: #81f57a;
  --accent-dark: #2d7d4d;
  --danger: #ff7680;
  --shadow: rgba(0, 0, 0, 0.4);
  --button-bg: linear-gradient(180deg, rgba(66, 140, 74, 0.95), rgba(38, 84, 56, 0.95));
  --button-disabled: linear-gradient(180deg, rgba(80, 92, 99, 0.85), rgba(42, 50, 55, 0.85));
  --grid-line: rgba(255, 255, 255, 0.09);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 20%, rgba(87, 171, 104, 0.15), transparent 18%),
    radial-gradient(circle at 80% 12%, rgba(118, 210, 255, 0.12), transparent 14%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
  font-family: "Trebuchet MS", "Lucida Sans Unicode", "Lucida Grande", "Lucida Sans", Arial, sans-serif;
  color: var(--text-main);
}

body {
  position: relative;
}

#app-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
}

#game-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#ui-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.screen {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 24px;
}

.panel {
  width: min(680px, calc(100vw - 48px));
  padding: 28px;
  background: var(--panel-bg);
  border: 3px solid var(--panel-border);
  border-radius: 18px;
  box-shadow: 0 24px 60px var(--shadow);
  backdrop-filter: blur(8px);
  pointer-events: auto;
}

.panel.compact {
  width: min(480px, calc(100vw - 48px));
}

.library-panel {
  width: min(860px, calc(100vw - 48px));
  max-height: min(88vh, 920px);
  overflow: auto;
}

.title {
  margin: 0 0 18px;
  text-align: center;
  font-size: clamp(2.2rem, 5vw, 4rem);
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  text-shadow: 0 0 24px rgba(129, 245, 122, 0.4);
}

.subtitle,
.small-copy,
.hud-copy,
.error-copy,
.success-copy {
  margin: 0;
  text-align: center;
  line-height: 1.45;
}

.subtitle,
.small-copy {
  color: var(--text-dim);
}

.success-copy {
  color: var(--accent);
}

.error-copy {
  color: var(--danger);
}

.button-stack,
.button-row,
.control-grid,
.editor-toolbar,
.pill-row {
  display: flex;
  gap: 12px;
}

.button-stack {
  flex-direction: column;
  margin-top: 24px;
}

.button-row {
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 18px;
}

.gallery-actions {
  justify-content: flex-start;
  margin-top: 14px;
}

.menu-button,
.toolbar-button,
.toolbar-select,
.toolbar-input,
.toolbar-textarea {
  pointer-events: auto;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  min-height: 48px;
  padding: 12px 18px;
  font: inherit;
  color: var(--text-main);
  background: var(--button-bg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

.menu-button,
.toolbar-button {
  cursor: pointer;
  transition: transform 140ms ease, filter 140ms ease, border-color 140ms ease;
}

.menu-button:hover:not(:disabled),
.toolbar-button:hover:not(:disabled),
.toolbar-button.active {
  transform: translateY(-1px);
  filter: brightness(1.08);
  border-color: rgba(255, 255, 255, 0.35);
}

.menu-button:disabled,
.toolbar-button:disabled {
  cursor: not-allowed;
  background: var(--button-disabled);
  color: rgba(255, 255, 255, 0.6);
}

.control-grid {
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 18px;
}

.pill {
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 8px 12px;
  color: var(--text-dim);
  background: rgba(255, 255, 255, 0.04);
}

.auth-pill {
  color: var(--text-main);
}

.hud {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.hud-card {
  min-width: 220px;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(7, 19, 28, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 30px var(--shadow);
}

.hud-title {
  margin: 0 0 4px;
  font-size: 0.92rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.hud-copy {
  text-align: left;
  color: var(--text-main);
}

.overlay-panel {
  max-width: 520px;
  text-align: center;
}

.editor-shell {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  pointer-events: none;
  padding: 16px;
}

.editor-shell.chrome-hidden .editor-toolbar,
.editor-shell.chrome-hidden .editor-footer {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.editor-shell.chrome-hidden .editor-toolbar *,
.editor-shell.chrome-hidden .editor-footer * {
  pointer-events: none !important;
  visibility: hidden;
}

.editor-toolbar {
  flex-wrap: wrap;
  align-items: center;
  padding: 12px;
  background: rgba(7, 19, 28, 0.82);
  border: 2px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  box-shadow: 0 18px 40px var(--shadow);
  pointer-events: auto;
}

.toolbar-select,
.toolbar-input,
.toolbar-textarea {
  background: rgba(19, 32, 43, 0.92);
}

.toolbar-textarea {
  width: min(360px, calc(100vw - 40px));
  min-height: 92px;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.4;
}

.editor-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  pointer-events: none;
}

.editor-footer > * {
  pointer-events: auto;
}

.status-box {
  max-width: min(480px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(7, 19, 28, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.hint-box {
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(7, 19, 28, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-dim);
}

.text-box-panel {
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(7, 19, 28, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.gallery-list {
  display: grid;
  gap: 14px;
  margin-top: 22px;
}

.level-card {
  padding: 18px;
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(14, 28, 37, 0.95), rgba(7, 18, 24, 0.92)),
    rgba(7, 19, 28, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.22);
}

.level-card-title {
  margin: 0 0 8px;
  font-size: 1.18rem;
  letter-spacing: 0.05em;
  color: var(--text-main);
}

.level-card-copy {
  text-align: left;
}

.panel-label {
  margin: 0 0 8px;
  font-size: 0.92rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}

.hidden-input {
  display: none;
}

@media (max-width: 820px) {
  .panel {
    padding: 22px;
  }

  .library-panel {
    max-height: min(90vh, 920px);
  }

  .editor-shell {
    padding: 12px;
  }

  .hud {
    top: 12px;
    left: 12px;
  }
}
