:root {
  --ink: #27364a;
  --muted: #647083;
  --paper: #f8f3ea;
  --panel: #ffffff;
  --line: #2f435c;
  --lime: #d9e56f;
  --pink: #ee7698;
  --blue: #8dd5dc;
  --yellow: #ffc95d;
  --mint: #93d0bc;
  --coral: #f4866c;
  --shadow: 0 10px 24px rgba(47, 67, 92, 0.06);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: "Manrope", Helvetica, Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
  min-width: 0;
}

button {
  cursor: pointer;
}

.is-hidden {
  display: none !important;
}

.login-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--paper);
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='34' height='34' viewBox='0 0 34 34'%3E%3Cg transform='rotate(-36 17 17)'%3E%3Crect x='14' y='3' width='7' height='23' rx='3.5' fill='%23ffffff'/%3E%3Cpath d='M14 25h7l-3.5 6z' fill='%23ffffff'/%3E%3C/g%3E%3C/svg%3E") 3 29, crosshair;
}

.login-doodle-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(90vw, 650px);
  padding: 24px;
  border: 2px solid #d8e1ee;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  cursor: auto;
}

.eyebrow {
  margin: 0 0 8px;
  color: #ef6ca8;
  font-family: "Manrope", Helvetica, Arial, sans-serif;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  font-family: "Manrope", Helvetica, Arial, sans-serif;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.9rem, 6vw, 3.2rem);
  line-height: 1;
}

h2 {
  font-size: clamp(1.45rem, 3vw, 2.55rem);
  line-height: 1.05;
}

h3 {
  font-size: 1.05rem;
}

.login-copy,
.form-note,
.empty-state {
  color: var(--muted);
}

.login-form,
.control-stack,
.studio-toolbar,
.art-dialog form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  max-width: 100%;
  min-height: 40px;
  border: 2px solid #d7e0ed;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
}

button,
.accent-button,
.ghost-button {
  min-height: 40px;
  border: 2px solid #334155;
  border-radius: 13px;
  padding: 8px 13px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  box-shadow: 0 4px 0 #cbd5e1;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

button:hover {
  transform: translateY(-2px) rotate(-0.5deg);
  box-shadow: 0 6px 0 #cbd5e1;
}

button:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #cbd5e1;
}

.accent-button,
.login-form button {
  background: var(--lime);
}

.ghost-button {
  background: #fff;
}

.app-shell {
  width: min(1260px, calc(100% - 44px));
  margin: 0 auto;
  padding: 18px 0 46px;
}

.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 2px 2px 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand small {
  display: block;
  color: var(--muted);
  font-weight: 700;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--yellow);
  font-family: "Baloo 2", sans-serif;
  font-weight: 800;
  rotate: -6deg;
}

.author-tag {
  margin: 0;
  font-size: clamp(1.25rem, 2.7vw, 2.45rem);
  white-space: nowrap;
}

.app-nav {
  position: absolute;
  top: calc(100% - 8px);
  right: 0;
  display: none;
  min-width: 220px;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 10px;
  border: 1px solid #e6dccd;
  border-radius: 16px;
  background: #fffdf8;
  box-shadow: var(--shadow);
}

.app-nav.is-open {
  display: flex;
}

.app-nav a,
.app-nav button {
  min-height: 38px;
  padding: 8px 10px;
  border: 2px solid transparent;
  border-radius: 14px;
  box-shadow: none;
  background: transparent;
  color: inherit;
  font-weight: 800;
  text-decoration: none;
}

.app-nav a:hover,
.app-nav button:hover,
.app-nav a.is-active {
  border-color: var(--line);
  box-shadow: none;
  transform: none;
}

.nav-toggle {
  display: inline-grid;
  place-items: center;
  width: 42px;
  min-width: 42px;
  min-height: 42px;
  margin-left: auto;
  padding: 10px;
  box-shadow: none;
  background: transparent;
}

.nav-toggle span {
  display: block;
  width: 21px;
  height: 2px;
  border-radius: 999px;
  background: var(--line);
}

.panel {
  margin-top: 16px;
  border: 1px solid #e6dccd;
  border-radius: 16px;
  background: #fffdf8;
  box-shadow: var(--shadow);
}

.page {
  display: none;
}

.page.is-active {
  display: block;
}

.home-page {
  min-height: calc(100vh - 110px);
  padding: clamp(16px, 3vw, 32px);
}

.birthday-banner {
  min-height: 118px;
  display: grid;
  align-content: center;
  gap: 6px;
  margin-bottom: clamp(18px, 3vw, 34px);
  border: 1px dashed #d8cdbc;
  border-radius: 14px;
  background: rgba(255, 253, 248, 0.62);
  text-align: center;
}

.birthday-banner p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.95rem, 1.6vw, 1.18rem);
  font-weight: 700;
}

.magnet-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.015em;
  font-family: "Manrope", Helvetica, Arial, sans-serif;
  line-height: 1.08;
}

.magnet-title span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.magnet-title .photo-letter img {
  display: block;
  width: auto;
  height: 1em;
  object-fit: contain;
  user-select: none;
}

.magnet-title .word-gap {
  flex: 0 0 0.34em;
  width: 0.34em;
}

.login-card .magnet-title {
  margin-bottom: 12px;
  flex-wrap: nowrap;
  font-size: clamp(1.75rem, 3.75vw, 2.8rem);
  gap: 0;
}

.home-tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.home-tile {
  display: grid;
  min-height: 158px;
  align-content: space-between;
  gap: 8px;
  padding: 16px;
  border: 1px solid #e6dccd;
  border-radius: 14px;
  background: #fffdf8;
  color: inherit;
  text-decoration: none;
  box-shadow: var(--shadow);
  transition: transform 160ms ease, border-color 160ms ease;
}

.home-tile:hover {
  transform: translateY(-3px);
  border-color: var(--line);
}

.home-tile strong {
  font-family: "Manrope", Helvetica, Arial, sans-serif;
  font-size: 0.98rem;
  line-height: 1;
  font-weight: 800;
}

.home-tile small {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.tile-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid #d8cdbc;
  border-radius: 11px;
  background: var(--tile-accent, #fff);
  font-family: "Manrope", Helvetica, Arial, sans-serif;
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--line);
}

.tile-pink { --tile-accent: #ee7698; }
.tile-blue { --tile-accent: #8dd5dc; }
.tile-mint { --tile-accent: #93d0bc; }
.tile-yellow { --tile-accent: #ffc95d; }

.panel {
  padding: clamp(14px, 3vw, 24px);
}

.section-heading,
.mini-heading,
.button-row,
.gallery-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.prompt-output {
  margin-top: 18px;
  min-height: 118px;
  display: grid;
  place-items: center;
  padding: 18px;
  border: 1px dashed #a8b4c5;
  border-radius: 16px;
  background: linear-gradient(120deg, #fff, #fbfeff);
  font-family: "Baloo 2", "Manrope", sans-serif;
  font-size: clamp(1.15rem, 2.6vw, 2.1rem);
  font-weight: 800;
  text-align: center;
}

.gallery-layout,
.puppet-layout,
.studio-layout {
  display: grid;
  gap: 14px;
  margin-top: 16px;
}

.gallery-layout {
  grid-template-columns: 260px 1fr;
}

.gallery-viewbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}

.gallery-viewbar strong {
  color: var(--ink);
  font-size: 0.98rem;
}

.icon-button {
  width: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50%;
}

.portfolio-panel,
.studio-toolbar,
.control-stack {
  border: 2px solid #d8e1ee;
  border-radius: 16px;
  background: #fff;
  padding: 12px;
}

.portfolio-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.portfolio-pill {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  box-shadow: none;
  text-align: left;
}

.portfolio-pill.is-active {
  background: var(--blue);
}

.upload-zone {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px dashed #a8b4c5;
  border-radius: 16px;
  background: #fff9fd;
}

.upload-zone input {
  display: none;
}

.upload-zone span {
  display: block;
  color: var(--muted);
  font-weight: 800;
}

.gallery-tools {
  align-items: end;
  margin: 14px 0;
}

.gallery-tools label {
  flex: 1;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
}

.gallery-collapsed {
  padding-top: 18px;
}

.gallery-collapsed .section-heading,
.gallery-collapsed .portfolio-panel,
.gallery-collapsed .upload-zone,
.gallery-collapsed .gallery-tools {
  display: none;
}

.gallery-collapsed .gallery-layout {
  display: block;
}

.gallery-collapsed .gallery-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 18px;
}

.gallery-collapsed .art-card,
.gallery-fullscreen .art-card {
  border-color: #edf1f5;
  border-radius: 8px;
  box-shadow: none;
}

.gallery-collapsed .art-card-body,
.gallery-fullscreen .art-card-body {
  display: none;
}

.gallery-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 30;
  overflow: auto;
  width: 100%;
  max-width: none;
  min-height: 100vh;
  margin: 0;
  padding: clamp(18px, 4vw, 48px);
  border: 0;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
}

.gallery-fullscreen .section-heading,
.gallery-fullscreen .portfolio-panel,
.gallery-fullscreen .upload-zone,
.gallery-fullscreen .gallery-tools {
  display: none;
}

.gallery-fullscreen .gallery-layout {
  display: block;
}

.gallery-fullscreen .gallery-viewbar {
  max-width: 1180px;
  margin: 0 auto 22px;
}

.gallery-fullscreen .gallery-grid {
  max-width: 1180px;
  margin: 0 auto;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: clamp(12px, 2vw, 24px);
}

.gallery-fullscreen-mode {
  overflow: hidden;
}

.art-card {
  overflow: hidden;
  border: 1px solid #d8e1ee;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 4px 0 #f1f5f9;
}

.art-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #f5f5f5;
}

.art-card-body {
  display: grid;
  gap: 6px;
  padding: 10px;
}

.art-card-title {
  margin: 0;
  font-weight: 900;
}

.art-card-date {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.card-actions button,
.icon-button {
  min-height: 34px;
  padding: 6px 8px;
  box-shadow: none;
}

.stage {
  position: relative;
  overflow: hidden;
  min-height: min(58vw, 450px);
  border: 1px solid #d8e1ee;
  border-radius: 16px;
  background:
    linear-gradient(90deg, rgba(122, 215, 255, 0.22) 1px, transparent 1px),
    linear-gradient(rgba(255, 139, 209, 0.24) 1px, transparent 1px),
    #ffffff;
  background-size: 24px 24px;
  touch-action: none;
}

.stage.has-background {
  background-position: center;
  background-size: cover;
}

.stage-character {
  position: absolute;
  left: 45%;
  top: 44%;
  width: clamp(76px, 15vw, 150px);
  aspect-ratio: 1;
  border: 2px solid #334155;
  border-radius: 50% 45% 52% 48%;
  background:
    radial-gradient(circle at 38% 38%, var(--pink) 0 7px, transparent 8px),
    radial-gradient(circle at 62% 38%, var(--ink) 0 6px, transparent 7px),
    radial-gradient(circle at 50% 68%, var(--yellow) 0 20%, transparent 21%),
    var(--mint);
  background-position: center;
  background-size: cover;
  box-shadow: 3px 3px 0 var(--line);
  cursor: grab;
  transform: translate(-50%, -50%);
  touch-action: none;
  animation:
    bounceDance var(--bounce-duration, 1.5s) ease-in-out infinite,
    paceDance var(--pace-duration, 7s) ease-in-out infinite,
    floatDance var(--float-duration, 4s) ease-in-out infinite;
}

.stage-character:active {
  cursor: grabbing;
}

@keyframes bounceDance {
  0%, 100% { margin-top: 0; }
  50% { margin-top: calc(var(--bounce-distance, 18px) * -1); }
}

@keyframes paceDance {
  0%, 100% { margin-left: calc(var(--pace-distance, 24px) * -1); }
  50% { margin-left: var(--pace-distance, 24px); }
}

@keyframes floatDance {
  0%, 100% { rotate: -2deg; }
  50% { rotate: 5deg; }
}

.puppet-layout {
  grid-template-columns: minmax(0, 1fr) 260px;
}

.studio-layout {
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  align-items: start;
  overflow: hidden;
}

.studio-toolbar,
.canvas-wrap {
  min-width: 0;
}

.studio-toolbar {
  overflow: hidden;
}

.studio-toolbar label,
.studio-toolbar input,
.studio-toolbar select,
.studio-toolbar .studio-actions,
.crayon-box {
  min-width: 0;
  max-width: 100%;
}

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

.studio-actions button {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 7px 9px;
  border-radius: 12px;
  text-align: center;
  white-space: normal;
}

.canvas-wrap {
  overflow: hidden;
  border: 1px solid #d8e1ee;
  border-radius: 16px;
  background: #fff;
}

#studioCanvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  background: #ffffff;
  cursor: crosshair;
}

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

.swatch {
  min-height: 26px;
  border: 2px solid #334155;
  border-radius: 8px;
  box-shadow: none;
  padding: 0;
}

.swatch.is-active {
  outline: 3px solid var(--lime);
  outline-offset: 2px;
}

.art-dialog {
  width: min(92vw, 460px);
  border: 1px solid #d8e1ee;
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.art-dialog::backdrop {
  background: rgba(23, 32, 38, 0.28);
}

.check-list {
  display: grid;
  gap: 8px;
  max-height: 180px;
  overflow: auto;
}

.check-list label {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.check-list input {
  width: auto;
  min-height: auto;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 18px, 720px);
  }

  .app-nav {
    top: calc(100% - 10px);
  }

  .home-tiles,
  .gallery-layout,
  .puppet-layout,
  .studio-layout {
    grid-template-columns: 1fr;
  }

  .section-heading,
  .gallery-tools,
  .upload-zone {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .section-heading {
    display: grid;
  }

  .puppet-layout {
    display: flex;
    flex-direction: column;
  }

  .control-stack {
    order: -1;
  }

  .studio-toolbar {
    order: 2;
  }

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

@media (max-width: 520px) {
  .author-tag {
    font-size: clamp(1.05rem, 6.4vw, 1.55rem);
  }

  .login-card {
    padding: 18px;
    box-shadow: var(--shadow);
  }

  .login-card .magnet-title {
    flex-wrap: wrap;
    font-size: clamp(1.55rem, 8.5vw, 2.2rem);
  }

  .panel {
    box-shadow: var(--shadow);
  }

  .gallery-grid {
    grid-template-columns: 1fr;
  }

  .gallery-viewbar {
    align-items: stretch;
    flex-direction: column;
  }

  .gallery-collapsed .gallery-grid,
  .gallery-fullscreen .gallery-grid {
    grid-template-columns: 1fr;
  }

  .card-actions,
  .button-row {
    grid-template-columns: 1fr;
    display: grid;
  }
}
