/* ==========================================================
   THE FORT BUILDER CHRONICLE
   Clash of Clans-inspired twilight Builder Base
   ========================================================== */

:root {
  --midnight: #0a1230;
  --deep: #101c45;
  --charcoal: #1b1f2c;
  --stone: #2b3041;
  --forest: #12301f;
  --gold: #e8b84a;
  --gold-hi: #ffe08a;
  --gold-lo: #8a5a1f;
  --bronze: #a86a2e;
  --turq: #3de0d0;
  --emerald: #3ecf8e;
  --text: #f4f1e8;
  --text-dim: #b9c2d6;
  --ink: #0b0d15;

  --font-display: "Arial Rounded MT Bold", "Avenir Next", "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --font-text: Georgia, "Palatino Linotype", "Book Antiqua", Palatino, "Noto Serif", serif;
}

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--midnight);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  color: var(--text);
  font-family: var(--font-text);
  line-height: 1.4;
  /* no body background: the fixed .scene sits behind the content and html supplies the base colour */
  -webkit-tap-highlight-color: transparent;
}

h1, h2, p { margin: 0; }

/* ---------- Cartoon outline text (Clash-style lettering) ---------- */
.game, h1, .elapsed, .days-num, .tile-num, .ribbon span, .zone-name, .badge-title, .tag, .copy {
  font-family: var(--font-display);
  font-weight: 900;
}

/* ==========================================================
   BACKGROUND SCENE
   ========================================================== */
.scene {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
}

.sky {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 90% 50% at 76% 24%, rgba(61, 224, 208, .16), transparent 70%),
    radial-gradient(ellipse 120% 55% at 50% 100%, rgba(232, 150, 60, .22), transparent 70%),
    linear-gradient(180deg, #050a22 0%, #0a1536 38%, #15305a 70%, #1d4a5e 100%);
}

.scene-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.veil {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(5, 10, 34, .55) 0%, rgba(5, 10, 34, .25) 45%, rgba(5, 10, 34, .55) 100%);
}

/* clouds: plain radial gradients, no blur filters */
.cloud {
  position: absolute;
  left: -40vw;
  width: 70vw;
  max-width: 760px;
  height: 160px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(150, 190, 230, .20) 0%, rgba(150, 190, 230, .08) 45%, transparent 72%);
  will-change: transform;
  animation: drift 110s linear infinite;
}
.cloud-a { top: 9%; }
.cloud-b { top: 24%; height: 130px; animation-duration: 150s; animation-delay: -60s; opacity: .8; }
.cloud-c { top: 40%; height: 180px; animation-duration: 190s; animation-delay: -120s; opacity: .6; }

@keyframes drift {
  from { transform: translate3d(0, 0, 0); }
  to   { transform: translate3d(190vw, 0, 0); }
}

/* lit windows and torches */
.win { animation: flicker 5s ease-in-out infinite; }
.w2 { animation-duration: 7s; animation-delay: -2s; }
.w3 { animation-duration: 6s; animation-delay: -4s; }
.w4 { animation-duration: 9s; animation-delay: -1s; }

@keyframes flicker {
  0%, 100% { opacity: .95; }
  45% { opacity: .65; }
  60% { opacity: 1; }
}

.torch { animation: torch 2.8s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.torch.t2 { animation-delay: -1.2s; }

@keyframes torch {
  0%, 100% { opacity: .85; }
  50% { opacity: .55; }
}

/* floating embers (spawned by script.js) */
.embers { position: absolute; inset: 0; overflow: hidden; }

.ember {
  position: absolute;
  bottom: -12px;
  left: var(--x);
  width: var(--s);
  height: var(--s);
  border-radius: 50%;
  background: radial-gradient(circle, #fff1b8 0%, #ffb347 55%, rgba(255, 140, 40, 0) 100%);
  opacity: 0;
  will-change: transform, opacity;
  animation: rise var(--d) linear var(--delay) infinite;
}
.ember.cool { background: radial-gradient(circle, #d6fffb 0%, #3de0d0 55%, rgba(61, 224, 208, 0) 100%); }

@keyframes rise {
  0%   { transform: translate3d(0, 0, 0); opacity: 0; }
  12%  { opacity: .9; }
  80%  { opacity: .5; }
  100% { transform: translate3d(var(--dx), -105vh, 0); opacity: 0; }
}

/* ==========================================================
   PAGE LAYOUT
   ========================================================== */
.page {
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding:
    max(18px, env(safe-area-inset-top))
    max(14px, env(safe-area-inset-right))
    max(22px, env(safe-area-inset-bottom))
    max(14px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Title ---------- */
.title { text-align: center; padding-top: 4px; }

.game {
  font-size: .8rem;
  letter-spacing: .32em;
  color: var(--gold-hi);
  text-shadow: 0 2px 0 #3a2410, 0 0 12px rgba(232, 184, 74, .35);
}

h1 {
  margin-top: 4px;
  font-size: clamp(1.25rem, 6.2vw, 2rem);
  line-height: 1.12;
  letter-spacing: .04em;
  color: #fff;
  text-shadow:
    -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink),
    0 4px 0 var(--ink), 0 6px 14px rgba(0, 0, 0, .55);
  overflow-wrap: anywhere;
}

/* ==========================================================
   THE MONUMENT (stopwatch)
   ========================================================== */
.monument {
  position: relative;
  padding: 6px;
  border-radius: 24px;
  background: linear-gradient(145deg, var(--gold-hi) 0%, var(--gold) 22%, var(--gold-lo) 52%, var(--gold) 78%, var(--gold-hi) 100%);
  box-shadow:
    0 0 0 2px #2a1a08,
    0 18px 40px rgba(0, 0, 0, .55),
    0 0 46px rgba(61, 224, 208, .16);
  animation: frameGlow 6s ease-in-out infinite;
}

@keyframes frameGlow {
  0%, 100% { box-shadow: 0 0 0 2px #2a1a08, 0 18px 40px rgba(0,0,0,.55), 0 0 34px rgba(61,224,208,.12); }
  50%      { box-shadow: 0 0 0 2px #2a1a08, 0 18px 40px rgba(0,0,0,.55), 0 0 54px rgba(61,224,208,.26); }
}

/* shimmering gold edge */
.monument::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 24px;
  background: linear-gradient(115deg, transparent 38%, rgba(255, 255, 255, .45) 50%, transparent 62%);
  background-size: 260% 100%;
  background-position: 120% 0;
  mix-blend-mode: overlay;
  pointer-events: none;
  animation: shimmer 9s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 55% { background-position: 120% 0; }
  100% { background-position: -40% 0; }
}

.gem {
  position: absolute;
  top: -13px;
  left: 50%;
  width: 26px;
  height: 26px;
  margin-left: -13px;
  transform: rotate(45deg);
  border-radius: 5px;
  background: linear-gradient(135deg, #c8fff9, var(--turq) 55%, #0f8f8a);
  border: 3px solid var(--gold);
  box-shadow: 0 0 0 2px #2a1a08, 0 0 18px rgba(61, 224, 208, .8);
  z-index: 2;
  animation: gemPulse 4s ease-in-out infinite;
}

@keyframes gemPulse {
  0%, 100% { box-shadow: 0 0 0 2px #2a1a08, 0 0 12px rgba(61,224,208,.55); }
  50%      { box-shadow: 0 0 0 2px #2a1a08, 0 0 24px rgba(61,224,208,.95); }
}

.monument-inner {
  position: relative;
  overflow: hidden;
  border-radius: 18px;
  padding: 28px 12px 18px;
  border: 3px solid var(--ink);
  background:
    /* gold rivets */
    radial-gradient(circle at 13px 13px, var(--gold) 0 3.5px, #5a3a12 4px 5px, transparent 5.5px),
    radial-gradient(circle at calc(100% - 13px) 13px, var(--gold) 0 3.5px, #5a3a12 4px 5px, transparent 5.5px),
    radial-gradient(circle at 13px calc(100% - 13px), var(--gold) 0 3.5px, #5a3a12 4px 5px, transparent 5.5px),
    radial-gradient(circle at calc(100% - 13px) calc(100% - 13px), var(--gold) 0 3.5px, #5a3a12 4px 5px, transparent 5.5px),
    /* ambient magic behind the display */
    radial-gradient(ellipse 80% 55% at 50% 22%, rgba(61, 224, 208, .17), transparent 70%),
    /* stone courses */
    repeating-linear-gradient(0deg, rgba(255, 255, 255, .025) 0 1px, transparent 1px 34px),
    linear-gradient(180deg, #252a3b 0%, #181c29 100%);
}

/* ---------- Days ---------- */
.days-block {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 6px 0 4px;
}

.rune-ring {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(92%, 340px);
  aspect-ratio: 1;
  height: auto;
  margin: 0;
  transform: translate(-50%, -50%);
  opacity: .8;
  pointer-events: none;
  animation: spin 160s linear infinite;
}

@keyframes spin { to { transform: translate(-50%, -50%) rotate(360deg); } }

.elapsed {
  position: relative;
  font-size: .78rem;
  letter-spacing: .3em;
  padding-left: .3em;
  color: var(--turq);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .6), 0 0 10px rgba(61, 224, 208, .45);
}

/* The day counter: dominant element. Container-query sizing keeps ANY number of digits inside the frame. */
.days-wrap {
  position: relative;
  width: 100%;
  margin-top: 6px;
  container-type: inline-size;
  text-align: center;
}

.days-num {
  --digits: 6;
  display: block;
  font-size: 17vw; /* fallback */
  font-size: clamp(2rem, min(21cqw, calc(96cqw / (var(--digits) * .66))), 7.5rem);
  line-height: 1.05;
  font-variant-numeric: tabular-nums lining-nums;
  letter-spacing: .02em;
  color: var(--gold-hi);
  overflow-wrap: anywhere;
  word-break: break-all;
  text-shadow:
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink),
    0 5px 0 #3a2410, 0 8px 10px rgba(0, 0, 0, .6),
    0 0 26px rgba(232, 184, 74, .38);
}

.ribbon {
  position: relative;
  margin-top: 2px;
}
.ribbon span {
  display: inline-block;
  padding: 4px 26px 5px;
  font-size: .95rem;
  letter-spacing: .34em;
  padding-left: calc(26px + .34em);
  color: #fff;
  background: linear-gradient(180deg, #2c4f9a, #1a2f66);
  border: 2px solid var(--gold);
  border-radius: 6px;
  clip-path: polygon(0 0, 100% 0, calc(100% - 9px) 50%, 100% 100%, 0 100%, 9px 50%);
  text-shadow: 0 2px 0 var(--ink);
}

/* ---------- Hours / minutes / seconds ---------- */
.tiles {
  position: relative;
  margin-top: 18px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(2px, 1.5vw, 8px);
}

.tile {
  flex: 1 1 0;
  min-width: 0;
  max-width: 150px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 2px 8px;
  border-radius: 12px;
  border: 2px solid #0a0c14;
  background: linear-gradient(180deg, #0f1322, #1b2236);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, .6), 0 0 0 2px rgba(232, 184, 74, .55);
}

.tile-num {
  font-size: clamp(1.7rem, 9.5vw, 3rem);
  line-height: 1.05;
  font-variant-numeric: tabular-nums lining-nums;
  color: #fff;
  text-shadow:
    -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink),
    0 4px 0 rgba(0, 0, 0, .55);
  will-change: transform;
}

.tile-label {
  margin-top: 3px;
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(.5rem, 2.4vw, .68rem);
  letter-spacing: .14em;
  color: var(--gold);
  white-space: nowrap;
}

.tile-seconds {
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, .6), 0 0 0 2px rgba(61, 224, 208, .75), 0 0 18px rgba(61, 224, 208, .22);
}
.tile-seconds .tile-label { color: var(--turq); }

.colon {
  align-self: center;
  margin-top: -14px;
  font-family: var(--font-display);
  font-weight: 900;
  font-size: clamp(1.2rem, 6vw, 2rem);
  color: var(--gold);
  text-shadow: 0 2px 0 var(--ink);
}

/* upgrade-timer style progress bar (seconds within the current minute) */
.bar {
  position: relative;
  margin: 14px 4px 0;
  height: 10px;
  border-radius: 6px;
  background: #0a0c14;
  border: 2px solid #0a0c14;
  box-shadow: 0 0 0 1px rgba(232, 184, 74, .5);
  overflow: hidden;
}
.bar i {
  position: absolute;
  inset: 0;
  display: block;
  border-radius: 4px;
  background: linear-gradient(90deg, #14a89e, var(--turq) 70%, #c9fffb);
  transform-origin: left center;
  transform: scaleX(0);
  transition: transform 1s linear;
  will-change: transform;
}

.zone { margin-top: 14px; text-align: center; }
.zone-name {
  font-size: .74rem;
  letter-spacing: .22em;
  color: var(--gold-hi);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .6);
}
.zone-since {
  margin-top: 3px;
  font-size: .78rem;
  color: var(--text-dim);
}
.status {
  margin-top: 8px;
  font-size: .8rem;
  color: var(--turq);
}

/* ==========================================================
   MESSAGE PLAQUE
   ========================================================== */
.plaque {
  position: relative;
  padding: 4px;
  border-radius: 18px;
  background: linear-gradient(160deg, var(--gold-hi), var(--gold) 35%, var(--bronze) 70%, var(--gold));
  box-shadow: 0 0 0 2px #2a1a08, 0 12px 26px rgba(0, 0, 0, .5);
}
.plaque-text {
  position: relative;
  padding: 20px 20px 22px;
  border-radius: 14px;
  border: 2px solid var(--ink);
  text-align: center;
  font-family: var(--font-text);
  font-weight: 700;
  font-size: clamp(1.1rem, 5vw, 1.55rem);
  line-height: 1.35;
  color: var(--text);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .6), 0 0 14px rgba(61, 224, 208, .22);
  background:
    radial-gradient(circle at 12px 12px, var(--gold) 0 3px, transparent 3.5px),
    radial-gradient(circle at calc(100% - 12px) 12px, var(--gold) 0 3px, transparent 3.5px),
    radial-gradient(circle at 12px calc(100% - 12px), var(--gold) 0 3px, transparent 3.5px),
    radial-gradient(circle at calc(100% - 12px) calc(100% - 12px), var(--gold) 0 3px, transparent 3.5px),
    linear-gradient(180deg, #2a3042, #1a1e2c);
  overflow-wrap: break-word;
}
/* glowing rune underline */
.plaque-text::after {
  content: "";
  display: block;
  width: 56%;
  height: 3px;
  margin: 12px auto 0;
  border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--turq), transparent);
  box-shadow: 0 0 10px rgba(61, 224, 208, .7);
}

/* ==========================================================
   PLAYER IDENTITY BADGE
   ========================================================== */
.badge {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 14px 12px;
  border-radius: 16px;
  border: 3px solid var(--ink);
  background:
    linear-gradient(180deg, rgba(61, 224, 208, .08), transparent 60%),
    linear-gradient(180deg, #232a40, #161a29);
  box-shadow: 0 0 0 2px var(--gold), 0 12px 26px rgba(0, 0, 0, .5);
}

.shield { width: 40px; height: 47px; display: block; filter: drop-shadow(0 3px 0 rgba(0, 0, 0, .5)); }

.badge-body { min-width: 0; }

.badge-title {
  font-size: .66rem;
  letter-spacing: .24em;
  color: var(--text-dim);
}

.tag {
  margin-top: 2px;
  font-size: clamp(1.15rem, 5.6vw, 1.9rem);
  letter-spacing: .05em;
  color: #fff;
  user-select: all;
  -webkit-user-select: all;
  white-space: nowrap;
  text-shadow:
    -2px -2px 0 var(--ink), 2px -2px 0 var(--ink), -2px 2px 0 var(--ink), 2px 2px 0 var(--ink),
    0 4px 0 rgba(0, 0, 0, .5);
}

.copy {
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
  min-height: 44px;
  padding: 8px 16px;
  font-size: .92rem;
  letter-spacing: .02em;
  color: #fff;
  border: 2px solid var(--ink);
  border-bottom-width: 5px;
  border-radius: 12px;
  background: linear-gradient(180deg, #7be05a 0%, #3ea934 55%, #2f8a2a 100%);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .55);
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, .4);
  transition: transform .12s ease, border-bottom-width .12s ease, background .2s ease;
}
.copy:active { transform: translateY(3px); border-bottom-width: 2px; }
.copy.done { background: linear-gradient(180deg, #8ef0ff 0%, #34c4d6 55%, #1f93a6 100%); }

.copy:focus-visible,
.tag:focus-visible {
  outline: 3px solid var(--turq);
  outline-offset: 3px;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  max-width: calc(100% - 8px);
  padding: 8px 14px;
  border-radius: 10px;
  border: 2px solid var(--gold);
  background: #0f1a35;
  color: var(--gold-hi);
  font-family: var(--font-display);
  font-weight: 800;
  font-size: .82rem;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, .5), 0 0 16px rgba(61, 224, 208, .25);
  opacity: 0;
  transform: translate(-50%, 6px);
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast:empty { display: none; }

/* ---------- Footer / noscript ---------- */
.foot {
  text-align: center;
  font-size: .74rem;
  color: var(--text-dim);
  padding: 2px 10px;
}
.noscript { text-align: center; color: var(--gold-hi); font-size: .9rem; }

/* ==========================================================
   RESPONSIVE
   ========================================================== */
@media (min-width: 560px) {
  .page { padding-top: max(34px, env(safe-area-inset-top)); gap: 20px; }
  .monument-inner { padding: 34px 26px 22px; }
  .tile { padding: 12px 4px 10px; }
}

@media (min-width: 900px) {
  .page { max-width: 720px; }
  .scene-art { opacity: 1; }
}

/* landscape phones: tighten vertical rhythm */
@media (max-height: 520px) and (orientation: landscape) {
  .page { max-width: 760px; gap: 10px; }
  .title { padding-top: 0; }
  h1 { font-size: 1.15rem; }
  .monument-inner { padding: 24px 12px 12px; }
  .tiles { margin-top: 10px; }
  .days-num { font-size: clamp(2rem, min(12cqw, calc(96cqw / (var(--digits) * .66))), 4.5rem); }
  .plaque-text { padding: 12px 16px 14px; font-size: 1.05rem; }
}

/* narrow phones: the tag keeps its own line, the copy button spans the panel below it */
@media (max-width: 430px) {
  .badge { grid-template-columns: auto 1fr; }
  .copy { grid-column: 1 / -1; width: 100%; }
}

/* ==========================================================
   LOW-POWER MODE (set by script.js on budget devices / data saver)
   ========================================================== */
.lite .cloud-b, .lite .cloud-c, .lite .win, .lite .torch { animation: none; }
.lite .cloud-a { animation-duration: 160s; }
.lite .monument { animation: none; }
.lite .monument::after { display: none; }
.lite .rune-ring { animation: none; }
.lite .days-num { text-shadow: -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink), 0 5px 0 #3a2410; }

/* pause all decoration while the tab is hidden */
.is-hidden *, .is-hidden *::before, .is-hidden *::after { animation-play-state: paused !important; }

/* ==========================================================
   REDUCED MOTION
   ========================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .embers { display: none; }
  .monument::after { display: none; }
}
