:root {
  --grass: #7BB661;
  --sky: #4FA8D8;
  --coral: #E8563F;
  --gold: #F2B33D;
  --oak: #8B5E3C;
  --slate: #3F4A52;
  --bevel: #5C6A74;
  --cream: #F5EFE2;
  --ink: #1B2328;
  --panel: #3A464F;
  --panel-dark: #2C3740;
  --pixel: 'Pixelify Sans', 'Trebuchet MS', sans-serif;
  --text: 'Nunito', 'Segoe UI', sans-serif;
  --num: 'Silkscreen', 'Courier New', monospace;
  --plate-slice: 12;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: #232f2c url('assets/elements/backdrop_pixel_tile.webp') repeat;
  background-size: 512px 512px;
  background-blend-mode: multiply;
  color: var(--cream);
  font-family: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: none;
  font-smooth: never;
  text-rendering: geometricPrecision;
}

button { font: inherit; color: inherit; }
img { display: block; }
::selection { background: var(--gold); color: var(--ink); }

#page {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
}

/* ---- stone plates ---------------------------------------------------- */

.plate {
  position: absolute;
  inset: 0;
  z-index: 0;
  border: calc(var(--plate-slice) * 1px) solid transparent;
  border-image-slice: var(--plate-slice) fill;
  border-image-width: var(--plate-slice);
  border-image-repeat: stretch;
  pointer-events: none;
}

.topbar-plate {
  border-image-source: url('assets/elements/stone_panel_plates_04_score_strip.webp');
}

.rail-plate {
  border-image-source: url('assets/elements/stone_panel_plates_01_challenge_card.webp');
}

.tray-plate {
  border-image-source: url('assets/elements/stone_panel_plates_02_code_tray.webp');
}

.control-plate {
  border-image: url('assets/elements/stone_panel_plates_03_control_bar.webp') 10 fill stretch;
  border-width: 10px;
}

.overlay-plate {
  border-image: url('assets/elements/stone_panel_plates_01_challenge_card.webp') 12 fill stretch;
  border-width: 12px;
}

/* ---------------------------------------------------------------- topbar */

#topbar {
  position: relative;
  flex: 0 0 clamp(78px, 10.4vh, 104px);
  min-height: 0;
}

.topbar-content {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 6px 20px;
}

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

.crest {
  width: clamp(44px, 5.4vh, 62px);
  height: auto;
  image-rendering: auto;
}

.wordmark {
  height: clamp(44px, 6.6vh, 72px);
  width: auto;
}

.top-strip {
  flex: 1 1 auto;
  min-width: 0;
  height: 72%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: clamp(8px, 1.2vw, 20px);
  padding: 0 clamp(10px, 1.1vw, 18px);
  background: #303B44;
  border: 2px solid #64737D;
  border-right-color: #1C252B;
  border-bottom-color: #1C252B;
  overflow: hidden;
}

.challenge-tag {
  display: flex;
  flex-direction: column;
  justify-content: center;
  flex: 1 1 auto;
  min-width: 0;
  line-height: 1;
}

.tag-label {
  font-family: var(--pixel);
  font-size: clamp(8px, 0.62vw, 11px);
  letter-spacing: 1.8px;
  color: var(--gold);
  white-space: nowrap;
}

.tag-label b { font-weight: 700; }

#challengeName {
  margin-top: 4px;
  font-family: var(--text);
  font-weight: 800;
  font-size: clamp(12px, 1.05vw, 18px);
  color: var(--cream);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex: 0 0 auto;
}

.stat-label {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 1.6px;
  color: #AAB7BE;
  margin-bottom: 3px;
}

.stat-value {
  font-family: var(--num);
  font-size: clamp(15px, 1.55vw, 26px);
  font-variant-numeric: tabular-nums;
  color: var(--cream);
  letter-spacing: 0.5px;
}

.score-stat .stat-value { color: var(--gold); }

.timer-stat {
  flex-direction: row;
  gap: 7px;
}

.timer-stat .stat-value.is-urgent { color: var(--coral); }

.clock-icon {
  width: clamp(15px, 1.35vw, 23px);
  height: auto;
  color: var(--gold);
}

.round-stat .stat-value { font-size: clamp(14px, 1.4vw, 24px); }

.medal-chip {
  position: relative;
  flex: 0 0 auto;
  width: clamp(38px, 4.6vh, 54px);
  height: calc(clamp(38px, 4.6vh, 54px) * 1.33);
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.medal-chip .medal {
  width: 100%;
  height: 100%;
  object-fit: contain;
  margin-top: -8px;
}

.medal-count {
  position: absolute;
  right: -5px;
  bottom: 0;
  min-width: 18px;
  padding: 1px 3px;
  background: #242E35;
  border: 2px solid #66757F;
  font-family: var(--num);
  font-size: 10px;
  line-height: 1.1;
  color: var(--gold);
  text-align: center;
}

.sound-btn {
  flex: 0 0 auto;
  width: clamp(30px, 3.4vh, 40px);
  height: clamp(30px, 3.4vh, 40px);
  padding: 6px;
  background: #34414A;
  border: 2px solid #687882;
  border-right-color: #1D262C;
  border-bottom-color: #1D262C;
  color: #CBD5D9;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.sound-btn svg { width: 100%; height: 100%; }
.sound-btn .sound-off { display: none; }
.sound-btn.is-off .sound-on { display: none; }
.sound-btn.is-off .sound-off { display: block; }
.sound-btn:active { transform: translate(1px, 1px); }

/* ------------------------------------------------------------- workshop */

#workshop {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: clamp(200px, 16.6vw, 316px) minmax(0, 1fr) clamp(238px, 18.4vw, 342px);
  gap: 8px;
}

#leftRail,
#rightRail,
#stage {
  position: relative;
  min-height: 0;
}

.rail-inner,
.tray-inner {
  position: relative;
  z-index: 1;
  height: 100%;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: inset 0 0 28px rgba(8, 14, 18, 0.3);
}

.rail-head {
  font-family: var(--pixel);
  font-size: clamp(16px, 1.25vw, 21px);
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--cream);
  line-height: 1;
}

.rail-help,
.tray-help {
  margin: 6px 0 0;
  font-family: var(--text);
  font-weight: 700;
  font-size: clamp(9px, 0.66vw, 11.5px);
  line-height: 1.25;
  color: #B9C5CA;
}

.palette-group { flex: 0 0 auto; }
.palette-group:first-of-type { margin-top: 10px; }

.palette-group h2 {
  margin: 0 0 5px;
  font-family: var(--pixel);
  font-size: clamp(12px, 0.95vw, 16px);
  font-weight: 700;
  letter-spacing: 1.4px;
  color: var(--cream);
  line-height: 1;
}

.palette-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 6px;
}

.pal-item {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 2px 0 1px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  cursor: grab;
  touch-action: none;
  min-width: 0;
  background: rgba(26, 34, 40, 0.32);
  box-shadow: inset 0 0 0 2px rgba(10, 16, 20, 0.22), inset 0 2px 0 rgba(245, 239, 226, 0.045);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 5px), calc(100% - 5px) 100%, 0 100%);
  transition: background 90ms steps(2);
}

.pal-item:hover { background: rgba(48, 60, 68, 0.55); }
.pal-item:active { background: rgba(58, 72, 80, 0.7); }

.pal-item img {
  width: clamp(52px, 5vw, 94px);
  height: auto;
  filter: drop-shadow(0 3px 0 rgba(17, 24, 28, 0.32));
  transition: transform 90ms steps(2);
  pointer-events: none;
}

.pal-item span {
  font-family: var(--text);
  font-weight: 800;
  font-size: clamp(9.5px, 0.72vw, 12.5px);
  line-height: 1.04;
  text-align: center;
  color: var(--cream);
  pointer-events: none;
}

.pal-item:hover img,
.pal-item:focus-visible img { transform: translateY(-4px); }
.pal-item:active img { transform: translateY(2px); filter: brightness(0.88); }
.pal-item:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

.is-locked .pal-item { pointer-events: none; opacity: 0.55; }
.pal-item.is-dragging-source img { transform: translateY(-4px); opacity: 0.42; }
.pal-item.is-dragging-source span { opacity: 0.55; }
.is-locked .p-remove { pointer-events: none; opacity: 0.4; }

.pal-item.is-hinted img {
  animation: hintNudge 680ms steps(2) infinite;
}

@keyframes hintNudge {
  0%, 100% { transform: translateY(0); filter: drop-shadow(0 3px 0 rgba(17,24,28,0.32)); }
  50% { transform: translateY(-5px); filter: drop-shadow(0 3px 0 rgba(242,179,61,0.65)); }
}

.dotted-rule {
  flex: 0 0 auto;
  margin: 8px 0 6px;
  border-top: 2px dotted rgba(245, 239, 226, 0.26);
}

/* ----------------------------------------------------------------- stage */

#stage {
  display: grid;
  grid-template-rows: minmax(0, 1fr) clamp(100px, 13.2vh, 124px);
  gap: 8px;
}

#arenaWrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #7CC6E8;
  border: 2px solid #27333A;
  box-shadow: inset 0 0 0 2px rgba(245, 239, 226, 0.13);
}

.arena-vignette {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(ellipse at 50% 47%, rgba(8, 14, 18, 0) 50%, rgba(8, 14, 18, 0.26) 100%);
}

#arena {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#arena:active { cursor: grabbing; }

.arena-toast {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 4;
  max-width: min(88%, 520px);
  padding: 8px 14px;
  background: #2A343C;
  border: 2px solid #6A7A85;
  border-right-color: #1A2228;
  border-bottom-color: #1A2228;
  font-family: var(--text);
  font-weight: 800;
  font-size: 13px;
  line-height: 1.2;
  color: var(--cream);
  text-align: center;
}

.arena-toast.is-good {
  color: var(--ink);
  background: var(--gold);
  border-color: #FFD98C #93661A #93661A #FFD98C;
}

/* ----------------------------------------------------------- control bar */

#controlBar {
  position: relative;
  min-height: 0;
}

.control-content {
  position: relative;
  z-index: 1;
  height: 100%;
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.2vw, 18px);
  padding: 8px 12px;
}

.objective-card {
  flex: 1 1 auto;
  min-width: 0;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 6px 14px;
  background: #333F48;
  border: 2px solid #667782;
  border-right-color: #1D262C;
  border-bottom-color: #1D262C;
  overflow: hidden;
}

.objective-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.objective-head {
  font-family: var(--pixel);
  font-size: clamp(9px, 0.68vw, 12px);
  letter-spacing: 1.8px;
  color: var(--gold);
  line-height: 1;
}

.quick-count {
  font-family: var(--pixel);
  font-size: clamp(7px, 0.54vw, 9px);
  letter-spacing: 1.2px;
  color: #AAB8BE;
  white-space: nowrap;
  line-height: 1;
}

.quick-count b {
  font-family: var(--num);
  font-size: clamp(9px, 0.68vw, 11px);
  color: var(--cream);
  font-weight: 400;
}

.objective-text {
  margin-top: 3px;
  font-family: var(--text);
  font-weight: 800;
  font-size: clamp(14px, 1.16vw, 21px);
  line-height: 1.05;
  color: var(--cream);
}

.hint-text {
  margin-top: 4px;
  font-family: var(--text);
  font-weight: 800;
  font-size: clamp(10px, 0.74vw, 13px);
  line-height: 1.15;
  color: var(--gold);
}

.ring-wrap {
  position: relative;
  flex: 0 0 clamp(64px, 6.1vw, 102px);
  width: clamp(64px, 6.1vw, 102px);
  height: clamp(64px, 6.1vw, 102px);
}

#timerRing {
  width: 100%;
  height: 100%;
  display: block;
}

.ring-time {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 6px;
  font-family: var(--num);
  font-size: clamp(13px, 1.25vw, 21px);
  font-variant-numeric: tabular-nums;
  color: var(--cream);
  line-height: 1;
}

.ring-unit {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 17%;
  text-align: center;
  font-family: var(--pixel);
  font-size: clamp(6px, 0.48vw, 8px);
  letter-spacing: 1.5px;
  color: #C6D0D5;
  line-height: 1;
}

.ring-wrap.is-urgent .ring-time { color: var(--coral); }

.action-cluster {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
}

.buttons {
  display: flex;
  gap: clamp(4px, 0.7vw, 10px);
}

.action-btn {
  appearance: none;
  border: 0;
  background: transparent;
  padding: 0;
  width: clamp(44px, 4.5vw, 68px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.action-btn img {
  width: 100%;
  height: auto;
  filter: drop-shadow(0 3px 0 rgba(17, 24, 28, 0.3));
  transition: transform 70ms steps(1);
  pointer-events: none;
}

.action-btn span {
  margin-top: -1px;
  font-family: var(--pixel);
  font-size: clamp(7px, 0.56vw, 10px);
  letter-spacing: 1.2px;
  color: #D6DFE2;
  line-height: 1;
  pointer-events: none;
}

.action-btn:hover img { transform: translateY(-3px); }
.action-btn:active img { transform: translateY(3px); filter: brightness(0.86); }
.action-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }
.action-btn.is-busy { opacity: 0.42; pointer-events: none; }

.key-cap {
  font-family: var(--pixel);
  font-size: clamp(6px, 0.5vw, 9px);
  letter-spacing: 1.4px;
  color: #96A6AD;
  line-height: 1;
  padding-right: 2px;
}

/* ------------------------------------------------------------ program tray */

.tray-inner { padding: 16px 14px 14px; }

.tray-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.tray-head h2 {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(15px, 1.2vw, 21px);
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--cream);
  line-height: 1;
  white-space: nowrap;
}

.tray-sub {
  font-family: var(--pixel);
  font-size: clamp(6px, 0.48vw, 8px);
  letter-spacing: 1.2px;
  color: #96A6AD;
  white-space: nowrap;
}

.slots {
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow-y: auto;
  padding: 1px 3px 3px 1px;
  scrollbar-width: thin;
  scrollbar-color: #6E7D87 #2E3941;
}

.slot {
  position: relative;
  flex: 1 1 0;
  min-height: 32px;
  max-height: 64px;
  background: linear-gradient(180deg, #344049 0%, #2B363F 100%);
  border: 2px solid #223039;
  box-shadow: inset 2px 2px 0 rgba(18, 24, 28, 0.45), inset -1px -1px 0 rgba(245, 239, 226, 0.06);
  clip-path: polygon(0 0, 100% 0, 100% calc(100% - 7px), calc(100% - 7px) 100%, 0 100%);
  transition: background 0ms;
}

.slot::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  width: 5px;
  height: 12px;
  transform: translateY(-50%);
  background: #1E272D;
  border-right: 2px solid #4C5B65;
  z-index: 0;
}

.slot::after {
  content: '';
  position: absolute;
  left: 13px;
  right: 9px;
  top: 50%;
  border-top: 2px dotted rgba(245, 239, 226, 0.1);
  z-index: 0;
}

.slot.is-full::after { display: none; }
.slot.is-full::before { opacity: 0.55; }

.slot.valid { animation: slotPulse 520ms steps(1) infinite; }
.slot.hot {
  background: #43525C;
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

@keyframes slotPulse {
  0%, 49% { background: #2E3942; }
  50%, 100% { background: #3E4C56; }
}

.placed {
  position: absolute;
  inset: 2px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 1px 16px 1px 3px;
  background: #3D4A53;
  border-left: 5px solid var(--tone, var(--grass));
  overflow: hidden;
}

.placed[data-tone="green"] { background: #3E4E3C; border-left-color: var(--grass); }
.placed[data-tone="blue"] { background: #35505E; border-left-color: var(--sky); }
.placed[data-tone="red"] { background: #532F2B; border-left-color: var(--coral); }
.placed[data-tone="gold"] { background: #4E442C; border-left-color: var(--gold); }
.placed[data-tone="brown"] { background: #4A3930; border-left: 5px solid var(--oak); }
.placed[data-tone="slate"] { background: #37434C; border-left-color: #8FA0AA; }

.placed img {
  width: clamp(22px, 2.2vw, 30px);
  height: auto;
  flex: 0 0 auto;
  pointer-events: none;
}

.placed .p-name {
  font-family: var(--text);
  font-weight: 800;
  font-size: clamp(9px, 0.74vw, 12.5px);
  line-height: 1;
  color: var(--cream);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
}

.placed .p-index {
  font-family: var(--num);
  font-size: clamp(7px, 0.55vw, 9px);
  color: #D5DEE1;
  flex: 0 0 auto;
  opacity: 0.7;
}

.placed .p-tag {
  font-family: var(--pixel);
  font-size: clamp(7px, 0.55vw, 9px);
  letter-spacing: 0.5px;
  color: var(--ink);
  background: var(--gold);
  padding: 1px 3px;
  flex: 0 0 auto;
  line-height: 1;
}

.p-remove {
  position: absolute;
  right: 1px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  appearance: none;
  border: 0;
  background: #2C373F;
  color: #C8D2D6;
  font-family: var(--pixel);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.p-remove:hover { background: var(--coral); color: var(--cream); }

.placed.is-firing {
  box-shadow: inset 0 0 0 2px var(--gold);
  background: #556150;
}

.placed.is-firing::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 2px solid var(--gold);
  pointer-events: none;
}

.placed.jolt { animation: jolt 130ms steps(2) 1; }
@keyframes jolt {
  0% { transform: translateY(-3px); }
  50% { transform: translateY(1px); }
  100% { transform: translateY(0); }
}

.tray-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 2px dotted rgba(245, 239, 226, 0.22);
}

.block-count {
  font-family: var(--pixel);
  font-size: clamp(8px, 0.62vw, 11px);
  letter-spacing: 1.4px;
  color: #C7D1D5;
}

.block-count b {
  font-family: var(--num);
  font-size: clamp(11px, 0.86vw, 15px);
  color: var(--gold);
  font-weight: 400;
}

.clear-btn {
  appearance: none;
  border: 2px solid #63737D;
  border-right-color: #1D262C;
  border-bottom-color: #1D262C;
  background: #333F48;
  color: #D8E0E3;
  font-family: var(--pixel);
  font-size: clamp(8px, 0.62vw, 11px);
  letter-spacing: 1.4px;
  padding: 4px 7px;
  cursor: pointer;
}

.clear-btn:hover { background: #44515B; }
.clear-btn:active { transform: translateY(2px); }

/* --------------------------------------------------------------- drag */

.drag-ghost {
  position: fixed;
  z-index: 120;
  width: 84px;
  height: 88px;
  margin-left: -42px;
  margin-top: -62px;
  pointer-events: none;
  filter: drop-shadow(0 6px 0 rgba(17, 24, 28, 0.38));
}

.drag-ghost img { width: 100%; height: 100%; object-fit: contain; }

.dust {
  position: fixed;
  z-index: 130;
  width: 6px;
  height: 6px;
  background: var(--cream);
  pointer-events: none;
  animation: dust 420ms steps(3) forwards;
}

@keyframes dust {
  0% { opacity: 1; transform: translate(0, 0); }
  33% { opacity: 0.85; transform: translate(calc(var(--dx) * 0.45), calc(var(--dy) * 0.45)); }
  66% { opacity: 0.5; transform: translate(calc(var(--dx) * 0.7), calc(var(--dy) * 0.7)); }
  100% { opacity: 0; transform: translate(var(--dx), var(--dy)); }
}

/* --------------------------------------------------------------- overlay */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(21, 28, 33, 0.84);
}

.overlay[hidden] { display: none; }

.overlay-card {
  position: relative;
  width: min(92vw, 470px);
  max-height: 92dvh;
  overflow: visible;
}

.overlay-inner {
  position: relative;
  z-index: 1;
  padding: 64px 28px 26px;
  max-height: 92dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.overlay-medal {
  position: absolute;
  top: -62px;
  left: 50%;
  transform: translateX(-50%);
  width: 92px;
  height: 122px;
  display: none;
  pointer-events: none;
}

.overlay-medal.show { display: block; }
.overlay-medal img { width: 100%; height: 100%; object-fit: contain; }
.overlay-medal.silver img { filter: grayscale(1) brightness(1.35); }
.overlay-medal.bronze img { filter: sepia(1) saturate(1.5) brightness(0.82); }
.overlay.no-medal .overlay-inner { padding-top: 30px; }

.overlay-eyebrow {
  font-family: var(--pixel);
  font-size: 11px;
  letter-spacing: 2.2px;
  color: var(--gold);
  line-height: 1;
}

.overlay-eyebrow.is-bad { color: var(--coral); }

.overlay-inner h2 {
  margin: 8px 0 0;
  font-family: var(--pixel);
  font-size: clamp(24px, 3.6vw, 40px);
  font-weight: 700;
  letter-spacing: 1.5px;
  line-height: 1;
  color: var(--cream);
  text-transform: uppercase;
}

.overlay-body {
  margin: 10px 0 0;
  font-family: var(--text);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.35;
  color: #D8E0E3;
  max-width: 340px;
}

.overlay-stats {
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 18px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 2px dotted rgba(245, 239, 226, 0.24);
}

.overlay-stats:empty { display: none; }

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

.ov-stat span {
  font-family: var(--pixel);
  font-size: 8px;
  letter-spacing: 1.4px;
  color: #AAB8BE;
}

.ov-stat b {
  font-family: var(--num);
  font-size: 20px;
  font-weight: 400;
  color: var(--gold);
  line-height: 1;
}

.pixel-button {
  margin-top: 18px;
  appearance: none;
  border: 2px solid #A9D883;
  border-right-color: #3A5F29;
  border-bottom-color: #3A5F29;
  background: var(--grass);
  color: #17220F;
  font-family: var(--pixel);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1.6px;
  padding: 10px 24px;
  cursor: pointer;
  text-transform: uppercase;
}

.pixel-button:hover { background: #8AC96E; }
.pixel-button:active { transform: translate(2px, 2px); border-color: #3A5F29 #A9D883 #A9D883 #3A5F29; }

.text-button {
  margin-top: 10px;
  appearance: none;
  border: 0;
  background: transparent;
  color: #B9C5CA;
  font-family: var(--text);
  font-weight: 800;
  font-size: 12px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 6px;
}

.text-button:hover { color: var(--cream); }
.text-button[hidden] { display: none; }

/* --------------------------------------------------------------- responsive */

@media (max-width: 1180px) and (min-width: 981px) {
  .challenge-tag { display: none; }
}

@media (max-width: 980px) {
  body { overflow: auto; }

  #page {
    height: auto;
    min-height: 100dvh;
    padding: 6px 6px 96px;
    gap: 6px;
  }

  #topbar {
    flex: 0 0 62px;
    position: sticky;
    top: 0;
    z-index: 50;
  }

  .topbar-content { padding: 4px 12px; gap: 8px; }

  .brand { gap: 6px; }
  .crest { width: 38px; }
  .wordmark { height: 36px; }

  .top-strip { height: 80%; gap: 8px; padding: 0 8px; }
  .challenge-tag { display: none; }
  .score-stat { display: none; }
  .clock-icon { width: 14px; }
  .stat-label { font-size: 6px; letter-spacing: 1px; margin-bottom: 2px; }
  .stat-value { font-size: 15px; }
  .round-stat .stat-value { font-size: 14px; }
  .medal-chip { width: 32px; height: 42px; }
  .medal-count { font-size: 8px; min-width: 15px; }
  .sound-btn { width: 30px; height: 30px; padding: 5px; margin-left: 6px; }

  #workshop {
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(0, 0.92fr);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "stage stage" "palette program";
    gap: 6px;
    min-height: 0;
  }

  #stage {
    grid-area: stage;
    display: flex;
    flex-direction: column;
    gap: 6px;
  }

  #arenaWrap {
    height: max(220px, 37dvh);
    min-height: 0;
    flex: 0 0 auto;
  }

  #controlBar {
    position: fixed;
    left: 6px;
    right: 6px;
    bottom: max(6px, env(safe-area-inset-bottom));
    z-index: 60;
    height: 78px;
    flex: 0 0 auto;
  }

  .control-content { padding: 5px 7px; gap: 6px; }

  .objective-card { padding: 4px 8px; }
  .objective-head { font-size: 8px; letter-spacing: 1.2px; }
  .objective-text { font-size: 12px; margin-top: 2px; }
  .hint-text { font-size: 9px; margin-top: 2px; max-height: 22px; overflow: hidden; }

  .ring-wrap { flex: 0 0 54px; width: 54px; height: 54px; }
  .ring-time { font-size: 12px; padding-bottom: 3px; }
  .ring-unit { font-size: 5px; bottom: 17%; }

  .buttons { gap: 2px; }
  .action-btn { width: 42px; }
  .action-btn span { font-size: 6px; letter-spacing: 0.6px; }
  .key-cap { display: none; }

  #leftRail { grid-area: palette; }
  #rightRail { grid-area: program; }

  .rail-inner { padding: 12px 10px; overflow: hidden; }
  .rail-help, .tray-help { display: none; }
  .rail-head { font-size: 13px; }

  .palette-group { margin-top: 1px; }
  .palette-group h2 { font-size: 11px; margin-bottom: 3px; letter-spacing: 1px; }

  .palette-grid { grid-template-columns: 1fr 1fr; gap: 2px 4px; }

  .pal-item img { width: min(12vw, 52px); }
  .pal-item span { font-size: 8.5px; }

  .dotted-rule { margin: 5px 0 4px; }

  .tray-inner { padding: 12px 10px 10px; overflow: hidden; }
  .tray-head h2 { font-size: 13px; letter-spacing: 0.6px; }
  .tray-sub { display: none; }
  .slots { margin-top: 6px; gap: 3px; overflow-y: auto; }
  .slot { flex: 1 1 0; min-height: 26px; max-height: 48px; }
  .placed img { width: 21px; }
  .placed .p-name { font-size: 9.5px; }
  .placed .p-index { display: none; }
  .tray-foot { margin-top: 6px; padding-top: 6px; }
  .block-count { font-size: 7px; }
  .block-count b { font-size: 10px; }

  .overlay-inner { padding: 60px 18px 22px; }
  .overlay.no-medal .overlay-inner { padding-top: 26px; }
  .overlay-medal { width: 76px; height: 100px; top: -44px; }
  .overlay-inner h2 { font-size: 24px; }
  .overlay-body { font-size: 13px; }
  .ov-stat b { font-size: 17px; }
}

@media (max-width: 420px) {
  .wordmark { height: 30px; }
  .crest { width: 32px; }
  .stat-value { font-size: 13px; }
  .round-stat .stat-value { font-size: 12px; }
  .top-strip { gap: 6px; }
  .action-btn { width: 38px; }
  .ring-wrap { flex-basis: 48px; width: 48px; height: 48px; }
  .objective-text { font-size: 11px; }
}


@media (max-width: 980px) and (max-height: 720px) and (orientation: portrait) {
  #arenaWrap { height: max(190px, 31dvh); }

  .rail-inner { padding: 9px 8px; }
  .rail-head { font-size: 12px; }
  .palette-group h2 { font-size: 10px; margin-bottom: 2px; }
  .pal-item img { width: min(10.5vw, 42px); }
  .pal-item span { font-size: 8px; }
  .dotted-rule { margin: 4px 0 3px; }

  .tray-inner { padding: 9px 8px 8px; }
  .tray-head h2 { font-size: 12px; }
  .slots { margin-top: 4px; gap: 2px; }
  .slot { min-height: 22px; }
  .placed img { width: 18px; }
  .placed .p-name { font-size: 8.5px; }
  .tray-foot { margin-top: 4px; padding-top: 4px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  #page {
    height: 100dvh;
    padding: 5px;
    gap: 5px;
    overflow: hidden;
  }
  body { overflow: hidden; }
  #topbar { flex: 0 0 56px; position: relative; }
  .wordmark { height: 32px; }
  .crest { width: 34px; }
  .top-strip { height: 84%; }
  .challenge-tag, .score-stat { display: none; }
  .stat-value { font-size: 14px; }
  .round-stat .stat-value { font-size: 13px; }
  .medal-chip { width: 28px; height: 38px; }
  .sound-btn { width: 28px; height: 28px; }

  #workshop {
    display: grid;
    grid-template-columns: 156px minmax(0, 1fr) 178px;
    grid-template-rows: none;
    grid-template-areas: none;
    gap: 5px;
    min-height: 0;
  }
  #leftRail { grid-area: auto; order: 0; }
  #stage { grid-area: auto; order: 0; display: grid; grid-template-rows: minmax(0, 1fr) 66px; gap: 5px; }
  #rightRail { grid-area: auto; order: 0; }
  #arenaWrap { height: auto; flex: 1 1 auto; }
  #controlBar { position: relative; left: auto; right: auto; bottom: auto; height: auto; }

  .rail-inner, .tray-inner { padding: 10px 8px; }
  .rail-head { font-size: 13px; }
  .rail-help, .tray-help { display: none; }
  .palette-group h2 { font-size: 9px; margin-bottom: 1px; }
  .palette-grid { grid-template-columns: 1fr 1fr; gap: 1px 3px; }
  .pal-item img { width: 42px; }
  .pal-item span { font-size: 7px; }
  .dotted-rule { margin: 3px 0; }
  .tray-head h2 { font-size: 12px; }
  .tray-sub { display: none; }
  .slots { gap: 3px; margin-top: 5px; }
  .slot { flex: 0 0 auto; min-height: 25px; max-height: none; }
  .placed img { width: 18px; }
  .placed .p-name { font-size: 8px; }
  .placed .p-tag { display: none; }
  .tray-foot { margin-top: 4px; padding-top: 4px; }
  .block-count { font-size: 7px; }

  .control-content { padding: 3px 6px; gap: 6px; }
  .objective-card { padding: 2px 7px; }
  .objective-head { font-size: 7px; }
  .objective-text { font-size: 11px; }
  .hint-text { font-size: 8px; line-height: 1.05; margin-top: 1px; max-height: 17px; overflow: hidden; }
  .ring-wrap { flex-basis: 44px; width: 44px; height: 44px; }
  .ring-time { font-size: 10px; }
  .ring-unit { display: none; }
  .action-btn { width: 32px; }
  .action-btn span { font-size: 5px; }
  .key-cap { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .pal-item img, .action-btn img { transition: none; }
  .pal-item.is-hinted img { animation: none; }
  .slot.valid { animation: none; background: #43515B; }
}


@media (max-width: 360px) {
  .wordmark { display: none; }
  .brand { gap: 0; }
  .top-strip { gap: 5px; padding: 0 6px; }
  .control-content { gap: 4px; padding: 4px 5px; }
  .ring-wrap { flex-basis: 44px; width: 44px; height: 44px; }
  .action-btn { width: 36px; }
  .objective-card { padding: 4px 6px; }
  .quick-count { display: none; }
  .objective-text { font-size: 10px; }
  .overlay-inner { padding-left: 12px; padding-right: 12px; }
}
