:root {
  --ink: #3f3350;
  --ink-soft: #6f6280;
  --line: #7d6b8f;
  --line-soft: #cbbbd9;
  --pink: #f49ac1;
  --pink-soft: #fbe3ef;
  --lav: #c3a6f0;
  --lav-soft: #efe7fb;
  --sky-1: #e9eefb;
  --sky-2: #efe6f8;
  --sky-3: #fbe7f0;
  --win-bg: linear-gradient(140deg, #ffffff 0%, #fdf1f7 45%, #f1e9fb 100%);
  --shadow: 3px 3px 0 rgba(90, 70, 110, 0.18);
  --pixel: "Silkscreen", monospace;
  --body: "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--sky-2);
  color: var(--ink);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

img.px { image-rendering: pixelated; image-rendering: crisp-edges; display: block; }

/* Pixel cursors: pink/purple arrow everywhere, butterfly on anything clickable */
html, body { cursor: url("../assets/icons/cursor-arrow.png") 0 0, default; }
button, input[type="range"], video {
  cursor: url("../assets/icons/cursor-butterfly.png") 15 4, pointer;
}

button { font: inherit; color: inherit; }

.btn {
  font-family: var(--pixel);
  font-size: 12px;
  letter-spacing: 0.04em;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 7px 14px;
  box-shadow: inset -2px -2px 0 #eadcf3, inset 2px 2px 0 #fff, 2px 2px 0 rgba(90, 70, 110, 0.2);
  transition: transform 0.08s;
}
.btn:hover { background: var(--pink-soft); }
.btn:active { transform: translate(1px, 1px); box-shadow: inset 2px 2px 0 #eadcf3; }
.btn.small { font-size: 10px; padding: 4px 9px; }

/* ---------- Flapping ---------- */
.flap img { animation: flap 0.5s ease-in-out infinite alternate; transform-origin: center; }
@keyframes flap { from { transform: scaleX(1); } to { transform: scaleX(0.35); } }

/* ---------- Boot ---------- */
#boot {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: linear-gradient(160deg, var(--sky-1), var(--sky-2) 50%, var(--sky-3));
}
.boot-card {
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
#boot-logo { height: 72px; display: grid; place-items: center; margin-bottom: 6px; }
.boot-card h1 { font-family: var(--pixel); font-weight: 400; font-size: 32px; margin: 0; letter-spacing: 0.06em; }
.boot-ver { font-family: var(--pixel); font-size: 11px; color: var(--ink-soft); margin: 0 0 10px; }
.boot-bar {
  width: 240px; height: 16px; border: 1px solid var(--line); background: #fff; padding: 2px;
  box-shadow: var(--shadow);
}
.boot-fill {
  height: 100%; width: 0%;
  background: repeating-linear-gradient(90deg, var(--pink) 0 8px, var(--lav) 8px 16px);
  transition: width 0.4s steps(6);
}
.boot-msg { font-family: var(--pixel); font-size: 11px; color: var(--ink-soft); min-height: 1em; margin: 4px 0 8px; }
.boot-start { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

/* ---------- Desktop ---------- */
#desktop {
  position: fixed; inset: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(255, 255, 255, 0.6), transparent 40%),
    radial-gradient(circle at 80% 70%, rgba(247, 161, 196, 0.18), transparent 45%),
    linear-gradient(160deg, var(--sky-1), var(--sky-2) 50%, var(--sky-3));
  user-select: none;
  animation: fadeIn 0.6s ease;
}
@keyframes fadeIn { from { opacity: 0; } }

#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 26px; z-index: 50;
  display: flex; justify-content: space-between; align-items: stretch;
  background: #fff; border-bottom: 1px solid var(--line);
  font-family: var(--pixel); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
}
#topbar > div { display: flex; align-items: center; gap: 6px; padding: 0 10px; }
.tb-left { border-right: 1px solid var(--line); }
.tb-right { border-left: 1px solid var(--line); }
#topbar > .tb-clock {
  position: absolute; left: 50%; top: 0; bottom: 0; transform: translateX(-50%);
  border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  padding: 0 14px; white-space: pre; gap: 0;
}
.tb-clock .clock-colon.off { visibility: hidden; }

#sky, #garden { position: absolute; inset: 26px 0 0 0; pointer-events: none; overflow: hidden; }
.bfly { position: absolute; top: 0; left: 0; opacity: 0.85; will-change: transform; }
#garden .flower { position: absolute; bottom: -4px; opacity: 0.9; }

#icons {
  position: absolute; top: 44px; left: 16px; z-index: 5;
  display: flex; flex-direction: column; gap: 14px;
}
.icon {
  background: none; border: 0; padding: 4px;
  width: 78px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-family: var(--pixel); font-size: 10px; color: var(--ink);
  position: relative;
}
.icon .icon-img { height: 48px; display: grid; place-items: center; }
.icon span.label { padding: 1px 4px; text-align: center; line-height: 1.4; }
.icon:hover span.label, .icon:focus-visible span.label { background: var(--ink); color: #fff; }
.icon:hover img { transform: translateY(-2px); }
.icon img { transition: transform 0.15s; }
.badge {
  position: absolute; top: 0; right: 10px;
  background: var(--pink); color: #fff; border: 1px solid var(--line);
  font-family: var(--pixel); font-size: 9px; min-width: 16px; height: 16px; line-height: 14px; text-align: center;
  animation: pulse 1.4s ease-in-out infinite;
}

/* ---------- Photo widgets ---------- */
#widgets {
  position: absolute; top: 44px; right: 18px; z-index: 4;
  display: flex; flex-direction: column; gap: 14px;
}
.widget {
  width: 168px; height: 168px; position: relative;
  border-radius: 22px;
  background-size: cover; background-position: center;
  border: 3px solid #fff;
  box-shadow: 0 0 0 1px var(--line), 4px 4px 0 rgba(90, 70, 110, 0.18), 0 10px 24px rgba(90, 70, 110, 0.18);
  animation: widgetIn 0.6s cubic-bezier(.3,1.4,.5,1) both;
  transition: transform 0.2s ease;
}
.widget:hover { transform: translateY(-3px) rotate(-1deg); }
@keyframes widgetIn { from { transform: translateY(-12px) scale(0.85); opacity: 0; } }
.widget-badge {
  position: absolute; left: 10px; bottom: 10px;
  background: rgba(255, 255, 255, 0.92); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px;
}

/* ---------- Windows ---------- */
#windows { position: absolute; inset: 26px 0 0 0; pointer-events: none; }
.win {
  position: absolute; pointer-events: auto;
  display: flex; flex-direction: column;
  background: var(--win-bg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  animation: winOpen 0.18s steps(3);
  max-width: calc(100vw - 16px);
}
@keyframes winOpen { from { transform: scale(0.9); opacity: 0; } }
.win-title {
  height: 22px; flex: none;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  border-bottom: 1px solid var(--line);
  background: repeating-linear-gradient(180deg, #e6d8ee 0 1px, #fbf7fd 1px 3px);
  background-clip: content-box;
  padding: 4px 4px;
  cursor: grab;
  touch-action: none;
}
.win-title:active { cursor: grabbing; }
.win-title span {
  background: #fcf8fd; padding: 0 10px;
  font-family: var(--pixel); font-size: 11px; letter-spacing: 0.04em; text-transform: lowercase;
}
.win-close {
  position: absolute; left: 6px; top: 50%; transform: translateY(-50%);
  width: 13px; height: 13px; padding: 0;
  border: 1px solid var(--line); background: #fcf8fd;
  font-size: 9px; line-height: 10px; font-family: var(--pixel);
}
.win-close:hover { background: var(--pink); color: #fff; }
.win-body { flex: 1; min-height: 0; overflow: auto; position: relative; user-select: text; }

/* retro scrollbars */
.win-body::-webkit-scrollbar { width: 12px; }
.win-body::-webkit-scrollbar-track { background: #faf5fc; border-left: 1px solid var(--line-soft); }
.win-body::-webkit-scrollbar-thumb { background: var(--lav-soft); border: 1px solid var(--line); }

/* ---------- Mail: lock ---------- */
.lock-bar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 18px;
  background: linear-gradient(90deg, #f6e9dd, #f3e4e6);
  border-bottom: 1px solid var(--line-soft);
  transition: margin 0.5s ease, opacity 0.4s;
}
.lock-bar.gone { opacity: 0; margin-top: -110px; }
.lock-form { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.lock-form label { font-size: 13px; font-weight: 600; }
.lock-row { display: flex; gap: 6px; }
.lock-row input {
  flex: 1; min-width: 0;
  font-family: var(--pixel); font-size: 14px; letter-spacing: 0.4em;
  padding: 5px 8px; border: 1px solid var(--line); background: #fff; color: var(--ink);
  box-shadow: inset 2px 2px 0 #eee4f3; outline: none;
}
.lock-row input:focus { border-color: var(--pink); }
.hint-btn {
  align-self: flex-start; background: none; border: 0; padding: 0;
  font-family: var(--pixel); font-size: 10px; color: var(--ink-soft); text-decoration: underline;
}
.hint-btn.nudge { color: #d45d93; animation: pulse 1s ease-in-out infinite; }
.hint { margin: 0; font-size: 12px; color: #b34a7d; font-weight: 600; }

.win-mail .win-body { display: flex; flex-direction: column; overflow-x: hidden; }
.win-mail.unlocked .win-body { display: block; }
.win-video .win-body { overflow: hidden; display: flex; flex-direction: column; }
.win-video:fullscreen { width: 100vw !important; height: 100vh; border: 0; }
.win-video:fullscreen .vid-wrap { flex: 1; width: 100% !important; height: auto !important; min-height: 0; }
.lock-stage {
  flex: 1; min-height: 220px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  transition: opacity 0.5s;
}
.lock-bfly { transition: transform 0.9s ease-in, opacity 0.9s; }
.lock-bfly.shake { animation: shake 0.6s ease-in-out; }
.lock-bfly.flyaway { transform: translate(120px, -260px) rotate(20deg); opacity: 0; }
@keyframes shake {
  0%, 100% { transform: rotate(0); }
  20% { transform: rotate(-16deg); }
  40% { transform: rotate(14deg); }
  60% { transform: rotate(-10deg); }
  80% { transform: rotate(6deg); }
}
.lock-msg { font-family: var(--pixel); font-size: 11px; color: var(--ink-soft); min-height: 1.2em; margin: 0; }
.bubble {
  background: #fff; border: 1px solid var(--line); padding: 6px 10px; position: relative;
  box-shadow: var(--shadow);
}

/* ---------- Mail: letter music bar ---------- */
.mail-player {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: 7px 12px;
  background: linear-gradient(90deg, #fdf3f8, #f3ecfc);
  border-bottom: 1px solid var(--line-soft);
  animation: fadeIn 0.6s ease;
}
.mp-note { font-size: 14px; color: #d45d93; }
.mp-time { font-family: var(--pixel); font-size: 10px; white-space: nowrap; }
.mp-vol { flex: 1; min-width: 50px; max-width: 140px; margin-left: auto; }

/* ---------- Mail: letter ---------- */
.letter { padding: 26px 30px 36px; }
.letter h2 {
  font-family: var(--pixel); font-weight: 400; font-size: 20px; letter-spacing: 0.1em; text-transform: uppercase;
  margin: 0 0 14px;
}
.letter-text p { margin: 0 0 12px; font-size: 15px; line-height: 1.6; }
.letter-sign {
  font-family: var(--pixel); font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase;
  margin: 18px 0 0; line-height: 1.8;
}
.caret {
  display: inline-block; width: 7px; height: 1em; background: var(--pink);
  vertical-align: -2px; margin-left: 1px; animation: blink 0.8s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
.letter-end { margin-top: 26px; display: flex; justify-content: center; animation: fadeIn 0.8s ease; }

/* ---------- Video ---------- */
.vid-wrap { background: #1d1724; position: relative; display: grid; place-items: center; }
.vid-wrap video { display: block; width: 100%; height: 100%; background: #1d1724; }
.vid-controls, .music-btns {
  display: flex; align-items: center; gap: 8px;
}
.vid-controls { padding: 8px 10px; border-top: 1px solid var(--line); }
.vid-controls .time { font-family: var(--pixel); font-size: 10px; white-space: nowrap; }
.vbtn {
  width: 28px; height: 24px; flex: none; padding: 0;
  display: grid; place-items: center;
  background: #fff; border: 1px solid var(--line);
  box-shadow: inset -2px -2px 0 #eadcf3;
}
.vbtn:hover { background: var(--pink-soft); }
.vbtn svg { width: 12px; height: 12px; fill: var(--ink); }
.vol-icon { width: 14px; height: 14px; flex: none; fill: var(--ink); }

input[type="range"] {
  -webkit-appearance: none; appearance: none;
  background: transparent; height: 18px; margin: 0; min-width: 0;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 8px; border: 1px solid var(--line); background: #fff;
  box-shadow: inset 1px 1px 0 #eee4f3;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 16px; margin-top: -5px;
  background: var(--pink); border: 1px solid var(--line);
}
input[type="range"]::-moz-range-track { height: 6px; border: 1px solid var(--line); background: #fff; }
input[type="range"]::-moz-range-progress { height: 6px; background: var(--lav); }
input[type="range"]::-moz-range-thumb { width: 10px; height: 14px; border-radius: 0; background: var(--pink); border: 1px solid var(--line); }
.vid-controls .seek { flex: 1; }
.vid-controls .vol { width: 70px; }

/* ---------- Music ---------- */
.music { display: flex; gap: 14px; padding: 12px; align-items: center; }
.turntable {
  width: 108px; height: 108px; flex: none; position: relative;
  border: 1px solid var(--line); background: #fbf7fd;
  box-shadow: inset -3px -3px 0 #eadcf3;
  display: grid; place-items: center;
}
.vinyl {
  width: 86px; height: 86px; border-radius: 50%;
  background:
    radial-gradient(circle, var(--pink) 0 11px, #fff 11px 13px, transparent 13px),
    repeating-radial-gradient(circle, #231c29 0 2px, #2f2636 2px 4px);
  box-shadow: 0 0 0 1px #1a141f;
  position: relative;
}
.vinyl::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 4px; height: 4px; margin: -2px;
  background: var(--ink); border-radius: 50%;
}
.vinyl::before {
  content: ""; position: absolute; inset: 14px; border-radius: 50%;
  background: conic-gradient(from 20deg, transparent 0 40deg, rgba(255,255,255,0.12) 50deg, transparent 60deg 220deg, rgba(255,255,255,0.08) 230deg, transparent 240deg);
}
.music.playing .vinyl { animation: spin 3s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.arm {
  position: absolute; right: 12px; top: 10px; width: 4px; height: 58px;
  background: #fff; border: 1px solid var(--line);
  transform-origin: top center; transform: rotate(8deg); transition: transform 0.6s ease;
}
.arm::before { content: ""; position: absolute; top: -5px; left: -5px; width: 12px; height: 12px; background: var(--lav); border: 1px solid var(--line); border-radius: 50%; }
.music.playing .arm { transform: rotate(26deg); }
.music-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.song-title { font-family: var(--pixel); font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.song-artist { font-size: 12px; color: var(--ink-soft); margin-top: -3px; }
.music-info .seek { width: 100%; }
.music-info .time { font-family: var(--pixel); font-size: 10px; }
.music-btns .vol { flex: 1; }

/* ---------- Memory match ---------- */
.mm { padding: 12px 14px 16px; }
.mm-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-family: var(--pixel); font-size: 11px; }
.mm-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.card {
  aspect-ratio: 1; padding: 0; border: 0; background: none; perspective: 600px;
}
.card-inner {
  position: relative; width: 100%; height: 100%;
  transform-style: preserve-3d; transition: transform 0.45s ease;
}
.card.flipped .card-inner, .card.matched .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border: 1px solid var(--line); box-shadow: 2px 2px 0 rgba(90, 70, 110, 0.18);
}
.card-back {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.35) 0 4px, transparent 4px 8px),
    linear-gradient(140deg, var(--pink-soft), var(--lav-soft));
  display: grid; place-items: center;
}
.card:hover .card-back { filter: brightness(1.04); }
.card-front { transform: rotateY(180deg); background-size: cover; background-position: center; background-color: #fff; }
.card.matched .card-front { box-shadow: 0 0 0 2px var(--pink); }
.mm-win {
  margin: 14px 0 0; text-align: center; font-weight: 700; font-size: 14px; color: #b34a7d;
  animation: fadeIn 0.6s ease;
}

/* ---------- Quiz ---------- */
.quiz { padding: 18px 20px 20px; }
.quiz h3 { font-family: var(--pixel); font-weight: 400; font-size: 14px; margin: 0 0 6px; letter-spacing: 0.04em; }
.quiz .qnum { font-family: var(--pixel); font-size: 10px; color: var(--ink-soft); margin: 0 0 8px; }
.quiz .qtext { font-size: 16px; font-weight: 700; margin: 0 0 14px; line-height: 1.4; }
.quiz .opts { display: flex; flex-direction: column; gap: 8px; }
.opt {
  text-align: left; font-family: var(--body); font-size: 14px; font-weight: 600;
  background: #fff; border: 1px solid var(--line); padding: 9px 12px;
  box-shadow: 2px 2px 0 rgba(90, 70, 110, 0.15);
}
.opt:hover { background: var(--pink-soft); }
.opt.picked { background: var(--lav); color: #fff; }
.quiz .intro { font-size: 14px; line-height: 1.5; margin: 0 0 16px; }
.quiz .score { font-family: var(--pixel); font-size: 34px; text-align: center; margin: 6px 0 8px; }
.quiz .result { text-align: center; font-size: 14px; font-weight: 600; margin: 0 0 16px; line-height: 1.5; }
.quiz .center { display: flex; justify-content: center; }
.dots { display: flex; gap: 4px; margin-bottom: 12px; }
.dots i { width: 10px; height: 10px; border: 1px solid var(--line); background: #fff; }
.dots i.on { background: var(--pink); }

/* ---------- Trash / note ---------- */
.trash { padding: 18px; min-height: 140px; display: flex; flex-wrap: wrap; gap: 12px; align-content: flex-start; }
.trash-empty { width: 100%; text-align: center; color: var(--ink-soft); font-family: var(--pixel); font-size: 11px; margin-top: 36px; }
.file {
  background: none; border: 0; padding: 4px; width: 96px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-family: var(--pixel); font-size: 9px;
  animation: pop 0.5s ease;
}
.file:hover span { background: var(--ink); color: #fff; }
@keyframes pop { 0% { transform: scale(0); } 70% { transform: scale(1.15); } }
.note { padding: 22px 24px; font-size: 15px; line-height: 1.6; white-space: pre-wrap; }

/* ---------- Toast ---------- */
#toast {
  position: absolute; top: 40px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: #fff; border: 1px solid var(--line); box-shadow: var(--shadow);
  padding: 10px 16px; font-size: 13px; font-weight: 600;
  display: flex; align-items: center; gap: 10px;
  animation: toastIn 0.3s steps(3);
  max-width: calc(100vw - 32px);
}
@keyframes toastIn { from { transform: translate(-50%, -20px); opacity: 0; } }

/* ---------- Finale ---------- */
#finale {
  position: fixed; inset: 0; z-index: 90; overflow: hidden;
  background: linear-gradient(180deg, #f3ecfd 0%, #fbe6f1 60%, #fde2ee 100%);
  animation: fadeIn 1.2s ease;
}
.fin-sky, .fin-garden { position: absolute; inset: 0; pointer-events: none; }
.fin-text {
  position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%);
  text-align: center; width: min(92vw, 900px);
}
.fin-l1 {
  font-family: var(--pixel); font-size: clamp(16px, 3vw, 28px); letter-spacing: 0.06em; margin: 0 0 14px;
  min-height: 1.3em;
}
.fin-name {
  font-family: var(--pixel); font-weight: 400; margin: 0;
  font-size: clamp(38px, 9vw, 104px); letter-spacing: 0.06em;
  color: #e0679f;
  text-shadow: 4px 4px 0 #c3a6f0, 8px 8px 0 rgba(90, 70, 110, 0.12);
  min-height: 1.2em;
}
.fin-l1 span, .fin-name span { display: inline-block; animation: letterIn 0.5s cubic-bezier(.3,1.6,.5,1) both; white-space: pre; }
@keyframes letterIn { from { transform: translateY(24px) scale(0.4); opacity: 0; } }
.fin-flower { position: absolute; bottom: 0; transform-origin: bottom center; animation: grow 1.2s cubic-bezier(.3,1.4,.5,1) both; }
@keyframes grow { from { transform: scaleY(0) scaleX(0.4); } }
.fin-flower img { animation: sway 3s ease-in-out infinite alternate; transform-origin: bottom center; }
@keyframes sway { from { transform: rotate(-4deg); } to { transform: rotate(4deg); } }
.petal {
  position: absolute; top: -20px; width: 8px; height: 8px; background: var(--pink);
  animation: fall linear forwards;
}
@keyframes fall { to { transform: translateY(110vh) rotate(540deg); } }
.fin-close { position: absolute; right: 20px; top: 20px; animation: fadeIn 1s ease; }

/* ---------- Small screens ---------- */
@media (max-width: 700px) {
  #icons { flex-direction: row; top: 34px; left: 8px; right: 8px; gap: 2px; justify-content: space-between; }
  .icon { width: 64px; font-size: 9px; }
  .icon .icon-img { height: 40px; }
  #windows { top: 120px; }
  #widgets { display: none; }
  #topbar > .tb-clock { display: none; }
  .letter { padding: 20px 18px 30px; }
  .lock-bar { padding: 12px; gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .flap img, .music.playing .vinyl, .fin-flower img { animation: none; }
}
