/* ==========================================================
   ToyKit — Editors, Event Matrix, Pixel Painter, Play & Wizard
   ========================================================== */

/* ========== LIBRARY PANEL ========== */
.category-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 8px 10px;
  border-bottom: 1.5px solid #EAE2D0;
  background: #FAF6EC;
}

.cat-pill {
  border: 1.6px solid var(--ink);
  border-radius: var(--radius-pill);
  background: #fff;
  padding: 4px 9px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.1s;
}

.cat-pill.is-active {
  background: var(--teal);
  color: #fff;
}

.library-grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  align-content: start;
}

.lib-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 9px 6px;
  background: var(--surface-alt);
  border: var(--border-thin);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  cursor: grab;
  transition: transform 0.08s, background-color 0.12s;
  touch-action: pan-y;
}

.lib-item:hover {
  background: var(--yellow-light);
  transform: translateY(-2px);
}

.lib-item:active {
  cursor: grabbing;
  transform: translate(1px, 1px);
  box-shadow: none;
}

.lib-item canvas {
  image-rendering: pixelated;
  width: 44px;
  height: 44px;
}

.lib-item-name {
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
}

.library-tip {
  padding: 8px 12px;
  background: var(--teal-light);
  border-top: var(--border-thin);
  font-size: 0.78rem;
  font-weight: 700;
  text-align: center;
}

/* ========== STAGE CANVAS & FLOATING BAR ========== */
#stage-canvas {
  background: #fff;
  border: var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  touch-action: none;
  cursor: default;
  max-width: 100%;
  max-height: 100%;
}

.stage-quick-bar {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  background: var(--surface);
  border: var(--border-thin);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  z-index: 15;
  /* An absolute box centred with left:50% would otherwise shrink to half the stage width. */
  width: max-content;
  max-width: calc(100% - 16px);
  flex-wrap: wrap;
  justify-content: center;
}
@media (max-width: 960px) {
  .stage-quick-bar { border-radius: var(--radius-md); }
}

.qbar-btn {
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-pill);
  background: var(--surface-alt);
  padding: 5px 11px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
}
.qbar-btn:hover { background: var(--yellow-light); }
.qbar-btn.qbar-danger { background: var(--coral-light); }
.qbar-btn.qbar-danger:hover { background: var(--coral); color: #fff; }

.path-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px;
  background: var(--yellow);
  border-bottom: var(--border-thin);
  font-size: 0.88rem;
}

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

.hud-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--surface-alt);
  border: 1.6px solid var(--ink);
  border-radius: var(--radius-pill);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
}

.stage-hint {
  margin-inline-start: auto;
  font-size: 0.8rem;
  color: var(--ink-muted);
  font-weight: 600;
}

/* ========== INSPECTOR PANEL ========== */
.inspector-empty {
  padding: 16px 14px;
  overflow-y: auto;
  text-align: center;
}

.empty-doodle {
  font-size: 2.2rem;
  margin-bottom: 6px;
}

.level-quick-card {
  margin-top: 18px;
  text-align: start;
  padding: 12px;
  background: var(--surface-alt);
  border: var(--border-thin);
  border-radius: var(--radius-md);
}

.level-quick-card h4 {
  margin: 0 0 10px;
  font-size: 0.9rem;
}

.inspector-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.obj-hero {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--surface-alt);
  border: var(--border-thin);
  border-radius: var(--radius-md);
}

.sprite-preview-box {
  background: repeating-conic-gradient(#EAE4D5 0% 25%, #FFFDF8 0% 50%) 50% / 12px 12px;
  border: var(--border-thin);
  border-radius: var(--radius-sm);
  image-rendering: pixelated;
  flex-shrink: 0;
}

.obj-hero-info {
  flex: 1;
  min-width: 0;
}

.insp-section {
  padding: 10px;
  background: var(--surface-alt);
  border: 1.6px solid #D9D0BD;
  border-radius: var(--radius-md);
}

.insp-label {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--ink-soft);
  margin-bottom: 8px;
}

.movement-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.move-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 5px;
  border: 1.8px solid var(--ink);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 700;
  text-align: center;
  transition: background-color 0.1s;
}

.move-card:hover {
  background: var(--teal-light);
}

.move-card.is-active {
  background: var(--yellow);
  box-shadow: var(--shadow-sm);
}

.move-card-icon {
  font-size: 1.2rem;
  line-height: 1;
}

.insp-actions-row {
  display: flex;
  gap: 8px;
  background: transparent;
  border: none;
  padding: 0;
}

/* ========== STORYBOARD GRID ========== */
.storyboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.level-card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.1s;
}

.level-card.is-current {
  box-shadow: 0 0 0 3px var(--teal), var(--shadow-md);
}

.level-thumb-wrap {
  position: relative;
  background: #222;
  aspect-ratio: 16 / 10;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-bottom: var(--border-thin);
  overflow: hidden;
}

.level-thumb-wrap canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.level-num-badge {
  position: absolute;
  top: 8px;
  inset-inline-start: 8px;
  background: var(--yellow);
  border: var(--border-thin);
  border-radius: var(--radius-pill);
  padding: 2px 10px;
  font-size: 0.78rem;
  font-weight: 900;
}

.level-card-body {
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.level-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ========== EVENT EDITOR MATRIX (KLIK & PLAY ICONIC GRID!) ========== */
.events-container {
  flex: 1;
  overflow: auto;
  padding-bottom: 24px;
}

.matrix-wrap {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  overflow-x: auto;
}

.event-matrix {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

.event-matrix th, .event-matrix td {
  border: 1.5px solid #D4CBB8;
  padding: 8px;
  vertical-align: middle;
}

.event-matrix thead th {
  background: var(--surface-alt);
  border-bottom: var(--border-thin);
  position: sticky;
  top: 0;
  z-index: 5;
  text-align: center;
  min-width: 78px;
}

.event-matrix thead th.col-cond {
  min-width: 260px;
  text-align: start;
  background: var(--yellow-light);
  padding-inline-start: 14px;
}

.col-header-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.76rem;
  font-weight: 800;
}

.col-header-inner canvas {
  image-rendering: pixelated;
  width: 30px;
  height: 30px;
}

.col-header-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.cond-cell {
  background: #FFFDF8;
  padding: 10px 12px !important;
}

.cond-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cond-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
}
.cond-pill:hover {
  background: var(--yellow-light);
  border-color: var(--ink);
}

.cond-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: var(--ink);
  color: #fff;
  border-radius: 50%;
  font-size: 0.74rem;
  font-weight: 800;
  flex-shrink: 0;
}

.action-cell {
  text-align: center;
  cursor: pointer;
  transition: background-color 0.1s;
  min-height: 54px;
}

.action-cell:hover {
  background: var(--teal-light);
}

.action-cell.has-actions {
  background: var(--green-light);
}

.action-cell-badge {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.action-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--green);
  color: #fff;
  border: 1.8px solid var(--ink);
  border-radius: 8px;
  font-weight: 900;
  font-size: 0.9rem;
  box-shadow: 1.5px 1.5px 0 var(--ink);
}

.action-mini-text {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ink);
  max-width: 82px;
  line-height: 1.15;
}

.action-add-hint {
  color: #C3B8A3;
  font-size: 1.1rem;
  font-weight: 800;
}

/* Sentence Cards View for Events */
.event-cards-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.event-sentence-card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 12px 16px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.ev-when-badge {
  background: var(--yellow);
  border: 1.6px solid var(--ink);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-weight: 800;
  font-size: 0.86rem;
}

.ev-then-arrow {
  font-weight: 900;
  font-size: 1.1rem;
  color: var(--teal);
}

.ev-action-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--green-light);
  border: 1.6px solid var(--ink);
  border-radius: var(--radius-pill);
  padding: 4px 11px;
  font-size: 0.84rem;
  font-weight: 700;
}

/* ========== PLAY MODAL & TOUCH CONTROLS ========== */
.play-window {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(1040px, 98vw);
  max-height: 96vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.play-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-alt);
  border-bottom: var(--border-thin);
}

.play-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.play-badge {
  background: var(--green);
  color: #fff;
  border: 1.8px solid var(--ink);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
  font-size: 0.8rem;
  font-weight: 800;
}

.play-badge.is-magic {
  background: var(--orange);
}

.play-level-pill {
  background: var(--yellow-light);
  border: 1.5px solid var(--ink);
  border-radius: var(--radius-pill);
  padding: 2px 9px;
  font-size: 0.8rem;
  font-weight: 700;
}

.play-hud-live {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
  font-size: 1rem;
}

.play-top-btns {
  display: flex;
  align-items: center;
  gap: 6px;
}

.play-stage-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12px;
  background: #232936;
  gap: 10px;
  overflow: auto;
}

.play-canvas-shell {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 70vh;
}

#play-canvas {
  border: 3px solid #FFFDF8;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  touch-action: none;
  max-width: 100%;
  max-height: 68vh;
  background: #111;
}

.play-overlay-banner {
  position: absolute;
  inset: 0;
  background: rgba(20, 25, 36, 0.72);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.banner-card {
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 22px 28px;
  text-align: center;
  max-width: 360px;
}

.banner-emoji {
  font-size: 3rem;
  margin-bottom: 6px;
}

.banner-card h2 {
  margin: 0 0 6px;
  font-size: 1.5rem;
}

.banner-card p {
  margin: 0 0 16px;
  color: var(--ink-soft);
  font-weight: 600;
}

.banner-btns {
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* Tactile On-Screen Touch Controls */
.touch-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(640px, 100%);
  padding: 6px 12px;
  gap: 16px;
  direction: ltr; /* D-pad layout left/right stays physically right! */
}
.touch-controls.no-dpad { justify-content: flex-end; } /* a lone Jump/Action group stays under the right thumb */

.touch-dpad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.tpad-mid {
  display: flex;
  gap: 36px;
}

.tpad-btn {
  width: 52px;
  height: 46px;
  border: 2.2px solid #FFFDF8;
  border-radius: 12px;
  background: #364156;
  color: #fff;
  font-size: 1.2rem;
  font-weight: 900;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 3px 0 #111622;
}

.tpad-btn:active, .tpad-btn.is-pressed {
  background: var(--yellow);
  color: var(--ink);
  transform: translateY(2px);
}

.touch-action-btns {
  display: flex;
  gap: 10px;
}

.tpad-action {
  min-width: 88px;
  height: 58px;
  border: 2.2px solid #FFFDF8;
  border-radius: 16px;
  font-weight: 800;
  font-size: 0.92rem;
  color: #fff;
  cursor: pointer;
  touch-action: none;
  box-shadow: 0 4px 0 #111622;
}

.tpad-jump { background: var(--teal); }
.tpad-fire { background: var(--orange); }
.tpad-action:active, .tpad-action.is-pressed {
  transform: translateY(3px);
  filter: brightness(1.1);
}

.play-footer-hint {
  padding: 7px 14px;
  background: var(--surface-alt);
  border-top: 1.5px solid #DED5C2;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
  text-align: center;
}

/* ========== STEP-THROUGH MAGIC WIZARD ========== */
.wizard-card {
  width: min(580px, 96vw);
}

.wizard-header {
  background: var(--orange-light);
  justify-content: flex-start;
  flex-wrap: wrap;
}

.wizard-spark {
  background: var(--orange);
  color: #fff;
  border: 1.6px solid var(--ink);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 800;
}

.wizard-encounter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 12px;
  background: var(--yellow-light);
  border: var(--border-thin);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  font-weight: 800;
  font-size: 1rem;
}

.wizard-encounter canvas {
  image-rendering: pixelated;
  width: 44px;
  height: 44px;
  background: #fff;
  border: 1.8px solid var(--ink);
  border-radius: 8px;
}

.wizard-sub {
  margin: 0 0 10px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.wizard-options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.wiz-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 11px;
  border: var(--border-thin);
  border-radius: var(--radius-md);
  background: #fff;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 700;
  text-align: start;
  transition: all 0.1s;
}

.wiz-opt:hover { background: var(--teal-light); }
.wiz-opt.is-selected {
  background: var(--green-light);
  box-shadow: var(--shadow-sm);
}

.wizard-sound-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1.5px dashed #D6CCB8;
  font-weight: 700;
  font-size: 0.86rem;
}

.wizard-sound-row select {
  flex: 1;
}

/* ========== PIXEL ART & ANIMATION STUDIO ========== */
.pixel-dialog {
  width: min(860px, 98vw);
}

.pixel-workspace {
  display: grid;
  grid-template-columns: 210px 1fr 165px;
  gap: 16px;
  padding: 16px;
  overflow-y: auto;
}

.pixel-tool-btns {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}

.ptool {
  padding: 8px 6px;
  border: var(--border-thin);
  border-radius: var(--radius-sm);
  background: #fff;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
}
.ptool.is-active {
  background: var(--yellow);
  box-shadow: var(--shadow-sm);
}

.pixel-quick-ops {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.pixel-palette {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 5px;
  margin-bottom: 8px;
}

.pal-swatch {
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: 6px;
  cursor: pointer;
}
.pal-swatch.is-active {
  outline: 3px solid var(--teal);
  transform: scale(1.08);
}

.custom-color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
  font-weight: 700;
}

.pixel-canvas-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

#pixel-canvas {
  border: var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  background: repeating-conic-gradient(#EAE4D5 0% 25%, #FFFDF8 0% 50%) 50% / 22px 22px;
  touch-action: none;
  cursor: crosshair;
  max-width: 100%;
  height: auto;
}

.pixel-frames-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.pixel-frames-list {
  display: flex;
  gap: 6px;
}

.frame-thumb {
  position: relative;
  border: 2px solid var(--ink);
  border-radius: 8px;
  padding: 3px;
  background: #fff;
  cursor: pointer;
}

.frame-thumb.is-active {
  background: var(--yellow);
  box-shadow: var(--shadow-sm);
}

.frame-thumb canvas {
  display: block;
  width: 36px;
  height: 36px;
  image-rendering: pixelated;
}

.frame-del-x {
  position: absolute;
  top: -7px;
  inset-inline-end: -7px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--ink);
  background: var(--coral);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.pixel-live-box {
  background: repeating-conic-gradient(#EAE4D5 0% 25%, #FFFDF8 0% 50%) 50% / 14px 14px;
  border: var(--border-thin);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#pixel-preview-canvas {
  image-rendering: pixelated;
  width: 96px;
  height: 96px;
}

/* ========== TEMPLATES & EXPORT CARDS ========== */
.templates-dialog {
  width: min(760px, 96vw);
}

.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}

.tpl-card {
  background: var(--surface-alt);
  border: var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.1s, background-color 0.12s;
  text-align: start;
}

.tpl-card:hover {
  background: var(--yellow-light);
  transform: translateY(-3px);
}

.tpl-icon {
  font-size: 2rem;
}

.tpl-card h4 {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
}

.tpl-card p {
  margin: 0;
  font-size: 0.83rem;
  color: var(--ink-soft);
  line-height: 1.35;
}

.tpl-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: auto;
}

.tpl-tag {
  background: #fff;
  border: 1.4px solid var(--ink);
  border-radius: var(--radius-pill);
  padding: 2px 8px;
  font-size: 0.72rem;
  font-weight: 700;
}

.export-options {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.export-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px;
  background: var(--surface-alt);
  border: var(--border-thin);
  border-radius: var(--radius-md);
}

.export-card-hero {
  background: var(--green-light);
  border-width: 2.2px;
}

.export-card h4 { margin: 0 0 4px; }
.export-card p { margin: 0; font-size: 0.84rem; color: var(--ink-soft); }
.export-icon { font-size: 2rem; flex-shrink: 0; }

/* ========== SHARE LINK & QR CODE MODAL ========== */
.share-dialog {
  width: min(540px, 96vw);
}

.share-body {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.share-qr-box {
  background: #fff;
  border: var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#share-qr-canvas {
  image-rendering: pixelated;
  max-width: 220px;
  height: auto;
  display: block;
}

.share-url-input {
  font-size: 0.78rem;
  font-family: monospace;
  text-align: left;
  background: var(--surface-alt);
}

.share-actions-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.share-actions-row a.btn {
  text-decoration: none;
}

.share-warn {
  background: var(--orange-light);
  border: var(--border-thin);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  width: 100%;
}

.share-privacy-note {
  margin: 4px 0 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
  font-weight: 600;
}
.share-privacy-note a { color: var(--teal); font-weight: 700; white-space: nowrap; }

/* ========== PICKER POPUPS (BG / ACTIONS / CONDITIONS) ========== */
.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.picker-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: var(--border-thin);
  border-radius: var(--radius-md);
  background: #fff;
  cursor: pointer;
  font-weight: 700;
  font-size: 0.86rem;
  text-align: start;
}

.picker-item:hover {
  background: var(--yellow-light);
}

.picker-item.is-selected {
  background: var(--green-light);
  box-shadow: var(--shadow-sm);
}

.bg-swatch-preview {
  width: 34px;
  height: 24px;
  border-radius: 5px;
  border: 1.5px solid var(--ink);
  flex-shrink: 0;
}

.action-list-existing {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.action-existing-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  background: var(--green-light);
  border: 1.6px solid var(--ink);
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 0.86rem;
}

@media (max-width: 760px) {
  .pixel-workspace {
    grid-template-columns: 1fr;
  }
  .wizard-options-grid {
    grid-template-columns: 1fr;
  }
  .export-card {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ==========================================================
   PHONES — portrait (≤600px wide) and landscape (≤500px tall)
   Goal: every control stays on screen. Portrait packs the top bar into three short rows
   ([logo][title][language] / [Play][Step][file buttons] / [mode tabs]), the stage toolbar
   into two and the HUD chips into one; the play window fills the screen. Landscape puts
   each bar on one row and the touch pad beside the game. Kept here, in the last
   stylesheet, so these rules win over layout.css and the rules above.
   ========================================================== */
@media (max-width: 600px) {
  /* --- Top bar: the action buttons join the top bar's own rows --- */
  .topbar {
    padding: 6px 8px 7px;
    column-gap: 5px;
    row-gap: 0;
  }
  .topbar::after { /* line break after the first row */
    content: '';
    order: 3;
    flex-basis: 100%;
  }
  .topbar-brand { order: 1; flex: 1 1 0; gap: 6px; }
  .brand-logo { padding: 4px 9px; font-size: 1rem; }
  .project-title-input { flex: 1 1 auto; width: auto; min-width: 0; padding: 5px 8px; font-size: 0.9rem; }
  #btn-pwa-install { order: 2; }
  .lang-select { order: 2; min-height: 36px; padding: 4px 6px; }
  .topbar-actions { display: contents; }
  .topbar-divider { display: none; }
  .topbar-actions > .btn { margin-top: 6px; min-height: 38px; padding: 6px 9px; }
  #btn-play-normal, #btn-play-step, #btn-templates, #btn-share-qr, #btn-export-menu { order: 4; }
  #btn-play-normal, #btn-play-step { flex: 1 1 auto; }
  #btn-pwa-install { margin-top: 0; min-height: 36px; }
  .mode-tabs { order: 5; width: 100%; margin-top: 6px; padding: 3px; gap: 4px; }
  .mode-tab { flex: 1 1 0; min-width: 0; padding: 6px 4px; gap: 4px; font-size: 0.8rem; white-space: nowrap; }
  .mode-tab svg { display: none; }
  .mode-tab > span[data-i18n] { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .tab-pill { padding: 0 6px; font-size: 0.7rem; }

  /* --- Stage toolbar: [Objects][Background][Properties] / [level][grid][undo][redo] --- */
  .stage-toolbar { padding: 6px 8px; gap: 6px 5px; justify-content: flex-start; }
  .stage-toolbar-group { display: contents; }
  #btn-toggle-library, #btn-stage-bg, #btn-toggle-inspector {
    flex: 1 1 28%;
    min-width: 0;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 6px;
    line-height: 1.35;
    font-size: 0.78rem;
    text-align: center;
  }
  #btn-toggle-library { order: 1; }
  #btn-stage-bg { order: 2; }
  #btn-toggle-inspector { order: 3; }
  #stage-level-select { order: 4; flex: 1 1 120px; min-width: 0; }
  #btn-grid-snap { order: 5; }
  #btn-undo { order: 6; }
  #btn-redo { order: 7; }
  #btn-grid-snap, #btn-undo, #btn-redo { min-width: 40px; padding: 5px 8px; }
  #btn-grid-snap > span {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }

  .stage-canvas-wrap { padding: 8px; }
  .stage-quick-bar { bottom: 6px; gap: 4px; padding: 4px 6px; }
  .qbar-btn { padding: 4px 8px; font-size: 0.76rem; }

  /* --- HUD chips: one compact row, no hint text --- */
  .stage-footer { padding: 5px 8px; gap: 6px; }
  .stage-hint { display: none; }
  .hud-chip { padding: 3px 8px; gap: 5px; font-size: 0.76rem; }

  /* --- Levels and Rule Grid pages --- */
  #view-storyboard, #view-events { padding: 12px 10px; }
  .storyboard-header, .events-header { gap: 10px; margin-bottom: 12px; }
  .section-title { font-size: 1.15rem; }
  .section-sub { font-size: 0.85rem; }
  .event-matrix { min-width: 0; }
  .event-matrix thead th { min-width: 60px; }
  .event-matrix thead th.col-cond { min-width: 168px; }

  /* --- Dialogs: less margin. Pixel painter: tools and colours sit right above the drawing grid,
     everything else (undo/flip, frames, name, custom colour, preview) below it. --- */
  .modal-backdrop { padding: 8px; }
  .pixel-workspace { padding: 10px; gap: 10px; }
  .pixel-tools-col, .pixel-canvas-col { display: contents; }
  .pixel-tool-btns { order: 1; margin: 0; grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .ptool { padding: 7px 2px; font-size: 0.76rem; }
  .pixel-palette { order: 2; margin: 0; grid-template-columns: repeat(10, 1fr); gap: 4px; }
  .pixel-tools-col > .insp-label { display: none; }
  #pixel-canvas { order: 3; justify-self: center; }
  .pixel-quick-ops { order: 4; justify-content: center; }
  .pixel-frames-bar { order: 5; }
  .pixel-tools-col > .field-label { order: 6; margin: 0; }
  .custom-color-row { order: 7; }
  .pixel-preview-col { order: 8; }

  /* --- Play window: full screen, compact bar, game + touch pad fit the height --- */
  #play-modal { padding: 0; }
  .play-window { width: 100%; height: 100%; max-height: none; border: 0; border-radius: 0; }
  .play-topbar { padding: 6px 8px; gap: 6px; }
  .play-title-wrap { flex: 1 1 100%; min-width: 0; gap: 6px; }
  #play-game-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .play-badge { white-space: nowrap; flex-shrink: 0; }
  .play-level-pill { min-width: 0; max-width: 45%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .play-top-btns { flex-wrap: wrap; justify-content: flex-end; margin-inline-start: auto; }
  #btn-play-toggle-touch, #btn-play-restart { font-size: 0; gap: 0; min-width: 40px; }
  #btn-play-toggle-touch::before { content: '📱'; font-size: 1rem; }
  #btn-play-restart::before { content: '🔄'; font-size: 1rem; }
  .play-stage-area { padding: 8px; gap: 8px; }
  .play-canvas-shell { max-height: none; }
  #play-canvas { max-height: calc(100vh - 270px); max-height: calc(100dvh - 270px); }
  .play-footer-hint { display: none; }
  .touch-controls { padding: 4px 2px; gap: 8px; }
  .tpad-mid { gap: 30px; }
  .tpad-btn { width: 48px; height: 44px; }
  .touch-action-btns { gap: 8px; }
  .tpad-action { min-width: 72px; height: 54px; padding: 2px 6px; font-size: 0.85rem; }
}

/* Narrow phones: Play and Step-by-Step keep their words but drop their icons, HUD chips keep only their emoji. */
@media (max-width: 480px) {
  #btn-play-normal svg, #btn-play-step svg { display: none; }
  .hud-chip > span[data-i18n] { font-size: 0; }
  .hud-chip > span[data-i18n]::before { font-size: 0.95rem; }
  .hud-chip > span[data-i18n="hud.showScore"]::before { content: '⭐'; }
  .hud-chip > span[data-i18n="hud.showLives"]::before { content: '❤️'; }
  .hud-chip > span[data-i18n="hud.showTimer"]::before { content: '⏱️'; }
}

/* The smallest phones (iPhone SE 1st gen, 320px): Step-by-Step shows only its wand. */
@media (max-width: 359px) {
  .brand-text { display: none; }
  #btn-play-step svg { display: inline; }
  #btn-play-step > span {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  #btn-play-step { flex: 0 0 auto; }
  #btn-toggle-library, #btn-stage-bg, #btn-toggle-inspector { font-size: 0.74rem; padding: 6px 4px; }
}

/* Phones held sideways: one row per bar, so the stage keeps most of the short screen. */
@media (orientation: landscape) and (max-height: 500px) {
  .topbar { flex-wrap: wrap; padding: 4px 8px; column-gap: 6px; row-gap: 4px; }
  .topbar::after { content: none; }
  .topbar-actions { display: contents; }
  .topbar-divider { display: none; }
  .topbar-brand { order: 1; flex: 1 1 120px; min-width: 0; gap: 6px; }
  .brand-text { display: none; }
  .brand-logo { padding: 3px 8px; }
  .project-title-input { flex: 1 1 auto; width: auto; min-width: 0; padding: 4px 8px; font-size: 0.88rem; }
  .mode-tabs { order: 2; width: auto; flex: 0 0 auto; margin: 0; padding: 3px; gap: 3px; }
  .mode-tab { flex: 0 0 auto; padding: 5px 8px; gap: 5px; font-size: 0.8rem; white-space: nowrap; }
  .mode-tab svg { display: block; }
  .topbar-actions > .btn { margin: 0; min-height: 36px; padding: 5px 9px; }
  #btn-play-normal, #btn-play-step, #btn-templates, #btn-share-qr, #btn-export-menu { order: 3; }
  #btn-pwa-install { display: none; } /* keeps the bar on one row; installing works from portrait or the browser menu */
  #btn-play-normal, #btn-play-step { flex: 0 0 auto; }
  #btn-play-step > span {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .lang-select { order: 4; min-height: 36px; padding: 3px 6px; }

  .stage-toolbar { padding: 4px 8px; gap: 5px; justify-content: flex-start; }
  .stage-toolbar-group { display: contents; }
  #btn-toggle-library, #btn-stage-bg, #btn-toggle-inspector {
    flex: 0 1 auto; display: inline-flex; min-height: 32px; padding: 4px 8px; font-size: 0.78rem;
  }
  #btn-toggle-library { order: 1; }
  #btn-stage-bg { order: 2; }
  #btn-toggle-inspector { order: 3; }
  #stage-level-select { order: 4; flex: 1 1 100px; min-width: 0; min-height: 32px; }
  #btn-grid-snap { order: 5; }
  #btn-undo { order: 6; }
  #btn-redo { order: 7; }
  #btn-grid-snap, #btn-undo, #btn-redo { min-height: 32px; min-width: 38px; padding: 4px 8px; }
  #btn-grid-snap > span {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .stage-canvas-wrap { padding: 6px; }
  .stage-quick-bar { bottom: 4px; gap: 4px; padding: 3px 6px; }
  .qbar-btn { padding: 3px 8px; font-size: 0.76rem; }
  .stage-footer { padding: 4px 8px; gap: 6px; }
  .stage-hint { display: none; }
  .hud-chip { padding: 2px 8px; gap: 5px; font-size: 0.76rem; }

  /* Play: full screen, one-row bar, D-pad left of the game and the action buttons right of it
     (in every language: the stage area is LTR, the game card text keeps the page direction). */
  #play-modal { padding: 0; }
  .play-window { width: 100%; height: 100%; max-height: none; border: 0; border-radius: 0; }
  .play-topbar { flex-wrap: nowrap; padding: 4px 8px; gap: 8px; }
  .play-title-wrap { flex: 1 1 auto; min-width: 0; gap: 6px; }
  #play-game-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .play-badge { white-space: nowrap; flex-shrink: 0; }
  .play-level-pill { min-width: 0; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .play-hud-live, .play-top-btns { flex: 0 0 auto; }
  #btn-play-toggle-touch, #btn-play-restart { font-size: 0; gap: 0; min-width: 40px; }
  #btn-play-toggle-touch::before { content: '📱'; font-size: 1rem; }
  #btn-play-restart::before { content: '🔄'; font-size: 1rem; }
  .play-footer-hint { display: none; }
  .play-stage-area { flex-direction: row; direction: ltr; padding: 6px; gap: 10px; }
  html[dir="rtl"] .play-canvas-shell { direction: rtl; }
  .play-canvas-shell { flex: 0 1 auto; min-width: 0; max-height: none; }
  #play-canvas { max-height: calc(100vh - 64px); max-height: calc(100dvh - 64px); }
  .touch-controls { display: contents; }
  .touch-dpad { order: -1; }
  .touch-action-btns { flex-direction: column; gap: 8px; }
  .tpad-mid { gap: 30px; }
  .tpad-btn { width: 48px; height: 44px; }
  .tpad-action { min-width: 72px; height: 52px; padding: 2px 6px; font-size: 0.85rem; }
}
@media (orientation: landscape) and (max-height: 500px) and (max-width: 839px) {
  .mode-tab > span[data-i18n] {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap;
  }
  .tab-pill { display: none; }
}
@media (orientation: landscape) and (max-height: 500px) and (min-width: 840px) {
  .mode-tab svg { display: none; }
}
