* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Center the state-1 block above the countdown clock */
.show-info #state-1 {
  width: 100%;
  max-width: var(--content-max);
  margin-left: auto;
  margin-right: auto;
}
.show-info #state-1 .topbar {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
}
.show-info #state-1 .app-title { text-align: center; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(180deg, #05102D 0%, #522020 100%);
    color: #e0e0e0;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
}

header {
    background: rgba(255, 255, 255, 0.05);
    padding: 20px 30px;
    border-radius: 10px 10px 0 0;
    /* margin-bottom: 30px; */
    backdrop-filter: blur(10px);
}

h1 {
    color: #4ecdc4;
    font-size: 2em;
    margin-bottom: 10px;
}

.status-bar {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    margin-bottom: 15px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.state-badge {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 600;
    background: #48c774;
    color: white;
    text-transform: capitalize;
}

.state-badge.show {
    background: #f39c12;
}

.state-badge.interactive {
    background: #3498db;
}

.state-badge.night {
    background: #2c3e50;
}

.state-badge.day {
    background: #f1c40f;
    color: #2c3e50;
}

.state-badge.evening {
    background: #9b59b6;
}

.current-show {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 600;
    background: #667eea;
    color: white;
}

.show-info-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
}

.show-label-outside {
    color: var(--Beige, #CCB99C);
    text-align: center;
    font-size: 14px;
    font-style: normal;
    font-weight: 400;
    line-height: normal;
    letter-spacing: 3px;
    display: flex;
    height: 42px;
    flex-direction: column;
    justify-content: center;
    align-self: stretch;
    text-transform: uppercase;
}

.show-info {
    gap: 30px;
    flex-wrap: wrap;
    padding: 20px 30px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: center;
    align-items: center;
    min-width: 300px;
}

.show-info-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.show-label {
    font-size: 0.8em;
    color: #cccccc;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.show-value {
    font-size: 1.2em;
    font-weight: 600;
    color: #feca57;
    font-family: 'Courier New', monospace;
}

.show-value--large {
    text-align: center;
    font-family: "JetBrains Mono";
    text-transform: uppercase;
    font-size: 25px;
    font-style: normal;
    font-weight: 700;
    line-height: normal;
    background: var(--BEIGE-GRADIENT, linear-gradient(180deg, #DFCAAB 0%, #534C40 100%));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.status-indicator {
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.85em;
    font-weight: 600;
}

.status-indicator.connected {
    background: #2ecc71;
    color: white;
}

.status-indicator.disconnected {
    background: #e74c3c;
    color: white;
}

.status-indicator.connecting {
    background: #f39c12;
    color: white;
}

main {
    background: rgba(255, 255, 255, 0.05);
    padding: 40px;
    border-radius: 0 0px 10px 10px;
    backdrop-filter: blur(10px);
}

.section-title-box {
    margin: 10px 0 18px 0;
    text-align: center;
    font-size: 22px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    text-shadow: 0 0 18px rgba(119,68,201,0.35);
}

.boxes-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    max-width: 800px;
    margin: 0 auto;
}

.box {
    width: 100%;
    aspect-ratio: 1;
    border: none;
    border-radius: 12px;
    font-size: 1.1em;
    font-weight: 600;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
}

.box:hover:not(:disabled) {
    transform: translateY(-4px);
    box-shadow: 0 8px 12px rgba(0, 0, 0, 0.4);
}

.box:active:not(:disabled) {
    transform: translateY(-2px);
}

.box:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

@media (max-width: 768px) {
    .boxes-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
    }
    
    main {
        padding: 20px;
    }
    
    h1 {
        font-size: 1.5em;
    }
    
    header {
        padding: 15px 20px;
    }
    
    .status-bar {
        gap: 15px;
    }
    
    .show-info {
        gap: 20px;
        padding: 12px;
    }
    
    .show-label {
        font-size: 0.7em;
    }
    
    /* .show-value {
        font-size: 1em;
    } */
}


/* ============================= Allt från Karin ============================= */

:root {
  --bg: #000000;
  --fg: #e2e8f0;
  --muted: #1f2937;
  --pad-height: 340px;
  --pad-radius: 16px;
  --content-max: clamp(300px, 92vw, 1000px);
}

.page-title {
  margin: 50px 0 18px 0;
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  text-shadow: 0 0 18px rgba(119,68,201,0.35);
}

/* Match section title to page-title styling */
.section-title {
  margin: 50px 0 18px 0;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  background: var(--BEIGE-GRADIENT, linear-gradient(180deg, #DFCAAB 0%, #534C40 100%));
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}


/* Color selector buttons */
.color-selector {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 20px auto 16px auto;
  max-width: var(--content-max);
}

.color-btn {
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  background: rgba(255,255,255,0.05);
  color: #e0e0e0;
  font-family: "JetBrains Mono", monospace;
}

.color-btn:hover {
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.4);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.color-btn.selected {
  border-color: currentColor;
  box-shadow: 0 0 20px currentColor, 0 4px 12px rgba(0,0,0,0.3);
  transform: translateY(-2px);
}

.color-btn--red {
  color: #ff4444;
  background: linear-gradient(180deg, rgba(150, 30, 30, 0.448) 0%, rgba(200, 50, 50, 0.659) 50%, rgba(255, 100, 100, 0.855) 100%);
}

.color-btn--green {
  color: #44ff44;
  background: linear-gradient(180deg, rgba(30, 150, 30, 0.448) 0%, rgba(50, 200, 50, 0.659) 50%, rgba(100, 255, 100, 0.855) 100%);
}

.color-btn--blue {
  color: #4444ff;
  background: linear-gradient(180deg, rgba(30, 30, 150, 0.448) 0%, rgba(50, 50, 200, 0.659) 50%, rgba(100, 100, 255, 0.855) 100%);
}

/* Pad simple container */
.pad {
  position: relative;
  height: var(--pad-height);
  width: 100%;
  max-width: var(--content-max);
  margin: 0 auto;
  box-sizing: border-box;
  border-radius: var(--pad-radius);
  background: transparent;
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  color: var(--fg);
  opacity: 0.92;
}


.howto {
  position: relative;
  width: 100%;
  max-width: var(--content-max);
  /* ensure horizontal centering */
  margin-left: auto;
  margin-right: auto;
  /* preserve vertical spacing */
  margin-top: 60px;
  margin-bottom: 120px; /* bring footer closer (was 240px) */
  padding: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.3), 0 2px 6px rgba(0,0,0,0.2);
  border: 1px solid var(--muted);
  border-radius: var(--pad-radius);
  /* Make anchor scroll settle with a small top margin */
  scroll-margin-top: 14px;
}


.howto__content {
  color: var(--fg);
  line-height: 1.5;
  opacity: 0.92;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  gap: 16px;
}

.howto__content .section-title {
  margin: 0;
  width: 100%;
}

/* Extra footer-like section centered at the bottom */
#extra {
  position: static;
  width: 100%;
  max-width: var(--content-max);
  margin-left: auto;
  margin-right: auto;
  margin-top: 0;
  margin-bottom: 16px;
  padding: 8px 12px;
  box-sizing: border-box;
}
#extra .extra-content {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}


.pad__content {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: var(--pad-radius);
  overflow: hidden;
}

/* Simple canvas for drawing */
.pad__canvas {
  position: absolute;
  inset: 0;
  border-radius: var(--pad-radius);
  z-index: 1;
}


/* Cursor */
.pad__cursor {
  position: absolute;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(34,211,238,1) 0%, rgba(34,211,238,0.9) 70%, rgba(34,211,238,0.3) 100%);
  box-shadow: 0 0 40px rgba(34,211,238,1), 0 0 60px rgba(34,211,238,0.9), 0 0 80px rgba(34,211,238,0.6);
  pointer-events: none;
  transform: translate(-50%, -50%) scale(var(--cursor-scale, 1));
  z-index: 5;
}


/* Pulse on tap */
.pad.pulse { animation: padpulse 2000ms ease-out; }
@keyframes padpulse {
  0%   { box-shadow: 0 0 0 0 rgba(34,211,238,0.0); }
  50%  { box-shadow: 0 0 0 10px rgba(34,211,238,0.15); }
  100% { box-shadow: 0 0 0 0 rgba(34,211,238,0.0); }
}


/* Interaction affordances */
.pad, .pad__content { cursor: pointer; }
.actionbtn, .pad, .pad__content, .pad__canvas { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.pad, .pad * { -webkit-tap-highlight-color: transparent; }


/* Focus ring if tabbed */
.pad:focus-visible { outline: 2px solid rgba(255,255,255,0.6); outline-offset: 2px; }

/* ===== Digital Clock styles ===== */

.section-title-clock {
  color: var(--Beige, #CCB99C);
  text-align: center;
  font-size: 14px;
  font-style: normal;
  font-weight: 400;
  line-height: normal;
  letter-spacing: 3px;
  display: flex;
  height: 42px;
  flex-direction: column;
  justify-content: center;
  align-self: stretch;
  margin: 0 auto 5px auto;
  text-transform: uppercase;
}

.clock {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--fg);
  text-align: center;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 12px rgba(34,211,238,0.25);
}

.clock--digital {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0;
  margin: 5px auto;
  max-width: var(--content-max);
  padding: 0 12px;
  --digit-nudge-y: 0px;
}
/* Ensure centering inside the header show-info layout */
.show-info .show-info-item #clock {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin-left: auto;
  margin-right: auto;
}
.clock--digital .group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.clock--digital .group .digits { display: flex; gap: var(--digits-gap, 8px); }
.clock--digital .group .label {
  font-size: clamp(11px, 1.6vw, 13px);
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: rgba(226,232,240,0.8);
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* More 3D clock */
.clock--digital .digit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--digit-w, 100px);
  height: var(--digit-h, 110px);
  border-radius: var(--digit-radius, 4px);
  background: linear-gradient(145deg, #625a54, #4e4842);
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 
    inset 2px 2px 4px rgba(255,255,255,0.1),
    inset -2px -2px 4px rgba(0,0,0,0.4),
    0 6px 12px rgba(0,0,0,0.4),
    0 2px 4px rgba(0,0,0,0.3);
  color: #e8dcc8;
  font-family: "JetBrains Mono";
  font-size: var(--digit-fs, 40px);
  font-weight: 500;
  letter-spacing: 0.5px;
  text-shadow: 
    0 1px 0 rgba(255,255,255,0.3),
    0 2px 2px rgba(0,0,0,0.5),
    0 4px 8px rgba(0,0,0,0.3),
    0 0 20px rgba(232, 220, 200, 0.2);
  position: relative;
  overflow: hidden;
  perspective: 600px;
  transform-style: preserve-3d;
}

/* Less 3D clock */

/* .clock--digital .digit {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 64px;
  border-radius: var(--digit-radius, 4px);
  background: linear-gradient(145deg, #625a54, #4e4842);
  border: 1px solid rgba(255,255,255,0.14);
  box-shadow: 0 4px 4px 0 rgba(0, 0, 0, 0.25);
  color: #e8dcc8;
  font-family: "JetBrains Mono";
  font-size: 28px;
  font-weight: 500;
  letter-spacing: 0.5px;
  text-shadow: 
    0 1px 0 rgba(255,255,255,0.3),
    0 2px 2px rgba(0,0,0,0.5),
    0 4px 8px rgba(0,0,0,0.3),
    0 0 20px rgba(232, 220, 200, 0.2);
  position: relative;
  overflow: hidden;
  perspective: 600px;
  transform-style: preserve-3d;
} */

.clock--digital .sep {
  display: inline-block;
  width: 10px;
  text-align: center;
  color: rgba(226,232,240,0.9);
  font-size: 34px;
  font-weight: 700;
  text-shadow: 0 0 6px rgba(236,72,153,0.2);
}

.clock--digital {
  --digit-w: clamp(48px, 8vw, 78px);
  --digit-h: clamp(60px, 10vw, 92px);
  --digit-radius: clamp(6px, 1.5vw, 10px);
  --digit-fs: clamp(22px, 4vw, 34px);
  --digits-gap: clamp(4px, 1vw, 10px);
  --group-gap: clamp(12px, 3vw, 36px);
  display: flex;
  align-items: flex-start;
  gap: 0;
}
.clock--digital .group { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.clock--digital .group:not(:last-child) { margin-right: var(--group-gap); }
.clock--digital .group:not(:last-child) .digits { position: relative; }
.clock--digital .group:not(:last-child) .digits::after {
  content: ":";
  position: absolute;
  left: calc(100% + (var(--group-gap) / 2) - 0.5ch + 6px);
  top: 50%;
  transform: translateY(-50%);
  color: rgba(226,232,240,0.9);
  font-size: var(--digit-fs, 34px);
  font-weight: 700;
  text-shadow: 0 0 6px rgba(236,72,153,0.2);
  line-height: 1;
  pointer-events: none;
}

.clock--digital .digit .digit__text {
  position: absolute;
  left: 0; right: 0; top: 50%;
  transform: translateY(calc(-50% + var(--digit-nudge-y)));
  display: block; width: 100%; text-align: center; line-height: 1;
}

@media (max-width: 420px) {
  .clock--digital { gap: 6px; }
  .clock--digital .digit { width: 36px; height: 48px; font-size: 24px; }
  .clock--digital .sep { width: 8px; font-size: 24px; }
}

.digit__wrap { position: absolute; inset: 0; display: grid; grid-template-rows: 1fr 1fr; color: inherit; }
.digit__half { display: none; align-items: center; justify-content: center; background: inherit; color: inherit; border-left: inherit; border-right: inherit; position: relative; overflow: hidden; }
.digit__top { border-top: inherit; border-top-left-radius: 4px; border-top-right-radius: 4px; border-bottom: 1px solid rgba(0,0,0,0.3); }
.digit__bottom { border-bottom: inherit; border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; }
.digit__face { position: absolute; inset: 0; display: block; color: inherit; z-index: 0; background: transparent; transform-style: preserve-3d; mask-image: none; }
.digit__face .digit__front, .digit__face .digit__back { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; backface-visibility: hidden; }
.digit__face .digit__back { transform: rotateX(180deg); }
.digit__roller { position: absolute; inset: 0; display: flex; flex-direction: column; will-change: transform, filter; transform: translateY(-100%); }
.digit__item { height: 100%; display: block; position: relative; text-align: center; padding: 0; flex: 0 0 100%; }

.digit.is-scrolling .digit__roller { animation: wheelScrollDown 420ms cubic-bezier(0.15, 0.6, 0.2, 1) forwards; filter: blur(0.3px); }
@keyframes wheelScrollDown { 0% { transform: translateY(-100%); } 100% { transform: translateY(0%); } }

.digit__top.flip, .digit__bottom.flip { position: absolute; left: 0; right: 0; overflow: hidden; backface-visibility: hidden; transform-style: preserve-3d; visibility: hidden; pointer-events: none; z-index: 2; background: inherit; }
.digit__top.flip { top: 0; height: 100%; transform-origin: center top; position: absolute; }
.digit__bottom.flip { bottom: 0; height: 50%; transform-origin: center top; }
.digit__clip { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; }
.digit__top .digit__clip { bottom: 50%; }
.digit__bottom .digit__clip { top: 50%; }
@keyframes flipFold { 0% { transform: rotateX(0deg); } 100% { transform: rotateX(-90deg); } }
@keyframes flipUnfold { 0% { transform: rotateX(-90deg); } 100% { transform: rotateX(0deg); } }
.digit.is-flipping .digit__top.flip { transform: rotateX(-90deg); animation: flipUnfold 360ms ease-out forwards; }
.digit.is-flipping .digit__bottom.flip { animation: none; }
.digit.is-flipping .digit__top.flip { visibility: visible; }
.digit.is-flipping .digit__bottom.flip { visibility: hidden; }
.digit.is-spinning .digit__face { animation: wheelSpinToward 480ms cubic-bezier(0.2, 0.6, 0.2, 1) forwards; }
.digit.is-spinning .digit__half { display: none; }
.digit.is-spinning .digit__top.flip, .digit.is-spinning .digit__bottom.flip { visibility: hidden; }
@keyframes wheelSpinToward { 0% { transform: rotateX(0deg); } 55% { transform: rotateX(200deg); } 100% { transform: rotateX(180deg); } }
.digit.is-flipping .digit__half { display: none; }
.digit.is-flipping .digit__face { visibility: visible; }
.digit.is-flipping .digit__top { border-bottom-color: transparent; }
.digit__top.flip::after { content: ""; position: absolute; inset: 0; pointer-events: none; }
.digit__top.flip::before { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 1px; background: linear-gradient(90deg, rgba(255,255,255,0), rgba(255,255,255,0.25), rgba(255,255,255,0)); opacity: 0; }
@keyframes flapShadowReveal { 0% { opacity: 0.0; filter: blur(0.2px); } 40% { opacity: 0.65; } 100% { opacity: 0.0; } }
@keyframes flapCreaseBlink { 0% { opacity: 0; } 35% { opacity: 0.8; } 60% { opacity: 0.3; } 100% { opacity: 0; } }
.digit.is-flipping .digit__top.flip::after { animation: flapShadowReveal 360ms ease-out forwards; }
.digit.is-flipping .digit__top.flip::before { animation: flapCreaseBlink 360ms ease-out forwards; }


/* Animated glow for State 1 show name */
#state1ShowName {
  position: relative;
  z-index: 0;
  padding: 0 4px;
  border-radius: 8px;
  /* keep subtle readability without its own glow spot */
  /* text-shadow: 0 0 6px rgba(255,191,73,0.18), 0 0 10px rgba(60,110,220,0.16); */
}
/* (removed span-level glow layers to avoid double spots) */
/* Expand glow to cover the entire title area in State 1 */
#state-1 .app-title {
  position: relative;
  z-index: 0;
  text-shadow: 0 0 18px rgba(119,68,201,0.35);
}
#state-1 .app-title::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 140%;
  height: 240%;
  border-radius: 999px;
  pointer-events: none;
  z-index: -1;
  filter: blur(36px);
  opacity: 0.9;
  /* Single blended glow (mix controlled by custom properties) */
  background:
    radial-gradient(74% 74% at 50% 50%, rgba(40,110,230, var(--blue-a)), rgba(40,110,230,0.0) 82%),
    radial-gradient(66% 66% at 50% 50%, rgba(255,191,73, var(--amber-a)), rgba(255,191,73,0.0) 72%),
    radial-gradient(34% 34% at 50% 50%, rgba(255,205,100, var(--amber-a)), rgba(255,205,100,0.0) 70%);
  animation:
    titleGlowPulse var(--title-pulse-dur) ease-in-out infinite alternate,
    titleMixPulse var(--title-mix-dur) ease-in-out infinite alternate;
}

@keyframes titleGlowPulse {
  0%   { transform: translate(-50%, -50%) scale(0.95); opacity: 0.65; filter: blur(30px); }
  50%  { transform: translate(-50%, -50%) scale(1.06); opacity: 1.0; filter: blur(38px); }
  100% { transform: translate(-50%, -50%) scale(1.01); opacity: 0.85; filter: blur(34px); }
}

/* Animate the color mix between amber and blue; values jitter via duration/delay set by JS */
@keyframes titleMixPulse {
  /* Alternate cleanly: amber peak -> blue peak -> amber peak, equal intensities */
  0%   { --amber-a: 0.99; --blue-a: 0.35; }
  50%  { --amber-a: 0.35; --blue-a: 0.99; }
  100% { --amber-a: 0.99; --blue-a: 0.35; }
}



/* Grid area: 6 columns x 3 rows (18 cells). */
.grid {
  display: grid;
  box-sizing: border-box;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  grid-auto-flow: row;
  column-gap: 6px;
  row-gap: 6px;
  padding: 16px 12px 12px 12px; /* standard padding; pad is now in-flow */
  margin: 6px auto var(--section-gap) auto; /* space from title and next section, center */
  width: 100%;
  max-width: var(--content-max); /* match other sections' width cap */
  position: relative; /* positioning context for overlays */
}

.grid--overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 16px;
  pointer-events: none; /* Allow cursor/trail interaction to pass through */
  z-index: 1; /* Same level as canvas, below cursor */
}

.grid--overlay .cell {
  pointer-events: auto; /* Re-enable pointer events on cells */
  touch-action: none; /* Prevent touch interference */
}

/* Ensure grid doesn't block pointer move events during drag */
.pad:active .grid--overlay {
  pointer-events: none;
}

.pad:active .grid--overlay .cell {
  pointer-events: none;
}

/* Base cell styles so the grid is visible */
.grid .cell {
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  background: rgba(255,255,255,0.06);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.14);
  position: relative;
  overflow: hidden;
  z-index: 15; /* Active cells above cursor (z-index: 5) */
}
.grid .cell.cell--inactive {
  background: transparent;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.06);
  z-index: 2; /* Inactive cells below cursor */
}

/* Click pulse effect for active grid cells */
.grid .cell.pulse {
  overflow: visible !important;
  border: 2px solid var(--pulse-bg, rgba(161, 124, 230, 0.85)) !important;
  box-shadow: 0 0 20px var(--pulse-bg, rgba(161, 124, 230, 0.85)), 0 0 30px var(--pulse-bg, rgba(161, 124, 230, 0.6)), inset 0 0 0 1px var(--pulse-bg, rgba(161, 124, 230, 0.85)) !important;
  animation: gridCellBorderGlow var(--pulse-duration, 1200ms) ease-in-out forwards;
}

/* Hide border and glow on cells that are part of merged groups */
.grid .cell.pulse-merged {
  border: none !important;
  box-shadow: none !important;
  animation: none !important;
}

.grid .cell.pulse::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(
    circle at center,
    color-mix(in srgb, var(--pulse-bg, rgba(161, 124, 230, 0.85)) 70%, white) 0%,
    var(--pulse-bg, rgba(161, 124, 230, 0.85)) 50%,
    var(--pulse-bg, rgba(161, 124, 230, 0.85)) 100%
  );
  animation: gridCellPulse var(--pulse-duration, 1200ms) ease-in-out forwards;
}

@keyframes gridCellBorderGlow {
  0% { 
    border-color: transparent !important;
    box-shadow: none !important;
    filter: blur(3px);
  }
  50% { 
    border-color: var(--pulse-bg, rgba(161, 124, 230, 0.85)) !important;
    box-shadow: 0 0 20px var(--pulse-bg, rgba(161, 124, 230, 0.85)), 0 0 30px var(--pulse-bg, rgba(161, 124, 230, 0.6)), inset 0 0 0 1px var(--pulse-bg, rgba(161, 124, 230, 0.85)) !important;
    filter: blur(0px);
  }
  100% { 
    border-color: transparent !important;
    box-shadow: none !important;
    filter: blur(3px);
  }
}

@keyframes gridCellPulse {
  0% { opacity: 0.0; filter: blur(3px); }
  35% { opacity: 0.6; filter: blur(0px); }
  100% { opacity: 0.0; filter: blur(3px); }
}

/* Overlays should not take up grid tracks */
.overlays {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

/* Show pointer cursor for interactive parts */
.actionbtn { cursor: pointer; }
/* .panel-b { cursor: pointer; } */
.grid .cell { cursor: pointer; }
.grid .cell.cell--inactive { cursor: default; }
.pad, .pad .pad__content { cursor: pointer; }
.actionbtn, .grid .cell, .pad, .pad__content, .pad__canvas {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none; /* disable long-press callout */
  -webkit-tap-highlight-color: transparent; /* remove blue flash on tap */
}

/* State 3 grid: duplicate State 1 styling */
#grid-state2 .cell {
  box-shadow: none;
}

/* Add white border only to active cells */
#grid-state2 .cell:not(.cell--inactive) {
  border: 1px solid rgba(255, 255, 255, 0.517);
  animation: cellBreathing 6s ease-in-out infinite;
}

/* Breathing animation - pulses darker */
@keyframes cellBreathing {
  0%, 100% {
    filter: brightness(1);
  }
  50% {
    filter: brightness(0.7);
  }
}

#grid-state2.grid {
  gap: 3px;
  column-gap: 5px;
  row-gap: 3px;
}

#grid-state2 {
  position: relative;
  background: #06183e67;
  border-radius: 10px;
  overflow: visible; /* Allow overlay to be visible */
}
#grid-state2::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(
    40% 40% at 50% 50%,
    rgba(220, 40, 40, 0.444) 0%,
    rgba(220, 40, 40, 0.167) 35%,
    rgba(220, 40, 40, 0.074) 70%
  );
  filter: blur(22px);
}
#grid-state2 .cell { position: relative; z-index: 1; }

#grid-state2 .cell.cell--inactive {
  background: transparent !important;
  box-shadow: none !important;
  pointer-events: none;
  filter: none !important;
}
#grid-state2 .cell.cell--inactive::before,
#grid-state2 .cell.cell--inactive::after {
  animation: none !important;
  opacity: 0 !important;
  background: none !important;
}

/* Center block merges */
#grid-state2 .cell:nth-child(15),
#grid-state2 .cell:nth-child(16),
#grid-state2 .cell:nth-child(21),
#grid-state2 .cell:nth-child(22) {
  box-shadow: none !important;
}
#grid-state2 .cell:nth-child(15) { margin-right: -3px; margin-bottom: -3px; }
#grid-state2 .cell:nth-child(16) { margin-left: -3px;  margin-bottom: -3px; }
#grid-state2 .cell:nth-child(21) { margin-right: -3px; margin-top: -3px; }
#grid-state2 .cell:nth-child(22) { margin-left: -3px;  margin-top: -3px; }

/* Row 1 merge: cells 2 & 3 */
#grid-state2 .cell:nth-child(2),
#grid-state2 .cell:nth-child(3) { position: relative; }
#grid-state2 .cell:nth-child(2) { margin-right: -3px; z-index: 2; }
#grid-state2 .cell:nth-child(3) { margin-left: -3px; z-index: 2; }
#grid-state2 .cell:nth-child(2),
#grid-state2 .cell:nth-child(3) {
  box-shadow: none !important;
}
/* Add border to merged cells but remove the middle border */
#grid-state2 .cell:nth-child(2) {
  border: 1px solid rgba(255, 255, 255, 0.517);
  border-right: none;
}
#grid-state2 .cell:nth-child(3) {
  border: 1px solid rgba(255, 255, 255, 0.517);
  border-left: none;
}

/* Disable inner ambient glows that can create a seam between 2 & 3 */
#grid-state2 .cell:nth-child(2)::after,
#grid-state2 .cell:nth-child(3)::after {
  content: none !important;
  background: none !important;
}

/* Vertical merge: cells 26 & 32 */
#grid-state2 .cell:nth-child(26),
#grid-state2 .cell:nth-child(32) { position: relative; }
#grid-state2 .cell:nth-child(26) { margin-bottom: -3.4px; }
#grid-state2 .cell:nth-child(32) { margin-top: -3.4px; }
#grid-state2 .cell:nth-child(26) {
  box-shadow: none !important;
  border: 1px solid rgba(255, 255, 255, 0.517);
  border-bottom: none;
}
#grid-state2 .cell:nth-child(32) {
  box-shadow: none !important;
  border: 1px solid rgba(255, 255, 255, 0.517);
  border-top: none;
}

#grid-state2 .cell:nth-child(26) { border-bottom-left-radius: 0 !important; border-bottom-right-radius: 0 !important; }
#grid-state2 .cell:nth-child(32) { border-top-left-radius: 0 !important; border-top-right-radius: 0 !important; }

#grid-state2 .cell:nth-child(26)::after {
  background: radial-gradient(circle at 50% 100%, rgba(255, 230, 150, 0.45) 0%, rgba(255, 190, 50, 0.25) 35%, rgba(255, 150, 0, 0.05) 100%);
}
#grid-state2 .cell:nth-child(32)::after {
  background: radial-gradient(circle at 50% 0%, rgba(255, 230, 150, 0.45) 0%, rgba(255, 190, 50, 0.25) 35%, rgba(255, 150, 0, 0.05) 100%);
}

/* Align the base amber backgrounds so they meet in the middle vertically (like row 1 merge) */
#grid-state2 .cell:nth-child(26) {
  background: radial-gradient(
    circle at 50% 100%,
    #b6862e 0%,
    #8b5e1f 45%,
    #4b2c0c 100%
  );
}
#grid-state2 .cell:nth-child(32) {
  background: radial-gradient(
    circle at 50% 0%,
    #b6862e 0%,
    #8b5e1f 45%,
    #4b2c0c 100%
  );
}

/* Seam guard */
#grid-state2 .cell:nth-child(2),
#grid-state2 .cell:nth-child(3),
#grid-state2 .cell:nth-child(26),
#grid-state2 .cell:nth-child(32) { outline: 0.5px solid transparent; }

/* Remove inner radii for merged 2 & 3 */
#grid-state2 .cell:nth-child(2) { border-top-right-radius: 0 !important; border-bottom-right-radius: 0 !important; }
#grid-state2 .cell:nth-child(3) { border-top-left-radius: 0 !important; border-bottom-left-radius: 0 !important; }

/* Center ambient glow across combined areas */
#grid-state2 .cell:nth-child(2)::after {
  background: radial-gradient(
    circle at 100% 50%,
    rgba(255, 230, 150, 0.45) 0%,
    rgba(255, 190, 50, 0.25) 35%,
    rgba(255, 150, 0, 0.05) 100%
  );
}
#grid-state2 .cell:nth-child(3)::after {
  background: radial-gradient(
    circle at 0% 50%,
    rgba(255, 230, 150, 0.45) 0%,
    rgba(255, 190, 50, 0.25) 35%,
    rgba(255, 150, 0, 0.05) 100%
  );
}

/* Hide individual cell pulses for merged cells - use overlay instead */
#grid-state2 .cell:nth-child(2).pulse::before,
#grid-state2 .cell:nth-child(3).pulse::before,
#grid-state2 .cell:nth-child(26).pulse::before,
#grid-state2 .cell:nth-child(32).pulse::before {
  display: none !important;
}

/* Also align the base amber background gradients to meet in the middle (row 1 col 2 & 3) */
#grid-state2 .cell:nth-child(2) {
  background: radial-gradient(
    circle at 100% 50%,
    #b6862e 0%,
    #8b5e1f 45%,
    #4b2c0c 100%
  );
}
#grid-state2 .cell:nth-child(3) {
  background: radial-gradient(
    circle at 0% 50%,
    #b6862e 0%,
    #8b5e1f 45%,
    #4b2c0c 100%
  );
}

/* Apply yellow gradient to all active cells EXCEPT the merged pairs */
/* Exclude: row 1 cells 2-3 (nth-child 2,3) and row 5-6 cell 2 (nth-child 26,32) */
#grid-state2 .cell:not(.cell--inactive):not(:nth-child(2)):not(:nth-child(3)):not(:nth-child(26)):not(:nth-child(32)) {
  background: radial-gradient(
    circle at 50% 50%,
    #b6862e 0%,
    #8b5e1f 45%,
    #4b2c0c 100%
  ) !important;
}

/* Single overlay pulse that spans merged cells */
#grid-state2 { position: relative; overflow: hidden; }
#grid-state2 .grid-pulse {
  position: absolute;
  pointer-events: none;
  z-index: 100;
  animation: gridMergePulse var(--pulse-duration, 1200ms) ease-in-out forwards, gridMergeBorderGlow var(--pulse-duration, 1200ms) ease-in-out forwards;
  background: radial-gradient(
    ellipse at 50% 50%,
    var(--pulse-bg, rgba(161, 124, 230, 0.85)) 0%,
    var(--pulse-bg, rgba(161, 124, 230, 0.85)) 60%,
    rgba(255,255,255,0) 100%
  );
  border-radius: 8px;
  border: 2px solid transparent;
  box-shadow: none;
  /* Ensure visibility */
  opacity: 1;
  will-change: transform, opacity;
}
/* Position overlay using absolute coords to cover cells 2 and 3 on row 1 */
/* Grid is 6x6, each cell is ~16.67% width/height, gap is 3px */
#grid-state2 .grid-pulse--r1c2-3 {
  top: -2px;
  left: calc(16.666% - 1px);
  width: calc(33.333% + 14px);
  height: calc(16.666% + 4px);
}
/* Position overlay to cover rows 5-6, column 2 (vertical merge) */
#grid-state2 .grid-pulse--r5-6c2 {
  top: calc(66.666% + 8px);
  left: calc(16.666% + 1px);
  width: calc(16.666% + 4px);
  height: calc(33.333% + 14px);
}

@keyframes gridMergePulse {
  0% { opacity: 0.0; filter: blur(3px); }
  35% { opacity: 0.45; filter: blur(0px); }
  100% { opacity: 0.0; filter: blur(3px); }
}

@keyframes gridMergeBorderGlow {
  0% { 
    border-color: transparent;
    box-shadow: none;
  }
  50% { 
    border-color: var(--pulse-bg, rgba(161, 124, 230, 0.85));
    box-shadow: 0 0 20px var(--pulse-bg, rgba(161, 124, 230, 0.85)), 0 0 30px var(--pulse-bg, rgba(161, 124, 230, 0.6));
  }
  100% { 
    border-color: transparent;
    box-shadow: none;
  }
}