:root {
  --bg: #f4ede0;
  --paper: #fbf7ec;
  --paper-edge: #e3d3ae;
  --ink: #2b2620;
  --ink-soft: #8a7f68;
  --line: #d9cfb8;

  --purple: #7c5cff;
  --purple-dark: #6a3ff0;
  --pink: #ff5f96;
  --orange: #ff9a3d;
  --teal: #2ee6b8;
  --yellow: #ffd93d;
  --rainbow: linear-gradient(90deg, var(--orange), var(--pink), var(--purple), #4fb8ff, var(--teal), var(--yellow));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh; /* iOS Safari sizes vh against the chrome-hidden viewport, so a plain
                     100% here can be taller than what's actually visible on load */
  background: var(--bg);
  color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.stage {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 2.4vh 4vw 2.2vh;
}

/* ---- top bar ---- */

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-shrink: 0;
}

.brand {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.back-link {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 0.8vh;
  color: var(--ink-soft);
  font-size: clamp(10px, 1.4vh, 12px);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-decoration: none;
}
.back-link:hover { color: var(--ink); }
.back-link svg { width: 13px; height: 13px; }

.title {
  margin: 0;
  font-size: clamp(16px, 2.6vh, 21px);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.title-accent {
  background: linear-gradient(90deg, var(--pink), var(--purple));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-divider {
  display: flex;
  align-items: center;
  gap: 0.4em;
  margin: 0.5em 0 0.35em;
}

.brand-divider span {
  display: block;
  height: 1px;
  width: 1.2em;
  background: var(--line);
}

.brand-divider span.dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--line);
}

.subtitle {
  margin: 0;
  font-size: clamp(10px, 1.4vh, 12px);
  letter-spacing: 0.3em;
  color: var(--ink-soft);
}

.top-actions {
  display: flex;
  gap: 2vw;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: transparent;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
}

.icon-btn:active {
  background: rgba(124, 92, 255, 0.12);
  border-color: var(--purple);
  color: var(--purple-dark);
  transform: scale(0.94);
}

.tagline-accent {
  color: var(--purple);
  font-weight: 700;
}

/* ---- canvas ---- */

.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 2vh 0;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  border-radius: 22px;
  background-color: var(--paper);
  background-image: radial-gradient(circle, rgba(43, 38, 32, 0.1) 1px, transparent 1.6px);
  background-size: 22px 22px;
  background-position: 11px 11px;
  border: 1.5px solid var(--paper-edge);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.6), 0 1.4vh 3vh rgba(60, 45, 20, 0.12);
  overflow: hidden;
}

canvas#canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.idle-prompt {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.2vh;
  text-align: center;
  padding: 0 6vw;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.idle-prompt svg {
  color: var(--purple);
  opacity: 0.85;
}

.idle-heading {
  margin: 0;
  font-size: clamp(15px, 2.2vh, 19px);
  font-weight: 800;
  line-height: 1.45;
  color: var(--ink);
}

.idle-hint {
  margin: 0;
  padding: 0.8vh 4vw;
  border: 1.5px dashed var(--purple);
  border-radius: 999px;
  background: rgba(124, 92, 255, 0.06);
  font-size: clamp(11px, 1.6vh, 13px);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--purple-dark);
  animation: pulse 1.8s ease-in-out infinite;
}

.idle-prompt.hide {
  opacity: 0;
}

@keyframes pulse {
  0%, 100% { opacity: 0.55; }
  50% { opacity: 1; }
}

/* ---- how to play ---- */

.howto-link {
  align-self: center;
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--purple-dark);
  font-weight: 600;
  font-size: clamp(12px, 1.8vh, 14px);
  letter-spacing: 0.02em;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  padding: 1vh 4px 0;
}

.seo-info {
  flex-shrink: 0;
  align-self: center;
  max-width: 90vw;
  margin-top: 0.6vh;
  font-size: 9px;
  color: var(--ink-soft);
  text-align: center;
}
.seo-info summary {
  cursor: pointer;
  letter-spacing: 0.06em;
  font-weight: 600;
  list-style: none;
}
.seo-info summary::-webkit-details-marker { display: none; }
.seo-info summary::after { content: " ▾"; }
.seo-info[open] summary::after { content: " ▴"; }
.seo-info p {
  margin: 4px 0 0;
  line-height: 1.5;
  text-align: left;
}

.howto-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30, 24, 16, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  z-index: 10;
}

.howto-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

.howto-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -1vh 3vh rgba(0, 0, 0, 0.25);
  padding: 1.6vh 6vw calc(4vh + env(safe-area-inset-bottom, 0px));
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(.4,0,.2,1);
  z-index: 11;
}

.howto-sheet.show {
  transform: translateY(0);
}

.howto-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--ink-soft);
  opacity: 0.4;
  margin: 0 auto 2vh;
}

.howto-title {
  margin: 0 0 1.6vh;
  font-size: clamp(14px, 2vh, 16px);
  font-weight: 600;
  letter-spacing: 0.1em;
  color: var(--ink);
}

.howto-list {
  margin: 0;
  padding: 0 0 0 1.1em;
  display: flex;
  flex-direction: column;
  gap: 1.2vh;
  font-size: clamp(13px, 1.9vh, 15px);
  color: var(--ink);
  line-height: 1.4;
}
.howto-list li::marker {
  color: var(--purple);
  font-weight: 700;
}

/* ---- game over overlay ----
   Translucent, not opaque: the whole point of the finished doodle is that it
   stays visible as the player's result, so the overlay only needs to sit on
   top of it, not hide it. */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: max(6vh, env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(244, 237, 224, 0.92) 0%, rgba(244, 237, 224, 0.55) 40%, rgba(244, 237, 224, 0) 75%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.overlay.show {
  opacity: 1;
  pointer-events: auto;
}

.overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.6vh;
}

.overlay-icon {
  color: var(--purple);
  margin-bottom: -0.4vh;
}

.overlay-title-row {
  display: flex;
  align-items: center;
  gap: 2.2vw;
}

.overlay-title {
  margin: 0;
  font-size: clamp(20px, 4vh, 30px);
  font-weight: 800;
  letter-spacing: 0.06em;
  background: linear-gradient(90deg, var(--pink), var(--orange));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.deco {
  font-size: clamp(12px, 2vh, 16px);
  line-height: 1;
}
.deco-1 { color: var(--purple); }
.deco-2 { color: var(--orange); }

.overlay-sub {
  margin: 0;
  font-size: clamp(12px, 1.8vh, 14px);
  color: var(--ink-soft);
  letter-spacing: 0.04em;
}

.overlay-actions {
  display: flex;
  gap: 3vw;
  margin-top: 0.6vh;
}

.again-btn,
.share-btn {
  display: flex;
  align-items: center;
  gap: 0.5em;
  padding: 1.2vh 4vw;
  border-radius: 999px;
  font-size: clamp(12px, 1.8vh, 14px);
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: transform 0.1s ease;
}
.again-btn:active,
.share-btn:active { transform: scale(0.96); }

.again-btn {
  border: none;
  background: linear-gradient(135deg, var(--purple), var(--purple-dark));
  color: #fff;
  box-shadow: 0 0.8vh 1.8vh rgba(124, 92, 255, 0.4);
}

.share-btn {
  border: 1.5px solid var(--purple);
  background: transparent;
  color: var(--purple-dark);
}

.share-note {
  margin: 0;
  font-size: clamp(11px, 1.5vh, 13px);
  color: var(--ink-soft);
  letter-spacing: 0.06em;
  opacity: 0;
  transition: opacity 0.25s ease;
}

.share-note.show {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .idle-hint { animation: none; }
}

/* ---- short viewports (phone landscape) ----
   The canvas box is just "whatever's left" after the surrounding rows —
   on a short/rotated viewport those fixed rows eat a disproportionate
   share of it, so trim the least essential ones to give the canvas back
   its room. Purely cosmetic: nothing here is removed from the DOM, so it
   stays in the page source for crawlers, it's just not rendered here. */
@media (max-height: 480px) {
  .stage { padding-top: 1.4vh; padding-bottom: 1.2vh; }
  .brand-divider, .subtitle, .seo-info { display: none; }
  .back-link { margin-bottom: 0.3vh; }
  .howto-link { padding-top: 0.4vh; }
}
