/* =========================================================================
   Ghostagotchi — styles
   Dark room + translucent bone-white egg + sickly green LCD + 3 buttons.
   Solid colors only (no gradients on buttons), no purple, no emojis.
   ========================================================================= */

/* The `hidden` attribute must win over component display rules (flex). */
[hidden] { display: none !important; }

:root{
  --room-bg: #05070a;
  --room-glow: #13110c;
  --plastic: #e9e6da;        /* bone-white */
  --plastic-edge: #b9b3a3;
  --plastic-shadow: #6c6759;
  --lcd-off: #0a160a;        /* unlit LCD pixel base */
  --lcd-on: #8fd86a;         /* sickly green lit pixel */
  --lcd-bezel: #1a1c14;
  --btn-body: #2a2c20;
  --btn-cap: #c9c4b3;
  --btn-cap-press: #8f8a78;
  --ink: #c7c2b0;
  --warn: #b23b2e;
}

*{ box-sizing: border-box; }

html, body{
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--room-bg);
  color: var(--ink);
  font-family: "Courier New", ui-monospace, monospace;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  overflow: hidden;
}

/* The room is a centered vignette with a faint warm glow behind the egg. */
.room{
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 4vh, 36px);
  padding: clamp(10px, 3vh, 28px);
  background:
    radial-gradient(120% 90% at 50% 38%, var(--room-glow) 0%, var(--room-bg) 70%);
}

/* faint ambient speckle so the dark room is not flat */
.room::before{
  content: "";
  position: absolute; inset: 0;
  pointer-events: none;
  background-image:
    radial-gradient(1px 1px at 20% 30%, rgba(255,255,255,0.04), transparent 60%),
    radial-gradient(1px 1px at 70% 60%, rgba(255,255,255,0.03), transparent 60%),
    radial-gradient(1px 1px at 40% 80%, rgba(255,255,255,0.03), transparent 60%);
}

/* ===== Egg ===== */
.egg{
  position: relative;
  --egg-w: min(78vw, 320px, calc(62vh * 0.8));
  width: var(--egg-w);
  aspect-ratio: 4 / 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  /* Padding sized against the egg's own width, not the (very wide) .room,
     so the side padding can't collapse the egg-shell into a thin pill. */
  padding: calc(var(--egg-w) * 0.07) calc(var(--egg-w) * 0.09) calc(var(--egg-w) * 0.06);
}

/* Desktop: scale the egg up with the viewport so the LCD is easy to read.
   Phones (<640px) keep the original sizing above; no horizontal scroll. */
@media (min-width: 640px){
  .egg{
    --egg-w: min(clamp(260px, 42vmin, 420px), calc(72vh * 0.8));
  }
}

.egg-shell{
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  border-radius: 50% 50% 48% 48% / 58% 58% 42% 42%;
  background: var(--plastic);
  /* translucent plastic: faint inner shading using stacked solid-ish layers */
  box-shadow:
    inset 0 2px 4px rgba(255,255,255,0.5),
    inset 0 -10px 22px rgba(0,0,0,0.22),
    inset 6px 0 14px rgba(255,255,255,0.18),
    inset -8px 0 16px rgba(0,0,0,0.16),
    0 18px 40px rgba(0,0,0,0.65),
    0 0 60px rgba(120,170,90,0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  opacity: 0.96;
  backdrop-filter: blur(1px);
}

/* scratches: thin semi-transparent dark lines on the plastic */
.egg-scratch{ position: absolute; background: rgba(60,55,40,0.18); pointer-events: none; }
.s1{ width: 38%; height: 1px; top: 16%; left: 12%; transform: rotate(-18deg); }
.s2{ width: 22%; height: 1px; top: 30%; left: 64%; transform: rotate(8deg); }
.s3{ width: 30%; height: 1px; bottom: 24%; left: 18%; transform: rotate(-6deg); }

/* a small crack near the top */
.egg-crack{
  position: absolute; top: 8%; left: 30%;
  width: 2px; height: 14%;
  background: rgba(60,55,40,0.22);
  box-shadow:
    6px 6px 0 -1px rgba(60,55,40,0.16),
    -4px 12px 0 -1px rgba(60,55,40,0.14);
  transform: rotate(12deg);
  pointer-events: none;
}

/* sticker: aged paper label reading GHOSTAGOTCHI 1997 */
.egg-sticker{
  position: absolute;
  top: 9%; right: 14%;
  transform: rotate(-7deg);
  padding: 4px 7px 3px;
  background: #d8cfb4;
  border: 1px solid #b3aa8c;
  box-shadow: 0 1px 2px rgba(0,0,0,0.35);
  font-family: "Courier New", monospace;
  font-size: clamp(7px, 1.7vw, 10px);
  letter-spacing: 0.5px;
  color: #2c2a22;
  line-height: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  pointer-events: none;
  opacity: 0.9;
}
.egg-sticker .sticker-year{ font-size: 0.85em; opacity: 0.85; }

/* ===== LCD ===== */
.lcd-bezel{
  position: relative;
  width: 74%;
  aspect-ratio: 32 / 16;
  background: var(--lcd-bezel);
  border-radius: 5px;
  box-shadow:
    inset 0 2px 5px rgba(0,0,0,0.6),
    inset 0 -1px 2px rgba(255,255,255,0.05),
    0 1px 0 rgba(255,255,255,0.18);
  padding: 6%;
}
.lcd-bezel canvas{
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--lcd-off);
  border-radius: 2px;
}

/* scanlines overlay (faint horizontal lines over the LCD) */
.lcd-scanlines{
  position: absolute;
  inset: 6%;
  pointer-events: none;
  background-image: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0.0) 0px,
    rgba(0,0,0,0.0) 2px,
    rgba(0,0,0,0.28) 3px,
    rgba(0,0,0,0.0) 4px
  );
  mix-blend-mode: multiply;
  border-radius: 2px;
}
/* subtle glass reflection */
.lcd-glass{
  position: absolute;
  inset: 6%;
  pointer-events: none;
  background: linear-gradient(160deg, rgba(255,255,255,0.10), rgba(255,255,255,0) 38%);
  border-radius: 2px;
}

/* CRT flicker on the whole egg when room is "alive" — handled by JS toggling .flicker */
.egg-shell.flicker{ filter: brightness(0.86); }

/* ===== Buttons ===== */
.buttons{
  display: flex;
  gap: clamp(14px, 5vw, 30px);
  margin-top: 4%;
}
.btn{
  position: relative;
  width: clamp(48px, 13vw, 64px);
  height: clamp(48px, 13vw, 64px);
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
.btn:focus-visible{ outline: 2px solid var(--lcd-on); outline-offset: 3px; }
.btn-cap{
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: var(--btn-cap);
  box-shadow:
    0 4px 0 var(--plastic-shadow),
    0 6px 9px rgba(0,0,0,0.55),
    inset 0 2px 3px rgba(255,255,255,0.55),
    inset 0 -3px 5px rgba(0,0,0,0.22);
  transition: transform 0.05s linear, box-shadow 0.05s linear;
}
.btn-letter{
  position: relative;
  z-index: 1;
  font-family: "Courier New", monospace;
  font-weight: bold;
  font-size: clamp(14px, 3.4vw, 18px);
  color: #2c2a20;
  text-shadow: 0 1px 0 rgba(255,255,255,0.5);
  user-select: none;
}
.btn:active .btn-cap,
.btn.pressed .btn-cap{
  transform: translateY(3px);
  background: var(--btn-cap-press);
  box-shadow:
    0 1px 0 var(--plastic-shadow),
    0 2px 4px rgba(0,0,0,0.55),
    inset 0 2px 3px rgba(255,255,255,0.25),
    inset 0 -3px 5px rgba(0,0,0,0.3);
}
.btn.active-indicator .btn-cap{
  box-shadow:
    0 4px 0 var(--plastic-shadow),
    0 6px 9px rgba(0,0,0,0.55),
    inset 0 2px 3px rgba(255,255,255,0.55),
    inset 0 -3px 5px rgba(0,0,0,0.22),
    0 0 0 3px var(--lcd-on);
}

/* ===== How to Play button ===== */
.help-btn{
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(90px, calc(90px + env(safe-area-inset-right)));
  display: inline-flex;
  align-items: center;
  padding: 6px 10px;
  background: #0c0e08;
  color: var(--ink);
  border: 1px solid #2a2c20;
  border-radius: 20px;
  font-family: "Courier New", monospace;
  font-size: 11px;
  letter-spacing: 1px;
  cursor: pointer;
}
.help-btn:hover{ border-color: var(--lcd-on); }

/* ===== Mute toggle ===== */
.mute{
  position: absolute;
  top: max(12px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  background: #0c0e08;
  color: var(--ink);
  border: 1px solid #2a2c20;
  border-radius: 20px;
  font-family: "Courier New", monospace;
  font-size: 11px;
  letter-spacing: 1px;
  cursor: pointer;
}
.mute-led{
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--lcd-on);
  box-shadow: 0 0 6px var(--lcd-on);
}
.mute.muted .mute-led{
  background: #3a3d2e;
  box-shadow: none;
}

/* ===== Share button ===== */
.share{
  position: absolute;
  bottom: max(14px, env(safe-area-inset-bottom));
  font-family: "Courier New", monospace;
  font-size: 12px;
  letter-spacing: 1.5px;
  color: var(--lcd-on);
  background: #0c0e08;
  border: 1px solid #2a2c20;
  padding: 7px 12px;
  border-radius: 20px;
  text-decoration: none;
  cursor: pointer;
}
.share:hover{ border-color: var(--lcd-on); }
.share.copied{ color: #fff; }

/* ===== Live button labels ===== */
.btn-labels{
  display: flex;
  gap: 14px;
  font-family: "Courier New", monospace;
  font-size: 11px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: #cfe9c0;
  opacity: 0.8;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
.btn-labels span{
  width: 68px;
  text-align: center;
}

/* ===== Selectable link box (clipboard blocked fallback) ===== */
.share-box{
  position: absolute;
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 46px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(90vw, 280px);
  padding: 10px;
  background: #0c0e08;
  border: 1px solid var(--lcd-on);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
  z-index: 8;
}
.share-box-label{
  font-family: "Courier New", monospace;
  font-size: 10px;
  letter-spacing: 1px;
  color: var(--lcd-on);
  text-align: center;
}
.share-box-row{
  display: flex;
  align-items: center;
  gap: 8px;
}
.share-link{
  flex: 1 1 auto;
  min-width: 0;
  font-family: "Courier New", monospace;
  font-size: 11px;
  color: var(--ink);
  background: #05070a;
  border: 1px solid #2a2c20;
  border-radius: 6px;
  padding: 5px 7px;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}
.share-link:focus{ border-color: var(--lcd-on); }
.share-close{
  flex: 0 0 auto;
  width: 24px; height: 24px;
  border: 1px solid #2a2c20;
  background: #05070a;
  color: var(--ink);
  border-radius: 50%;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 0;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.share-close:hover{ border-color: var(--lcd-on); color: var(--lcd-on); }

/* ===== How to Play panel ===== */
.help-panel{
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(90vw, 340px);
  padding: 16px;
  background: #0c0e08;
  border: 2px solid var(--lcd-on);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.8);
  z-index: 10;
}
.help-title{
  margin: 0;
  font-family: "Courier New", monospace;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 1px;
  color: var(--lcd-on);
  text-align: center;
}
.help-text{
  margin: 0;
  font-family: "Courier New", monospace;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
}
.help-close{
  align-self: center;
  padding: 6px 16px;
  background: #05070a;
  border: 1px solid var(--lcd-on);
  border-radius: 6px;
  font-family: "Courier New", monospace;
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--lcd-on);
  cursor: pointer;
}
.help-close:hover{ background: var(--lcd-on); color: #0c0e08; }

/* ===== Haunt overlays ===== */
.haunt-dim{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0);
  pointer-events: none;
  transition: background 0.4s ease;
  z-index: 5;
}
.room.haunting .haunt-dim{ background: rgba(0,0,0,0.72); }
.room.haunting .egg{ filter: hue-rotate(40deg) saturate(1.2); animation: eggShake 0.18s linear infinite; }
.room.haunting #mute,
.room.haunting .share{ filter: brightness(0.5); }

@keyframes eggShake{
  0%{ transform: translate(0,0); }
  25%{ transform: translate(-1px,1px); }
  50%{ transform: translate(1px,-1px); }
  75%{ transform: translate(-1px,-1px); }
  100%{ transform: translate(1px,1px); }
}

/* glitch crawl: a band of scrambled text drifting across the screen */
.glitch-crawl{
  position: fixed;
  left: 0; right: 0;
  top: 0;
  height: 100%;
  pointer-events: none;
  overflow: hidden;
  z-index: 6;
  opacity: 0;
}
.room.haunting .glitch-crawl{ opacity: 1; }
.glitch-crawl .line{
  position: absolute;
  left: 0;
  white-space: nowrap;
  font-family: "Courier New", monospace;
  font-weight: bold;
  color: #b23b2e;
  text-shadow: 2px 0 var(--lcd-on), -2px 0 #1a4d8a;
  letter-spacing: 2px;
  font-size: clamp(14px, 3vw, 22px);
  animation: crawl 6s linear infinite;
}
@keyframes crawl{
  from{ transform: translateX(0); }
  to{ transform: translateX(calc(100vw - 100% - 2vw)); }
}

/* ===== Read-only share card view (opened via ?ghost=...) ===== */
body.cardview .room{ display: none; }
.card{
  display: none;
  position: fixed;
  inset: 0;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
body.cardview .card{ display: flex; }
.card-inner{
  width: min(90vw, 360px);
  background: #0c0e08;
  border: 1px solid #2a2c20;
  border-radius: 14px;
  padding: 22px 20px 24px;
  text-align: center;
  box-shadow: 0 18px 50px rgba(0,0,0,0.7);
}
.card-inner canvas{
  image-rendering: pixelated;
  width: 128px; height: 64px;
  background: var(--lcd-off);
  border-radius: 4px;
  margin: 4px auto 14px;
  display: block;
}
.card-name{
  font-size: 20px;
  letter-spacing: 2px;
  color: var(--lcd-on);
  margin: 0 0 4px;
}
.card-stage{
  font-size: 12px;
  letter-spacing: 1px;
  color: var(--ink);
  opacity: 0.8;
}
.card-note{
  margin-top: 16px;
  font-size: 11px;
  color: var(--ink);
  opacity: 0.6;
  line-height: 1.5;
}
.card a{
  margin-top: 18px;
  display: inline-block;
  color: var(--lcd-on);
  text-decoration: none;
  border: 1px solid #2a2c20;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 11px;
  letter-spacing: 1px;
}
