@import url("../design_system/tokens.css");

*,
*::before,
*::after {
  box-sizing: border-box;
}

*:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

html {
  -webkit-text-size-adjust: 100%;
}

@keyframes app-gradient-shift {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-sans);
  background: linear-gradient(120deg, #d1f7ff, #dde8eb, #d1f7ff);
  background-size: 220% 220%;
  animation: app-gradient-shift 14s ease-in-out infinite;
  color: var(--color-heading);
}

[data-theme="dark"] body {
  background: linear-gradient(120deg, #111213, #171031, #111213);
  background-size: 220% 220%;
}

#app {
  min-height: 100dvh;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* —— Figma: Primary Button —— */
.ds-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 10px 16px;
  border-radius: var(--radius-control);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25rem;
  cursor: pointer;
  border: 1px solid var(--color-primary);
  background: var(--color-primary);
  color: var(--color-white);
}

.ds-btn--sm {
  min-height: 36px;
  padding: 8px 12px;
  font-size: 0.8125rem;
}

.ds-btn--ghost {
  background: var(--color-surface);
  color: var(--color-heading);
  border-color: var(--color-border);
}

/* —— Figma: Card —— */
.ds-card {
  display: flex;
  width: 100%;
  max-width: 350px;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 24px;
  border-radius: var(--radius-card);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: var(--shadow-card);
}

.ds-card__header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: center;
  width: 100%;
}

.ds-card__title {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 2rem;
  letter-spacing: -0.009em;
  color: var(--color-heading);
}

.ds-card__desc {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.25rem;
  color: var(--color-muted);
}

.ds-card__footer {
  display: flex;
  width: 100%;
  justify-content: center;
}

/* —— Figma: Menubar —— */
.ds-menubar {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-control);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.ds-menubar__btn {
  margin: 0;
  padding: 6px 12px;
  border: none;
  border-radius: 4px;
  background: var(--color-surface);
  color: var(--color-heading);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.ds-menubar__btn.is-active {
  background: var(--color-primary);
  color: var(--color-white);
}

/* —— Views —— */
.view-landing {
  display: flex;
  min-height: 100dvh;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: transparent;
}

.view-landing .robot-scene {
  width: min(78vmin, 280px);
  height: min(78vmin, 280px);
}

.view-main {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  padding: 0.75rem 1rem calc(5.25rem + env(safe-area-inset-bottom, 0px));
  background: transparent;
  box-sizing: border-box;
  position: relative;
}

.head-reset-btn {
  position: fixed;
  top: calc(0.5rem + env(safe-area-inset-top, 0px));
  right: calc(0.5rem + env(safe-area-inset-right, 0px));
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-heading);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  z-index: 60;
}

.head-reset-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.view-main__stack {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  max-width: min(100%, 480px);
  margin: 0 auto;
  min-height: 0;
  padding-top: calc(2.25rem + env(safe-area-inset-top, 0px));
}

.robot-stage-wrap {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.motion-hint {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 350px;
  margin-inline: auto;
  padding: 12px calc(2.5rem + env(safe-area-inset-right, 0px)) 12px 12px;
  border-radius: var(--radius-control);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  font-size: 0.875rem;
  line-height: 1.35;
  color: var(--color-muted);
  text-align: center;
}

.motion-hint p {
  margin: 0;
  width: 100%;
  text-align: center;
}

.motion-hint--below {
  flex-shrink: 0;
  margin-top: auto;
  padding-bottom: 0.25rem;
}

/* —— 3D robot (SVG vector, CSS 3D) —— */
.robot-scene {
  width: min(82vmin, min(88vw, 360px));
  height: min(82vmin, min(88vw, 360px));
  max-width: 100%;
  max-height: 100%;
  position: relative;
  margin: 0 auto;
  touch-action: none;
  cursor: grab;
}

.robot-scene:active {
  cursor: grabbing;
}

.robot-stars {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}

.robot-stars.is-active {
  opacity: 1;
}

.robot-notes {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}

.robot-notes.is-active {
  opacity: 1;
}

.robot-confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
}

.robot-confetti.is-active {
  opacity: 1;
}

.robot-star {
  position: absolute;
  color: #8fd4ff;
  text-shadow: 0 0 8px rgba(143, 212, 255, 0.6);
  transform: translateZ(0);
  animation: star-twinkle 0.45s ease-in-out infinite alternate;
}

.robot-star.s1 {
  left: 12%;
  top: 36%;
  font-size: 1.275rem;
  animation-delay: 0s;
}

.robot-star.s2 {
  left: 19%;
  top: 25%;
  font-size: 0.975rem;
  animation-delay: 0.12s;
}

.robot-star.s3 {
  right: 15%;
  top: 32%;
  font-size: 1.425rem;
  animation-delay: 0.07s;
}

.robot-star.s4 {
  right: 23%;
  top: 22%;
  font-size: 0.9rem;
  animation-delay: 0.18s;
}

.robot-note {
  position: absolute;
  color: #5ca2ff;
  text-shadow: 0 0 10px rgba(92, 162, 255, 0.45);
  animation: note-float 0.95s ease-in-out infinite;
}

.robot-note.n1 {
  left: 9%;
  top: 52%;
  font-size: 1.5rem;
  animation-delay: 0s;
}

.robot-note.n2 {
  left: 18%;
  top: 40%;
  font-size: 1.62rem;
  animation-delay: 0.16s;
}

.robot-note.n3 {
  right: 16%;
  top: 49%;
  font-size: 1.425rem;
  animation-delay: 0.1s;
}

.robot-note.n4 {
  right: 9%;
  top: 38%;
  font-size: 1.65rem;
  animation-delay: 0.24s;
}

.robot-confetti-piece {
  position: absolute;
  width: 7px;
  height: 10px;
  border-radius: 2px;
  opacity: 0.85;
  animation: confetti-fall 1.25s linear infinite;
}

.robot-confetti-piece.c1 { left: 6%; top: 6%; background: #ff7ab6; animation-delay: 0s; }
.robot-confetti-piece.c2 { left: 19%; top: 4%; background: #ffd166; animation-delay: 0.15s; }
.robot-confetti-piece.c3 { left: 32%; top: 8%; background: #7ef7c3; animation-delay: 0.28s; }
.robot-confetti-piece.c4 { left: 47%; top: 3%; background: #6aa6ff; animation-delay: 0.41s; }
.robot-confetti-piece.c5 { left: 61%; top: 7%; background: #c992ff; animation-delay: 0.09s; }
.robot-confetti-piece.c6 { left: 74%; top: 2%; background: #ff9f6e; animation-delay: 0.22s; }
.robot-confetti-piece.c7 { left: 86%; top: 5%; background: #6de0ff; animation-delay: 0.34s; }
.robot-confetti-piece.c8 { left: 93%; top: 1%; background: #ff6b8f; animation-delay: 0.5s; }

@keyframes star-twinkle {
  0% {
    opacity: 0.28;
    transform: scale(0.84);
  }
  100% {
    opacity: 1;
    transform: scale(1.18);
  }
}

@keyframes note-float {
  0% {
    opacity: 0.35;
    transform: translateY(4px) scale(0.88);
  }
  60% {
    opacity: 1;
    transform: translateY(-8px) scale(1.08);
  }
  100% {
    opacity: 0.35;
    transform: translateY(-16px) scale(0.92);
  }
}

@keyframes confetti-fall {
  0% {
    transform: translateY(-6px) rotate(0deg);
    opacity: 0;
  }
  10% {
    opacity: 0.95;
  }
  100% {
    transform: translateY(210px) rotate(430deg);
    opacity: 0;
  }
}

.robot-perspective {
  width: 100%;
  height: 100%;
  perspective: 900px;
  perspective-origin: 50% 50%;
}

.robot-pivot {
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  display: flex;
  align-items: center;
  justify-content: center;
  will-change: transform;
}

.robot-svg-host {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-style: preserve-3d;
}

.robot-svg-host svg.robot-vector {
  display: block;
  width: 100%;
  height: auto;
  max-height: 100%;
  aspect-ratio: 261 / 267;
  user-select: none;
}

.robot-svg-host svg.robot-vector .robot-eyes {
  transform-box: fill-box;
  transform-origin: center center;
}

@keyframes robot-eye-blink {
  0%,
  40%,
  60%,
  100% {
    transform: scaleY(1);
  }
  50% {
    transform: scaleY(0.07);
  }
}

.robot-svg-host svg.robot-vector .robot-eyes.robot-eyes--blink {
  animation: robot-eye-blink 0.22s ease-in-out;
}

.robot-img {
  display: block;
  max-width: 100%;
  max-height: min(72vw, 280px);
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  filter: drop-shadow(0 14px 28px rgba(0, 29, 77, 0.14));
}

.view-settings {
  min-height: 100dvh;
  padding: 1rem 1rem 5.5rem;
  background: var(--color-surface);
}

.view-tetris {
  min-height: 100dvh;
  background: transparent;
  color: var(--color-heading);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.tetris-close-btn {
  position: fixed;
  top: calc(0.5rem + env(safe-area-inset-top, 0px));
  left: calc(0.5rem + env(safe-area-inset-left, 0px));
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-heading);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  z-index: 60;
}

.tetris-close-btn svg {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.tetris-wrap {
  width: min(90vw, 320px);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}

.tetris-score {
  width: 100%;
  text-align: center;
  font-size: 1rem;
  font-weight: 600;
}

.tetris-canvas {
  width: 100%;
  height: auto;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
  touch-action: none;
}

.settings-block {
  border-bottom: 1px solid var(--color-divider);
  padding: 1rem 0;
}

.settings-block__title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-settings-title);
}

.settings-stat-heading {
  margin: 0.75rem 0 0.4rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-heading);
  letter-spacing: 0.02em;
}

.settings-stat-heading:first-of-type {
  margin-top: 0;
}

.settings-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 1rem;
  font-size: 0.875rem;
  color: var(--color-muted);
}

.stat-grid span:nth-child(even) {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--color-heading);
}

.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  cursor: pointer;
  padding: 0;
}

.toggle[aria-checked="true"] {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.toggle::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-white);
  transition: transform 0.15s ease;
}

.toggle[aria-checked="true"]::after {
  transform: translateX(20px);
}

.select-field {
  width: 100%;
  max-width: 200px;
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-control);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-heading);
  font-family: inherit;
  font-size: 0.875rem;
}

[data-theme="dark"] .ds-menubar__btn.is-active {
  background: var(--color-white);
  color: #0f152a;
}

[data-theme="dark"] .ds-btn {
  background: var(--color-white);
  border-color: var(--color-white);
  color: #0f152a;
}

[data-theme="dark"] .toggle {
  background: rgba(255, 255, 255, 0.2);
}
