@import url('../shared/theme.css');

:root {
  --night: var(--game-bg);
  --night-deep: var(--game-surface);
  --cream: var(--game-text);
  --mint: var(--game-accent);
  --peach: var(--game-warning);
  --muted: var(--game-muted);
  --line: var(--game-divider);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 240px;
  min-height: 100%;
}

body {
  display: grid;
  margin: 0;
  place-items: center;
  color: var(--cream);
  background: var(--night-deep);
  font-family: var(--game-font);
}

button {
  font: inherit;
}

.signature {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(108px, 1fr) auto;
  gap: 0.45rem;
  width: min(100%, 420px);
  height: clamp(220px, 65vw, 260px);
  min-height: 220px;
  padding: 0.75rem;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 0%, var(--game-accent-soft), transparent 42%),
    linear-gradient(145deg, var(--night), var(--night-deep));
  border: 1px solid var(--line);
  border-radius: var(--game-radius);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.eyebrow {
  margin: 0 0 0.1rem;
  color: var(--mint);
  font-family: var(--game-mono);
  font-size: 0.52rem;
  font-weight: 800;
  letter-spacing: 0.16em;
}

h1 {
  margin: 0;
  font-family: var(--game-font);
  font-size: 1.05rem;
  font-weight: 500;
  line-height: 1.1;
}

#count {
  min-width: 3.5rem;
  padding: 0.35rem 0.55rem;
  color: var(--muted);
  background: var(--game-surface-strong);
  border: 1px solid var(--line);
  border-radius: var(--game-radius);
  font-family: var(--game-mono);
  font-size: 0.68rem;
  text-align: center;
}

.sky {
  position: relative;
  width: 100%;
  min-height: 108px;
  padding: 0;
  overflow: hidden;
  color: inherit;
  background:
    radial-gradient(circle at 15% 22%, var(--cream) 0 1px, transparent 1.5px),
    radial-gradient(circle at 76% 68%, var(--mint) 0 1px, transparent 1.5px),
    radial-gradient(circle at 52% 35%, var(--cream) 0 1px, transparent 1.5px), var(--night-deep);
  background-size:
    58px 52px,
    71px 63px,
    89px 76px,
    auto;
  border: 1px solid var(--line);
  border-radius: var(--game-radius);
  cursor: crosshair;
  touch-action: manipulation;
  transition:
    border-color 320ms ease,
    box-shadow 320ms ease,
    background-color 320ms ease;
}

.sky::after {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 50%, rgba(169, 229, 202, 0.12), transparent 68%);
  content: '';
  opacity: 0;
  pointer-events: none;
  transition: opacity 450ms ease;
}

.sky:hover {
  border-color: var(--mint);
}

.sky:focus-visible {
  outline: 3px solid var(--mint);
  outline-offset: 2px;
}

.sky.is-awake {
  border-color: var(--mint);
  box-shadow: inset 0 0 2rem var(--game-accent-soft);
}

.sky.is-awake::after {
  opacity: 1;
}

.threads {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.connection {
  stroke: var(--mint);
  stroke-width: 1.4;
  vector-effect: non-scaling-stroke;
  animation: reveal-thread 380ms ease-out both;
}

.star {
  position: absolute;
  z-index: 2;
  width: 10px;
  height: 10px;
  background: var(--cream);
  border: 2px solid var(--game-bg);
  border-radius: 50%;
  box-shadow: 0 0 0 4px var(--game-accent-soft);
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: place-star 320ms ease-out both;
}

.star:last-of-type {
  background: var(--peach);
}

.sky-prompt {
  position: absolute;
  right: 0.55rem;
  bottom: 0.45rem;
  z-index: 3;
  max-width: calc(100% - 1.1rem);
  padding: 0.25rem 0.45rem;
  overflow: hidden;
  color: var(--cream);
  background: var(--night);
  border: 1px solid var(--line);
  border-radius: var(--game-radius);
  font-family: var(--game-mono);
  font-size: 0.62rem;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.message {
  display: block;
  min-height: 2.6em;
  color: var(--muted);
  font-family: var(--game-font);
  font-size: 0.72rem;
  line-height: 1.3;
  text-align: center;
}

.is-complete + .sr-only + .message {
  color: var(--cream);
}

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

@keyframes place-star {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.35);
  }
}

@keyframes reveal-thread {
  from {
    opacity: 0;
  }
}

html[data-embed='true'],
html[data-embed='true'] body {
  height: 100%;
  min-height: 220px;
  background: transparent;
}

html[data-embed='true'] .signature {
  width: 100%;
  max-width: none;
  height: 100%;
  border-radius: 0;
}

@media (prefers-reduced-motion: reduce) {
  .sky,
  .sky::after {
    transition: none;
  }

  .star,
  .connection {
    animation: none;
  }
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --game-bg: #1c1c1d;
    --game-surface-strong: #2c3237;
    --game-accent-soft: #134e4a;
    --night: #1c1c1d;
    --night-deep: #212529;
    --cream: #e0e0e0;
    --mint: #5eead4;
    --peach: #fbbf24;
    --muted: #9e9e9e;
    --line: #424246;
  }
}
