:root {
  --bg: #1b1f33;
  --panel: rgba(255, 255, 255, 0.07);
  --panel-border: rgba(255, 255, 255, 0.12);
  --text: #f3ece4;
  --muted: #b8b2c8;
  --accent: #f4c462;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(120% 90% at 50% 0%, #2b3155 0%, var(--bg) 60%, #141726 100%);
  color: var(--text);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  flex-wrap: wrap;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  font-size: 18px;
  color: var(--accent);
  margin-right: 4px;
}

.pill {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 14px;
}
.pill.subtle { color: var(--muted); }

.actions {
  margin-left: auto;
  display: flex;
  gap: 6px;
}

button {
  font: inherit;
  color: var(--text);
  cursor: pointer;
}

.actions button {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  font-size: 18px;
  line-height: 1;
  transition: background 0.2s, transform 0.1s;
}
.actions button svg { width: 18px; height: 18px; vertical-align: middle; }
.actions button:hover { background: rgba(255, 255, 255, 0.14); }
.actions button:active { transform: scale(0.94); }
.actions button:disabled { opacity: 0.35; cursor: default; }
.actions button.off { opacity: 0.45; text-decoration: line-through; }

#stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 12px 14px;
}

#game {
  display: block;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  background: linear-gradient(180deg, #27305a 0%, #3d3f72 38%, #6f5a86 64%, #c98f86 100%);
  touch-action: none;
  cursor: grab;
}
#game.grabbing { cursor: grabbing; }

.hint {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  max-width: min(420px, 86vw);
  text-align: center;
  background: rgba(20, 22, 40, 0.72);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(6px);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 14px;
  color: var(--text);
  pointer-events: none;
  transition: opacity 0.6s;
}
.hint.fade { opacity: 0; }

#sandboxBar {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: center;
  padding: 0 12px 14px;
  flex-wrap: wrap;
}
#sandboxBar[hidden] { display: none; }
.swatches { display: flex; gap: 8px; }
.swatch {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid transparent;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.2);
  font-size: 13px;
  color: rgba(0, 0, 0, 0.55);
}
.swatch.active { border-color: #fff; }

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 14, 26, 0.55);
  backdrop-filter: blur(4px);
  z-index: 10;
  padding: 20px;
  animation: fadeIn 0.35s ease;
}
.overlay[hidden] { display: none; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.card {
  background: linear-gradient(180deg, rgba(52, 56, 94, 0.95), rgba(34, 37, 64, 0.95));
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 26px 26px 22px;
  width: min(340px, 100%);
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  max-height: 92vh;
  overflow: auto;
}
.card.wide { width: min(460px, 100%); text-align: left; }

h1 { margin: 0 0 4px; font-size: 40px; color: var(--accent); letter-spacing: 0.01em; }
h2 { margin: 0 0 10px; font-size: 24px; }
.lede { color: var(--muted); margin: 0 0 16px; }
.small { color: var(--muted); font-size: 14px; line-height: 1.45; }

.promises {
  list-style: none;
  padding: 0;
  margin: 0 0 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-size: 14px;
}
.promises li {
  background: var(--panel);
  border-radius: 10px;
  padding: 6px 8px;
}

.howto { padding-left: 20px; line-height: 1.5; margin: 0 0 8px; }
.howto li { margin-bottom: 6px; }

button.primary, button.soft {
  display: block;
  width: 100%;
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 600;
  margin-top: 8px;
  border: 1px solid transparent;
}
button.primary { background: var(--accent); color: #2b2233; }
button.primary:hover { filter: brightness(1.06); }
button.soft { background: var(--panel); border-color: var(--panel-border); }
button.soft:hover { background: rgba(255, 255, 255, 0.13); }
#sandboxBar button.soft { width: auto; margin: 0; padding: 8px 14px; font-size: 14px; }

.row { display: flex; gap: 10px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.row > button { flex: 1; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); margin-right: 12px; }

.levelGrid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
  max-height: 40vh;
  overflow: auto;
  padding: 2px;
}
.levelGrid button {
  height: 40px;
  border-radius: 10px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  font-size: 14px;
}
.levelGrid button.done { background: rgba(244, 196, 98, 0.22); border-color: rgba(244, 196, 98, 0.45); }
.levelGrid button.current { outline: 2px solid #fff; }

kbd {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 12px;
}

@media (max-width: 480px) {
  .brand { display: none; }
  #bar { padding: 8px 10px; }
  .actions button { width: 34px; height: 34px; font-size: 16px; }
}
