:root {
  color-scheme: light;
  --bg: #f6f3ed;
  --ink: #1e1c1a;
  --muted: #746d63;
  --line: #ded6c9;
  --panel: #fffdfa;
  --panel-strong: #ffffff;
  --accent: #d9492f;
  --accent-2: #126c62;
  --accent-3: #edb642;
  --blue: #273b7a;
  --shadow: 0 18px 50px rgba(52, 39, 25, 0.14);
  --radius: 8px;
  --cell-w: 192px;
  --cell-h: 208px;
  --atlas-w: 1536px;
  --atlas-h: 1872px;
  --pet-scale: 1.1;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.58), rgba(255, 255, 255, 0) 240px),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 2px solid #171514;
  background: var(--accent-3);
  box-shadow: 5px 5px 0 #171514;
  color: #171514;
  font-size: 24px;
  font-weight: 900;
  line-height: 1;
}

.brand h1,
.brand p,
.section-heading h2,
.section-heading p,
.stage-toolbar h2,
.stage-toolbar p,
.control-panel h2 {
  margin: 0;
}

.brand h1 {
  font-size: clamp(24px, 3.4vw, 42px);
  line-height: 0.95;
  letter-spacing: 0;
}

.brand p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

.pet-tabs,
.segmented {
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  border-radius: var(--radius);
}

.pet-tab,
.segmented button,
.state-grid button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.pet-tab,
.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 14px;
}

.pet-tab {
  min-height: 42px;
  padding: 0 17px;
  font-size: 15px;
}

.pet-tab-icon {
  font-size: 18px;
  line-height: 1;
}

.pet-tab small {
  display: block;
  margin-top: 2px;
  color: currentColor;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1;
  opacity: 0.7;
  text-transform: uppercase;
}

.pet-tab-soon {
  cursor: default;
  opacity: 0.72;
}

.pet-tab.is-active,
.segmented button.is-active,
.state-grid button.is-active {
  background: #171514;
  color: #fffdfa;
}

main {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding-bottom: 52px;
}

.stage-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 18px;
  align-items: stretch;
}

.stage-panel,
.control-panel,
.atlas-frame,
.atlas-list {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.stage-panel,
.control-panel {
  border-radius: var(--radius);
}

.stage-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.stage-toolbar h2 {
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1;
}

.eyeline {
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.12em;
  line-height: 1;
  text-transform: uppercase;
}

.readout {
  display: grid;
  justify-items: end;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.readout strong {
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
  text-transform: none;
}

.stage {
  position: relative;
  min-height: 520px;
  overflow: hidden;
  border-radius: 0 0 var(--radius) var(--radius);
  background: #f5e4c0;
  isolation: isolate;
  touch-action: none;
}

.stage.theme-counter {
  background:
    linear-gradient(180deg, #fff1d1 0%, #ffd88c 58%, #c67b3c 58%, #a86032 100%);
}

.stage.theme-night {
  background:
    linear-gradient(180deg, #23356f 0%, #151727 62%, #0f111a 62%, #121112 100%);
}

.stage.theme-paper {
  background:
    linear-gradient(180deg, #fcfaf4 0%, #f2ede3 62%, #d5c6b3 62%, #b99b7a 100%);
}

.stage-grid {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.34) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.34) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0));
}

.stage-shelf {
  position: absolute;
  right: 8%;
  bottom: 78px;
  left: 8%;
  height: 14px;
  border: 2px solid rgba(23, 21, 20, 0.74);
  background: rgba(255, 255, 255, 0.44);
  box-shadow: 0 14px 0 rgba(23, 21, 20, 0.1);
}

.pet-wrap {
  position: absolute;
  z-index: 3;
  width: var(--cell-w);
  height: var(--cell-h);
  transform: translate(-50%, -100%) scale(var(--pet-scale));
  transform-origin: 50% 100%;
  will-change: left, top, transform;
}

.pet-sprite {
  position: relative;
  overflow: hidden;
  width: var(--cell-w);
  height: var(--cell-h);
}

.pet-sprite img {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: var(--atlas-w);
  max-width: none;
  height: var(--atlas-h);
  image-rendering: pixelated;
  pointer-events: none;
  user-select: none;
}

.pet-shadow {
  position: absolute;
  z-index: 2;
  width: 150px;
  height: 30px;
  border-radius: 999px;
  background: rgba(23, 21, 20, 0.2);
  filter: blur(2px);
  transform: translate(-50%, -50%) scale(var(--pet-scale));
  transform-origin: 50% 50%;
  pointer-events: none;
}

.pet-shadow.is-hidden {
  opacity: 0;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
}

.control-group {
  display: grid;
  gap: 12px;
}

.control-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.control-panel h2 {
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

#frameReadout {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.state-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
}

.state-grid button {
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
}

.state-grid button.is-active {
  border-color: #171514;
  background: var(--accent);
  color: #ffffff;
}

.sliders label {
  display: grid;
  gap: 9px;
}

.sliders span,
.toggle span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.swatches {
  display: flex;
  gap: 8px;
}

.swatch {
  width: 42px;
  height: 34px;
  border: 2px solid transparent;
  border-radius: 6px;
}

.swatch[data-theme="counter"] {
  background: linear-gradient(135deg, #fff1d1 0 48%, #a86032 48% 100%);
}

.swatch[data-theme="night"] {
  background: linear-gradient(135deg, #23356f 0 48%, #121112 48% 100%);
}

.swatch[data-theme="paper"] {
  background: linear-gradient(135deg, #fcfaf4 0 48%, #b99b7a 48% 100%);
}

.swatch.is-active {
  border-color: #171514;
}

.toggle {
  display: flex;
  align-items: center;
  gap: 9px;
}

.loops-section,
.ecard-section,
.atlas-section {
  margin-top: 34px;
}

.section-heading {
  display: grid;
  gap: 7px;
  justify-items: start;
  margin-bottom: 14px;
}

.section-heading h2 {
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1;
}

.ecard {
  position: relative;
  min-height: 470px;
  overflow: hidden;
  border: 1px solid #d4c4ae;
  border-radius: var(--radius);
  background:
    linear-gradient(110deg, rgba(255, 255, 255, 0.86) 0 34%, rgba(255, 255, 255, 0) 34%),
    radial-gradient(circle at 78% 18%, rgba(237, 182, 66, 0.42), transparent 24%),
    radial-gradient(circle at 47% 84%, rgba(18, 108, 98, 0.18), transparent 26%),
    linear-gradient(135deg, #fff8e9 0%, #f9dcc8 48%, #d9f1ea 100%);
  box-shadow: var(--shadow);
}

.ecard::before {
  position: absolute;
  right: 28px;
  bottom: 28px;
  left: 34%;
  height: 16px;
  border: 2px solid rgba(23, 21, 20, 0.7);
  background: rgba(255, 255, 255, 0.4);
  box-shadow: 0 13px 0 rgba(23, 21, 20, 0.08);
  content: "";
}

.ecard-copy {
  position: relative;
  z-index: 5;
  width: min(380px, 34%);
  padding: 34px 0 0 34px;
}

.ecard-kicker,
.ecard-copy h2,
.ecard-copy p {
  margin: 0;
}

.ecard-kicker {
  color: var(--accent);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.04em;
}

.ecard-copy h2 {
  margin-top: 12px;
  font-size: clamp(32px, 5vw, 58px);
  line-height: 0.94;
}

.ecard-copy p:not(.ecard-kicker) {
  margin-top: 16px;
  color: #514a43;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.5;
}

.ecard-button {
  min-height: 40px;
  padding: 0 18px;
  border: 0;
  border-radius: 6px;
  background: #171514;
  color: #fffdfa;
  font-size: 13px;
  font-weight: 900;
}

.ecard-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 22px;
}

.ecard-link {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 0 18px;
  border: 1px solid #171514;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.76);
  color: #171514;
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
}

.ecard-scene {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.ecard-actor {
  position: absolute;
  z-index: 3;
  display: grid;
  justify-items: center;
  gap: 9px;
}

.ecard-actor > span {
  padding: 6px 10px;
  border: 1px solid rgba(23, 21, 20, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: #2b2723;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
}

.ecard-actor .pet-wrap {
  position: relative;
  left: auto;
  top: auto;
  transform: scale(0.82);
  transform-origin: 50% 100%;
}

.ecard-louie {
  right: 48%;
  bottom: 42px;
}

.ecard-snowy {
  right: 6%;
  bottom: 42px;
}

.ecard-mirim {
  right: 28%;
  bottom: 43px;
}

.ecard-mirim img {
  display: block;
  width: min(240px, 22vw);
  min-width: 190px;
  border: 2px solid rgba(23, 21, 20, 0.72);
  border-radius: 8px;
  background: #fff8ee;
  box-shadow: 10px 10px 0 rgba(23, 21, 20, 0.13);
}

.ecard-hearts span {
  position: absolute;
  z-index: 4;
  color: #c3484d;
  font-size: 28px;
  font-weight: 900;
  opacity: 0.9;
  text-shadow: 0 2px 0 #fff8ee;
}

.ecard-hearts span:nth-child(1) {
  top: 64px;
  right: 29%;
}

.ecard-hearts span:nth-child(2) {
  top: 102px;
  right: 10%;
  color: var(--accent-2);
}

.ecard-hearts span:nth-child(3) {
  top: 210px;
  right: 44%;
}

.ecard-hearts span:nth-child(4) {
  top: 46px;
  right: 47%;
  color: #171514;
}

.ecard.is-cheering .ecard-hearts span {
  animation: float-heart 1.45s ease-out both;
}

.ecard.is-cheering .ecard-mirim img {
  animation: happy-bob 0.9s ease-in-out 2;
}

@keyframes float-heart {
  from {
    transform: translateY(18px) scale(0.82);
    opacity: 0;
  }
  45% {
    opacity: 1;
  }
  to {
    transform: translateY(-34px) scale(1.08);
    opacity: 0;
  }
}

@keyframes happy-bob {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-9px);
  }
}

.loop-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.loop-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
}

.loop-stage {
  position: relative;
  display: grid;
  height: 180px;
  place-items: center;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0.2)),
    #eadcc8;
}

.loop-stage::after {
  position: absolute;
  right: 12%;
  bottom: 28px;
  left: 12%;
  height: 7px;
  border-radius: 999px;
  background: rgba(23, 21, 20, 0.14);
  content: "";
}

.loop-stage .pet-wrap {
  position: relative;
  left: auto;
  top: auto;
  transform: scale(0.62);
}

.loop-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 13px;
  border-top: 1px solid var(--line);
}

.loop-meta strong {
  font-size: 14px;
  line-height: 1;
}

.loop-meta span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.atlas-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 14px;
  align-items: start;
}

.atlas-frame,
.atlas-list {
  border-radius: var(--radius);
}

.atlas-frame {
  overflow: auto;
  padding: 10px;
}

.atlas-frame img {
  display: block;
  width: 100%;
  min-width: 620px;
  height: auto;
  image-rendering: pixelated;
}

.atlas-list {
  display: grid;
  gap: 0;
  overflow: hidden;
}

.atlas-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) 62px;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.atlas-row:last-child {
  border-bottom: 0;
}

.row-number {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 50%;
  background: #171514;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
}

.atlas-row strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.1;
}

.atlas-row span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

@media (max-width: 980px) {
  .topbar,
  .stage-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stage-layout,
  .atlas-layout {
    grid-template-columns: 1fr;
  }

  .control-panel {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .loop-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ecard {
    min-height: 680px;
  }

  .ecard::before {
    left: 28px;
  }

  .ecard-copy {
    width: auto;
    max-width: 560px;
    padding: 28px 28px 0;
  }

  .ecard-louie {
    right: auto;
    left: 4%;
    bottom: 44px;
  }

  .ecard-mirim {
    right: 50%;
    bottom: 64px;
    transform: translateX(50%);
  }

  .ecard-snowy {
    right: 4%;
    bottom: 44px;
  }

  .ecard-mirim img {
    width: 220px;
  }
}

@media (max-width: 640px) {
  main,
  .topbar {
    width: min(100% - 20px, 1180px);
  }

  .brand {
    align-items: flex-start;
  }

  .pet-tabs,
  .segmented {
    flex-wrap: wrap;
  }

  .pet-tabs {
    width: 100%;
  }

  .pet-tab {
    flex: 1 1 120px;
  }

  .stage {
    min-height: 430px;
  }

  .control-panel,
  .loop-grid {
    grid-template-columns: 1fr;
  }

  .state-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .atlas-frame img {
    min-width: 520px;
  }

  .ecard {
    min-height: 760px;
  }

  .ecard-copy {
    padding: 24px 20px 0;
  }

  .ecard-copy h2 {
    max-width: 340px;
  }

  .ecard-actor .pet-wrap {
    transform: scale(0.62);
  }

  .ecard-louie {
    left: 0;
    bottom: 40px;
  }

  .ecard-snowy {
    right: 0;
    bottom: 40px;
  }

  .ecard-mirim {
    bottom: 118px;
  }

  .ecard-mirim img {
    width: 190px;
    min-width: 0;
  }

  .ecard-hearts span:nth-child(1) {
    top: 300px;
    right: 30%;
  }

  .ecard-hearts span:nth-child(2) {
    top: 348px;
    right: 12%;
  }

  .ecard-hearts span:nth-child(3) {
    top: 384px;
    right: 62%;
  }

  .ecard-hearts span:nth-child(4) {
    top: 310px;
    right: 76%;
  }
}
