:root {
  color-scheme: dark;
  --ink: #f8fbff;
  --muted: #a9b6c8;
  --line: rgba(255,255,255,.15);
  --glass: rgba(8, 16, 27, .72);
  --deep: #06101b;
  --teal: #16e6d0;
  --blue: #4f8cff;
  --orange: #ffb020;
  --danger: #ff5b6b;
  --console-h: 176px;
  --pad-h: 74px;
  --top-safe: 150px;
  --bottom-safe: 96px;
  --shadow: 0 20px 60px rgba(0,0,0,.42);
}

* { box-sizing: border-box; }
[hidden], .hidden { display: none !important; }

html,
body {
  margin: 0;
  min-height: 100dvh;
  overflow: hidden;
  font-family: Montserrat, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 50% 30%, rgba(22,230,208,.10), transparent 35%),
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255,255,255,.035) 1px, transparent 1px),
    #060e18;
  background-size: auto, 28px 28px, 28px 28px;
  color: var(--ink);
}

button,
input,
select,
a {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

.app {
  position: relative;
  width: min(100%, 540px);
  height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  background: #07111c;
  box-shadow: 0 0 0 1px rgba(255,255,255,.07), 0 28px 90px rgba(0,0,0,.48);
}

#stageCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hud {
  position: absolute;
  z-index: 60;
  top: max(8px, env(safe-area-inset-top));
  left: 8px;
  right: 8px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(7, 17, 28, .78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.brand {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand img {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.18);
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  color: #fff;
  font-size: 14px;
  line-height: 1.05;
}

.brand span {
  margin-top: 2px;
  color: var(--teal);
  font-size: 10px;
  font-weight: 950;
  text-transform: uppercase;
}

.hud-actions {
  display: flex;
  gap: 6px;
}

.icon-btn,
.mini-btn {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 14px;
  background: rgba(255,255,255,.08);
  color: #fff;
}

.icon-btn svg,
.mini-btn svg,
.pad-btn svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.mission {
  position: absolute;
  z-index: 50;
  top: calc(66px + env(safe-area-inset-top));
  left: 8px;
  right: 8px;
  min-height: 76px;
  padding: 10px 112px 10px 12px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 22px;
  background:
    linear-gradient(135deg, rgba(22,230,208,.13), rgba(79,140,255,.07)),
    rgba(7, 17, 28, .68);
  box-shadow: 0 16px 44px rgba(0,0,0,.30);
  backdrop-filter: blur(16px);
}

.mission span {
  color: var(--teal);
  font-size: 10px;
  font-weight: 950;
  letter-spacing: .04em;
}

.mission h1 {
  margin: 2px 0 0;
  color: #fff;
  font-size: 20px;
  line-height: 1.05;
}

.mission p {
  margin: 4px 0 0;
  color: #d5dfeb;
  font-size: 10px;
  font-weight: 850;
  line-height: 1.25;
}

.mode-pill {
  position: absolute;
  top: 12px;
  right: 10px;
  min-height: 38px;
  border: 0;
  border-radius: 999px;
  padding: 8px 15px;
  background: linear-gradient(135deg, #fbbf24, #15d8c5 52%, #3b82f6);
  color: #fff;
  font-weight: 950;
  box-shadow: 0 14px 32px rgba(22,230,208,.23);
}

.selection-pill {
  position: absolute;
  z-index: 51;
  top: calc(150px + env(safe-area-inset-top));
  left: 12px;
  max-width: calc(100% - 98px);
  padding: 8px 13px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 999px;
  background: rgba(7,17,28,.74);
  color: #fff;
  font-size: 12px;
  font-weight: 950;
  box-shadow: 0 14px 30px rgba(0,0,0,.28);
  backdrop-filter: blur(14px);
}

.action-rail {
  position: absolute;
  z-index: 51;
  top: calc(150px + env(safe-area-inset-top));
  right: 10px;
  display: grid;
  gap: 7px;
  padding: 6px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 22px;
  background: rgba(7,17,28,.76);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.mini-btn.danger {
  color: var(--danger);
}

.gamepad {
  position: absolute;
  z-index: 75;
  left: 8px;
  right: 8px;
  bottom: max(8px, env(safe-area-inset-bottom));
  height: var(--pad-h);
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 8px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 26px;
  background: rgba(7, 17, 28, .82);
  box-shadow: 0 -16px 52px rgba(0,0,0,.42);
  backdrop-filter: blur(20px);
  scrollbar-width: none;
}

.gamepad::-webkit-scrollbar {
  display: none;
}

.pad-btn {
  flex: 0 0 64px;
  display: grid;
  grid-template-rows: 22px auto;
  place-items: center;
  gap: 3px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 20px;
  background: rgba(255,255,255,.065);
  color: #d8e2ef;
  font-size: 10px;
  font-weight: 950;
}

.pad-btn.active {
  border-color: rgba(255,255,255,.42);
  background: linear-gradient(135deg, #18f0d9, #58a6ff);
  color: #06111d;
  box-shadow: 0 12px 30px rgba(22,230,208,.24);
}

.console {
  position: absolute;
  z-index: 70;
  left: 8px;
  right: 8px;
  bottom: calc(var(--pad-h) + max(16px, env(safe-area-inset-bottom)));
  height: var(--console-h);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 24px;
  background: rgba(7,17,28,.86);
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
  transform: translateY(calc(100% + 12px));
  opacity: 0;
  pointer-events: none;
  transition: transform .18s ease, opacity .18s ease;
}

.console.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}

.console-head {
  flex: 0 0 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px 5px;
}

.console-head strong {
  color: #fff;
  font-size: 13px;
}

.close-console {
  min-height: 30px;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 999px;
  padding: 0 12px;
  background: rgba(255,255,255,.08);
  color: #dbe7f5;
  font-size: 11px;
  font-weight: 950;
}

.panel {
  display: none;
  flex: 1 1 auto;
  overflow: auto;
  padding: 0 10px 10px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.30) transparent;
}

.panel.active {
  display: block;
  animation: rise .16s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

label {
  display: block;
  color: #b4c1d2;
  font-size: 10px;
  font-weight: 900;
}

input,
select,
.segment,
.console button,
.console a {
  min-height: 38px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 14px;
  background: rgba(255,255,255,.08);
  color: #fff;
  outline: none;
}

input,
select {
  width: 100%;
  margin-top: 4px;
  padding: 0 11px;
}

select option {
  color: #111827;
}

input::placeholder {
  color: #9aa8ba;
}

input:focus,
select:focus {
  border-color: rgba(22,230,208,.78);
  box-shadow: 0 0 0 3px rgba(22,230,208,.16);
}

input[type="range"] {
  height: 28px;
  padding: 0;
  accent-color: var(--teal);
}

.segmented,
.inline-grid,
.link-row,
.range-line,
.command-row,
.search-row,
.upload-grid,
.text-grid {
  display: grid;
  gap: 8px;
}

.segmented {
  grid-template-columns: 1fr 1fr;
}

.segment {
  color: #e7f1ff;
  font-weight: 950;
}

.segment.active {
  background: rgba(22,230,208,.18);
  border-color: rgba(22,230,208,.72);
}

.inline-grid {
  grid-template-columns: 1fr 1fr;
  margin-top: 8px;
}

.sticker-custom {
  grid-template-columns: 1fr 1fr 1fr auto;
}

.link-row,
.command-row {
  grid-template-columns: repeat(2, 1fr);
  margin-top: 8px;
}

.link-row a,
.command-row a,
.command-row button,
.text-grid button,
.sticker-custom button {
  display: inline-grid;
  place-items: center;
  text-decoration: none;
  font-weight: 950;
}

.range-line {
  grid-template-columns: auto 1fr auto;
  align-items: center;
}

.range-line label {
  margin: 0;
}

.search-row {
  grid-template-columns: 1fr auto;
}

.file-btn,
.upload-grid label {
  display: grid;
  place-items: center;
  min-height: 46px;
  border: 1px dashed rgba(255,255,255,.22);
  border-radius: 16px;
  background: rgba(255,255,255,.07);
  color: #fff;
}

.file-btn input,
.upload-grid input {
  display: none;
}

.category-row,
.pattern-row,
.preset-row,
.swatches {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 0 2px;
  scrollbar-width: none;
}

.category-row::-webkit-scrollbar,
.pattern-row::-webkit-scrollbar,
.preset-row::-webkit-scrollbar,
.swatches::-webkit-scrollbar {
  display: none;
}

.category-row button,
.preset-row button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  font-size: 11px;
  font-weight: 950;
}

.category-row button.active,
.preset-row button.active {
  border-color: rgba(22,230,208,.72);
  background: rgba(22,230,208,.18);
}

.pattern-row button {
  flex: 0 0 92px;
  overflow: hidden;
  min-height: 74px;
  padding: 0;
}

.pattern-row img {
  display: block;
  width: 100%;
  height: 50px;
  object-fit: cover;
}

.pattern-row span {
  display: block;
  padding: 4px 5px;
  font-size: 10px;
  font-weight: 900;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.text-grid {
  grid-template-columns: 1fr auto auto;
}

.swatches button {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.swatches button.active {
  border-color: #fff;
  box-shadow: 0 0 0 3px rgba(22,230,208,.25);
}

.export-mini {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 16px;
  background: rgba(255,255,255,.07);
}

.export-mini strong,
.export-mini span {
  color: #fff;
  font-size: 12px;
  font-weight: 950;
}

.send-row {
  grid-template-columns: repeat(4, 1fr);
}

.toast {
  position: absolute;
  z-index: 120;
  left: 50%;
  bottom: calc(var(--pad-h) + 18px + env(safe-area-inset-bottom));
  max-width: min(90vw, 390px);
  transform: translate(-50%, 16px);
  padding: 10px 13px;
  border-radius: 999px;
  background: rgba(7,17,28,.88);
  color: #fff;
  font-size: 12px;
  font-weight: 950;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.done {
  position: absolute;
  z-index: 200;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(2,8,14,.75);
  backdrop-filter: blur(14px);
}

.done-card {
  width: min(86vw, 360px);
  padding: 18px;
  border: 1px solid rgba(255,255,255,.16);
  border-radius: 24px;
  background: #0a1420;
  color: #fff;
  text-align: center;
  box-shadow: var(--shadow);
}

.done-card canvas {
  width: 100%;
  height: auto;
}

.done-card strong,
.done-card span {
  display: block;
}

.done-card strong {
  font-size: 22px;
}

.done-card span {
  margin: 8px 0 14px;
  color: #b6c4d4;
  font-size: 13px;
}

.done-card button {
  min-height: 44px;
  border: 0;
  border-radius: 16px;
  padding: 0 18px;
  background: linear-gradient(135deg, #16e6d0, #4f8cff);
  color: #06111d;
  font-weight: 950;
}

@media (max-width: 390px) {
  :root {
    --console-h: 170px;
    --pad-h: 72px;
    --top-safe: 146px;
    --bottom-safe: 92px;
  }

  .mission {
    min-height: 72px;
    padding-right: 102px;
  }

  .mission h1 {
    font-size: 18px;
  }

  .mission p {
    font-size: 9.5px;
  }

  .pad-btn {
    flex-basis: 55px;
    font-size: 9px;
  }
}

@media (min-width: 900px) {
  .app {
    border-radius: 30px;
  }
}
