/* ============================================================
   CAACOTyping — Victoria Harbour desktop theme.

   A pixel-friendly, night-scene Hong Kong skyline that lights up
   building-by-building as the user's daily streak grows. Day 20 of
   their global streak triggers "full bloom" — the entire harbour is
   illuminated and the rooftop Symphony-of-Lights lasers fire.

   Loaded only on the index.html XP-desktop surface. Switching theme
   is controlled by js/desktop-theme.js, which toggles
   .theme-harbour vs .theme-classic on .xp-desktop and writes the
   choice to localStorage (`caaco_desktop_theme`).
   ============================================================ */

/* ---------- THEME GATE ---------- */
/* Hide the harbour layer when classic theme is active. */
.xp-desktop:not(.theme-harbour) .xp-harbour { display: none; }

/* When harbour theme active, override the classic Bliss-hill gradients
   so the harbour SVG owns the entire wallpaper. */
.xp-desktop.theme-harbour {
    background-image: none !important;
    background-color: #04081a !important;
}
/* Also disable the time-of-day sun/cloud overlays that the classic
   theme paints via pseudo-elements (if any). */
.xp-desktop.theme-harbour::before,
.xp-desktop.theme-harbour::after {
    display: none !important;
}

/* ---------- HARBOUR CONTAINER ---------- */
.xp-harbour {
    position: absolute;
    inset: 0;
    z-index: 0;             /* icons (z=1) sit on top */
    overflow: hidden;
    pointer-events: none;   /* let clicks pass through to icons */
    background: #04081a;
}

/* Base + lit layers share identical framing so they stack pixel-aligned.
   Fill exactly (100% 100%) so the two frames register perfectly — the
   "off" image is derived pixel-for-pixel from the "lit" one. */
.harbour-base,
.harbour-lit {
    position: absolute;
    inset: 0;
    background-size: 100% 100%;
    background-position: center;
    background-repeat: no-repeat;
    image-rendering: pixelated;
}

/* ---------- TIME-OF-DAY FRAME (base = solid floor) ----------
   The harbour now uses 10 hand-made frames (17:00 → 20:00); the user's
   login streak picks which one. js/desktop-theme.js sets background-image
   on both layers. `.harbour-base` is the solid floor that always shows the
   current frame; the CSS image below is only a graceful fallback (frame 1,
   17:00) for the brief moment before JS runs. */
.harbour-base {
    background-image: url('../assets/harbour-1700-pixel.webp');
}

/* ---------- FRAME CROSSFADE LAYER ----------
   When the streak advances a day, js/desktop-theme.js paints the NEW frame
   here at opacity 0 and fades it to 1 over the floor (old frame), then the
   floor catches up — a smooth day-to-day transition with no flash. */
.harbour-lit {
    opacity: 0;
    transition: opacity 1100ms ease;
}

/* ---------- FULL-BLOOM CITY GLOW ---------- */
.harbour-glow {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 78%;
    opacity: 0;
    transition: opacity 1600ms ease;
    background: radial-gradient(120% 90% at 50% 100%,
        rgba(255,196,104,0.30) 0%,
        rgba(255,150,120,0.14) 38%,
        rgba(120,160,255,0.06) 64%,
        transparent 80%);
    mix-blend-mode: screen;
    pointer-events: none;
}
.xp-desktop.theme-harbour.harbour-full-bloom .harbour-glow { opacity: 1; }

/* ---------- SYMPHONY OF LIGHTS LASERS (full bloom only) ---------- */
.harbour-lasers {
    position: absolute;
    inset: 0;
    opacity: 0;
    transition: opacity 1500ms ease;
    pointer-events: none;
}
.xp-desktop.theme-harbour.harbour-full-bloom .harbour-lasers { opacity: 1; }
.harbour-lasers .laser {
    position: absolute;
    bottom: 40%;
    width: 3px;
    height: 62%;
    transform-origin: bottom center;
    filter: blur(0.6px);
    mix-blend-mode: screen;
    border-radius: 2px;
}
.harbour-lasers .laser:nth-child(1) { background: linear-gradient(to top, rgba(94,243,255,0),  #5ef3ff 45%, rgba(94,243,255,0));  animation: laserSweep 6.0s ease-in-out infinite; }
.harbour-lasers .laser:nth-child(2) { background: linear-gradient(to top, rgba(255,106,213,0), #ff6ad5 45%, rgba(255,106,213,0)); animation: laserSweep 5.4s ease-in-out infinite 0.7s; }
.harbour-lasers .laser:nth-child(3) { background: linear-gradient(to top, rgba(255,215,94,0),  #ffd75e 45%, rgba(255,215,94,0));  animation: laserSweep 6.8s ease-in-out infinite 1.4s; }
.harbour-lasers .laser:nth-child(4) { background: linear-gradient(to top, rgba(122,252,138,0), #7afc8a 45%, rgba(122,252,138,0)); animation: laserSweep 5.2s ease-in-out infinite 2.1s; }
.harbour-lasers .laser:nth-child(5) { background: linear-gradient(to top, rgba(181,155,255,0), #b59bff 45%, rgba(181,155,255,0)); animation: laserSweep 6.4s ease-in-out infinite 0.4s; }
@keyframes laserSweep {
    0%, 100% { transform: rotate(-20deg); opacity: 0; }
    20%      { opacity: 0.9; }
    50%      { transform: rotate(20deg);  opacity: 0.9; }
    80%      { opacity: 0.7; }
}

/* ---------- FIREWORKS (day-20 milestone) ----------
   Each .fw is a single 4px dot whose box-shadow paints a ring of particles
   at their fully-exploded offsets (in currentColor). Animating transform
   scale 0 → 1 expands the whole particle cluster outward from the centre,
   while opacity pulses, so it reads as a bursting firework. Positions,
   colours and animation-delays are set inline per element for variety. */
.harbour-fireworks {
    position: absolute;
    inset: 0;
    z-index: 1;
    opacity: 0;
    transition: opacity 1400ms ease;
    pointer-events: none;
}
.xp-desktop.theme-harbour.harbour-fireworks-on .harbour-fireworks { opacity: 1; }
.harbour-fireworks .fw {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: currentColor;
    transform: scale(0);
    opacity: 0;
    mix-blend-mode: screen;
    filter: blur(0.4px) drop-shadow(0 0 4px currentColor);
    animation: fwBurst 3s ease-out infinite;
    /* The exploded particle ring (two rings for a fuller burst). */
    box-shadow:
        0 -58px currentColor,    29px -50px currentColor,  50px -29px currentColor,
        58px 0 currentColor,     50px 29px currentColor,   29px 50px currentColor,
        0 58px currentColor,    -29px 50px currentColor,  -50px 29px currentColor,
        -58px 0 currentColor,   -50px -29px currentColor, -29px -50px currentColor,
        0 -32px currentColor,    23px -23px currentColor,  32px 0 currentColor,
        23px 23px currentColor,  0 32px currentColor,     -23px 23px currentColor,
        -32px 0 currentColor,   -23px -23px currentColor;
}
@keyframes fwBurst {
    0%   { transform: scale(0);   opacity: 0; }
    10%  { opacity: 1; }
    55%  { opacity: 1; }
    100% { transform: scale(1) translateY(16px); opacity: 0; }
}

/* ---------- PROGRESS TICKER (overlay banner) ---------- */
/* A small parchment-style label that tells the user how far they are
   from full bloom. Sits at top-left of harbour, hidden in classic. */
.harbour-progress {
    position: absolute;
    top: 12px;
    right: 14px;
    z-index: 2;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(180deg, rgba(15,28,55,0.85) 0%, rgba(9,18,38,0.85) 100%);
    border: 1px solid rgba(255,210,90,0.45);
    color: #ffeab8;
    font-family: Tahoma, "Microsoft Sans Serif", sans-serif;
    font-size: 11px;
    padding: 5px 9px;
    border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.45);
    line-height: 1;
    user-select: none;
    cursor: default;
}
.harbour-progress strong { color: #fff3c8; }
.harbour-progress .harbour-progress__num {
    font-family: "Trebuchet MS", Tahoma, sans-serif;
    font-weight: bold;
    font-size: 13px;
    color: #ffd66b;
    min-width: 1.2em;
    text-align: center;
}
.harbour-progress .harbour-progress__bar {
    display: block;
    width: 72px;
    height: 4px;
    background: #1a2a45;
    border-radius: 2px;
    overflow: hidden;
    flex-shrink: 0;
}
.harbour-progress .harbour-progress__fill {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, #ff8e3c, #ffd66b);
    border-radius: 2px;
    transition: width 1.2s ease;
    box-shadow: 0 0 4px rgba(255,200,80,0.7);
}
.xp-desktop:not(.theme-harbour) .harbour-progress { display: none; }
/* Floated on #xpDesktop — above taskbar (z=2) and desktop icons. */
.harbour-progress.harbour-progress--floated {
    z-index: 10007;
    right: 14px;
    top: 12px;
    bottom: auto;
    left: auto;
    max-width: min(140px, calc(100vw - 28px));
}
.xp-desktop.theme-harbour.harbour-full-bloom .harbour-progress {
    border-color: #ffd66b;
    background: linear-gradient(180deg, rgba(80,55,15,0.85) 0%, rgba(40,25,5,0.85) 100%);
    animation: harbourBadgeShimmer 3s ease-in-out infinite;
}
@keyframes harbourBadgeShimmer {
    0%, 100% { box-shadow: 0 4px 14px rgba(0,0,0,0.45); }
    50%      { box-shadow: 0 4px 18px rgba(255,200,80,0.55); }
}

/* ---------- TIME-OF-DAY PICKER (unlocked at 10-day streak) ----------
   Lives on #xpDesktop (not .xp-harbour) so it sits above icons/widgets. */
.harbour-time-picker {
    position: absolute;
    top: 12px;
    right: 14px;
    z-index: 10008;
    pointer-events: auto;
    max-width: min(420px, calc(100vw - 28px));
    background: linear-gradient(180deg, rgba(15,28,55,0.92) 0%, rgba(9,18,38,0.92) 100%);
    border: 1px solid rgba(255,210,90,0.45);
    border-radius: 4px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.45);
    padding: 6px 8px 8px;
    font-family: Tahoma, "Microsoft Sans Serif", sans-serif;
    color: #ffeab8;
}
.xp-desktop:not(.theme-harbour) .harbour-time-picker,
.xp-desktop:not(.harbour-times-unlocked) .harbour-time-picker { display: none !important; }

.harbour-time-picker__hd {
    font-size: 10px;
    color: #ffd66b;
    margin-bottom: 6px;
    letter-spacing: 0.02em;
}
.harbour-time-picker__grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
}
.harbour-time-picker__btn {
    appearance: none;
    border: 1px solid rgba(255,210,90,0.35);
    background: rgba(20,36,68,0.85);
    color: #ffeab8;
    border-radius: 3px;
    padding: 4px 2px;
    cursor: pointer;
    pointer-events: auto;
    position: relative;
    z-index: 1;
    font-family: "Trebuchet MS", Tahoma, sans-serif;
    font-size: 10px;
    line-height: 1.2;
    transition: background 120ms ease, border-color 120ms ease, transform 80ms ease;
}
.harbour-time-picker__btn:hover {
    background: rgba(40,60,100,0.95);
    border-color: rgba(255,210,90,0.65);
}
.harbour-time-picker__btn.is-active {
    background: linear-gradient(180deg, #ffd66b 0%, #e8a830 100%);
    border-color: #c48820;
    color: #3a2800;
    font-weight: bold;
    box-shadow: 0 0 6px rgba(255,200,80,0.55);
}
.harbour-time-picker__btn:active { transform: scale(0.96); }
.harbour-time-picker__time { display: block; white-space: nowrap; }

@media (max-width: 540px) {
    .harbour-time-picker__grid { grid-template-columns: repeat(5, 1fr); }
    .harbour-time-picker__btn { font-size: 9px; padding: 3px 1px; }
}

/* ---------- PERSONALISE MODAL ---------- */
.caaco-personalise-mask {
    position: fixed;
    inset: 0;
    z-index: 10010;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(2,10,28,0.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    visibility: visible !important;
    font-family: Tahoma, "Microsoft Sans Serif", sans-serif;
}
.caaco-personalise-mask.is-open { display: flex; animation: caacoModalFadeIn 200ms ease-out; }
@keyframes caacoModalFadeIn { from { opacity: 0; } to { opacity: 1; } }

.caaco-personalise {
    width: min(640px, 92vw);
    background: linear-gradient(180deg, #f6faff 0%, #e1ebf8 100%);
    border: 1px solid #4a6f9e;
    border-radius: 6px;
    box-shadow: 0 12px 32px rgba(0,30,80,0.5);
    overflow: hidden;
    color: #1a1a1a;
}
.caaco-personalise__title {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px 6px 10px;
    background: linear-gradient(180deg,#245edc 0%,#2c74e8 40%,#1a52c6 60%,#1147b3 100%);
    color: #fff;
    font-weight: bold;
    font-size: 13px;
    text-shadow: 0 1px 0 rgba(0,0,0,0.35);
}
.caaco-personalise__title-text { flex: 1; }
.caaco-personalise__close {
    width: 20px; height: 20px;
    background: linear-gradient(180deg, #e7f0ff 0%, #b6cdee 100%);
    border: 1px solid #99bbe6;
    border-radius: 2px;
    color: #b22323;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
}
.caaco-personalise__close:hover { background: linear-gradient(180deg, #fff 0%, #c8dcf6 100%); }

.caaco-personalise__body {
    padding: 14px 16px 16px;
}
.caaco-personalise__hd {
    font-size: 12px;
    color: #4a5a72;
    margin-bottom: 12px;
}
.caaco-personalise__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.caaco-personalise__profile {
    margin-top: 16px;
    padding-top: 14px;
    border-top: 1px solid #c8d6ea;
}
.caaco-personalise__profile-note {
    font-size: 12px;
    color: #4a5a72;
    margin: 0 0 10px;
    line-height: 1.45;
}
.caaco-personalise__profile-btn {
    border: 1px solid #4a6f9e;
    background: linear-gradient(180deg, #fff 0%, #e4eefc 100%);
    color: #1a1a1a;
    padding: 6px 12px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.caaco-personalise__profile-btn:hover {
    background: linear-gradient(180deg, #fff 0%, #d4e4fa 100%);
    border-color: #316ac5;
}
.caaco-theme-card {
    display: block;
    background: #fff;
    border: 1px solid #c8d6ea;
    border-radius: 5px;
    overflow: hidden;
    cursor: pointer;
    text-align: left;
    transition: transform 120ms ease, box-shadow 120ms ease, border-color 120ms ease;
    padding: 0;
}
.caaco-theme-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,30,80,0.25);
    border-color: #316ac5;
}
.caaco-theme-card.is-active {
    border-color: #d4a040;
    box-shadow: 0 0 0 2px rgba(255,200,80,0.55), 0 4px 12px rgba(0,30,80,0.25);
}
.caaco-theme-card__preview {
    width: 100%;
    height: 120px;
    background: #888;
    display: block;
    image-rendering: pixelated;
}
.caaco-theme-card__preview--simple {
    background: linear-gradient(165deg, #0d4f8b 0%, #2b88d8 50%, #a8d4f0 100%);
    image-rendering: auto;
}
.caaco-theme-card__preview--classic {
    background:
        linear-gradient(to top, #41853b 0 12%, #6aaa56 12% 19%, #84c36f 19% 27%, transparent 27%),
        linear-gradient(135deg, rgba(255,255,255,0.65) 0 6%, rgba(255,255,255,0.22) 6% 12%, transparent 12%),
        linear-gradient(to bottom, #2b66cf 0%, #60a7ef 35%, #bfe2fb 100%);
}
.caaco-theme-card__preview--harbour {
    background-image: url('../assets/harbour-2000.webp');
    background-size: cover;
    background-position: center;
    image-rendering: pixelated;
}
.caaco-theme-card__meta {
    padding: 8px 10px 10px;
    border-top: 1px solid #d8e1ee;
}
.caaco-theme-card__name {
    font-weight: bold;
    font-size: 12px;
    color: #1a1a1a;
}
.caaco-theme-card__name .is-active-tag {
    display: none;
    margin-left: 6px;
    padding: 1px 6px;
    background: #ffd66b;
    border: 1px solid #d4a040;
    border-radius: 2px;
    font-size: 10px;
    color: #5a3a00;
    vertical-align: middle;
}
.caaco-theme-card.is-active .is-active-tag { display: inline-block; }
.caaco-theme-card__desc {
    font-size: 11px;
    color: #4a5a72;
    margin-top: 3px;
    line-height: 1.45;
}

@media (max-width: 540px) {
    .caaco-personalise__grid { grid-template-columns: 1fr; }
}

/* ---------- REDUCED MOTION ---------- */
@media (prefers-reduced-motion: reduce) {
    .harbour-lit,
    .harbour-lasers .laser,
    .harbour-fireworks .fw,
    .xp-desktop.theme-harbour.harbour-full-bloom .harbour-progress {
        animation: none !important;
    }
}
