/* The achievements page as a trophy hall (views/achievementsPartial.jsx,
   behaviour in public/achievements-hall.js). A game screen, not a themed web
   page: wood frame, stone wall, the same look in light and dark themes. The
   shared badge component (.achievement-badge in achievements.css) is left
   alone — profile, toasts and the unlock celebration still use it. */

.ach-hall {
  --ach-ink: #f6e9cc;
  --ach-ink-dim: #d4c39f;
  --ach-gold: #ffd23a;
  --ach-tile-bg: rgba(18, 14, 10, 0.58);
  --ach-tile-edge: rgba(255, 220, 160, 0.16);
  padding: 22px 12px 40px;
  font-family: "Cinzel", serif;
  color: var(--ach-ink);
}

/* ── Frame: wood border, stone wall inside, iron brackets on top ── */
.ach-hall-frame {
  position: relative;
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 22px 26px;
  border: 12px solid transparent;
  border-radius: 10px;
  /* Stone wall inside, wood planks on the border. */
  background:
    linear-gradient(rgba(14, 12, 10, 0.62), rgba(14, 12, 10, 0.74)) padding-box,
    url("/gui/backgroundwalltexture.webp") center top / 260px auto repeat padding-box,
    url("/gui/wooden_texture.png") center / 300px auto repeat border-box;
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.55),
    inset 0 0 0 2px rgba(0, 0, 0, 0.55),
    inset 0 0 40px rgba(0, 0, 0, 0.6);
}
.ach-hall-bracket {
  position: absolute;
  top: -22px;
  height: 56px;
  width: auto;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.6));
}
.ach-hall-bracket-l { left: -24px; }
.ach-hall-bracket-r { right: -24px; transform: scaleX(-1); }

/* ── Header: ribbon banner, tally, shield row ── */
.ach-hall-head {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.ach-hall-banner {
  width: min(560px, 100%);
  aspect-ratio: 500 / 167;
  display: grid;
  place-items: center;
  margin-top: -6px;
  background: url("/gui/ribbon_light_3.png") center / contain no-repeat;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.55));
}
.ach-hall-banner h2 {
  max-width: 62%;
  margin: 0 0 6%;
  text-align: center;
  line-height: 1.05;
  font-size: clamp(0.9rem, 0.55rem + 1.6vw, 1.55rem);
  color: #3d2000;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.45);
}
.ach-hall-tally {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 18px;
  font-size: 0.92rem;
  color: var(--ach-ink-dim);
}
.ach-hall-tally .fa-trophy,
.ach-hall-tally .fa-coins { color: var(--ach-gold); }

/* One small shield per trophy: iron until won, then its own colour. */
.ach-shield-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px;
  max-width: 640px;
}
.ach-shield {
  width: 18px;
  height: 21px;
  clip-path: polygon(50% 0, 100% 14%, 100% 55%, 50% 100%, 0 55%, 0 14%);
  background: linear-gradient(#4a4e55, #2a2d32);
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.35);
  opacity: 0.85;
}
.ach-shield.is-won {
  opacity: 1;
  filter: drop-shadow(0 0 4px rgba(255, 210, 58, 0.6));
}

/* ── Rewards waiting ── */
.ach-waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 0 auto 16px;
  padding: 8px 16px;
  width: fit-content;
  max-width: 100%;
  border-radius: 12px;
  background: linear-gradient(rgba(70, 48, 10, 0.85), rgba(40, 26, 6, 0.85));
  border: 1px solid rgba(255, 210, 58, 0.55);
  box-shadow: 0 0 18px rgba(255, 210, 58, 0.25);
}
.ach-waiting img {
  width: 46px;
  height: 46px;
  animation: achChestShake 2.4s ease-in-out infinite;
}
.ach-waiting strong { display: block; color: var(--ach-gold); }
.ach-waiting-sub { font-size: 0.85rem; color: var(--ach-ink-dim); }

/* ── Section titles ── */
.ach-section-title,
.ach-shelf-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 10px;
  font-size: 1.02rem;
  color: var(--ach-ink);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.ach-section-title i,
.ach-shelf-title i { color: var(--ach-gold); }
.ach-shelf-count {
  margin-left: auto;
  white-space: nowrap;
  padding: 2px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.45);
  border: 1px solid var(--ach-tile-edge);
  font-size: 0.8rem;
  color: var(--ach-ink-dim);
}

/* ── Closest to unlocking ── */
.ach-closest {
  margin-bottom: 18px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px dashed rgba(255, 210, 58, 0.35);
}
.ach-closest-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

/* ── Shelves ── */
.ach-shelf { margin-top: 18px; }
.ach-shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  gap: 12px;
  padding: 0 6px;
}
/* The plank the trophies stand on. */
.ach-shelf-plank {
  height: 14px;
  margin-top: 8px;
  border-radius: 3px;
  background: url("/gui/wooden_texture.png") center / 220px auto repeat;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.18),
    0 8px 10px rgba(0, 0, 0, 0.5);
}

/* ── Tiles ── */
.ach-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 10px 10px;
  border-radius: 12px;
  background: var(--ach-tile-bg);
  border: 1px solid var(--ach-tile-edge);
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.ach-tile:hover,
.ach-tile:focus-visible {
  transform: translateY(-3px);
  border-color: rgba(255, 210, 58, 0.6);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
  outline: none;
}
.ach-tile-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 100%;
}
.ach-tile-title {
  font-size: 0.86rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--ach-ink);
}
.ach-tile.is-locked .ach-tile-title { color: var(--ach-ink-dim); }
.ach-tile-foot {
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: auto;
}
.ach-tile-coins {
  font-family: system-ui, sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--ach-ink-dim);
}
.ach-tile-coins .fa-coins { color: var(--ach-gold); }
.ach-tile-claimed { color: #7ee07e; font-size: 1.2rem; }
.ach-tile.is-claimable {
  border-color: rgba(255, 210, 58, 0.75);
  animation: achClaimGlow 1.8s ease-in-out infinite;
}

/* Compact tile (Closest to unlocking): badge left, text right. */
.ach-tile-compact {
  flex-direction: row;
  align-items: center;
  text-align: left;
  padding: 8px 10px;
}
.ach-tile-compact .ach-tile-text { align-items: stretch; }

/* "New!" corner ribbon (shown by achievements-hall.js) and the rare gem. */
.ach-new-ribbon {
  position: absolute;
  top: 8px;
  left: -6px;
  z-index: 3;
  padding: 2px 8px;
  border-radius: 3px 3px 3px 0;
  background: #c0392b;
  color: #fff;
  font: 800 0.66rem/1.4 system-ui, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.4);
}
.ach-new-ribbon::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: -5px;
  border: 3px solid transparent;
  border-top-color: #7d1f15;
  border-right-color: #7d1f15;
}
.ach-new-ribbon[hidden] { display: none; }
.ach-rare-gem { color: #8fd8ff; filter: drop-shadow(0 0 4px rgba(143, 216, 255, 0.8)); }
.ach-tile-gem {
  position: absolute;
  top: 8px;
  right: 9px;
  font-size: 0.85rem;
}

/* ── Badge: rarity rim + colour face, hexagonal ── */
.ach-badge {
  --hex: polygon(50% 0, 96% 25%, 96% 75%, 50% 100%, 4% 75%, 4% 25%);
  position: relative;
  flex: 0 0 auto;
  width: 74px;
  height: 82px;
  display: inline-block;
}
.ach-badge-sm { width: 48px; height: 54px; }
.ach-badge-xl { width: 104px; height: 116px; }
.ach-badge-rim,
.ach-badge-face {
  position: absolute;
  clip-path: var(--hex);
}
.ach-badge-rim { inset: 0; }
.ach-badge-face {
  inset: 7%;
  display: grid;
  place-items: center;
  box-shadow: inset 0 -6px 10px rgba(0, 0, 0, 0.3);
}
.ach-badge-face i {
  font-size: 1.9em;
  color: #fff;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.45));
}
.ach-badge-sm .ach-badge-face i { font-size: 1.25em; }
.ach-badge-xl .ach-badge-face i { font-size: 2.6em; }

/* Rarity = rim material. */
.ach-rarity-common .ach-badge-rim,
.ach-badge.ach-rarity-common .ach-badge-rim {
  background: url("/gui/wooden_texture.png") center / 120px auto, #7a4f2a;
}
.ach-badge.ach-rarity-uncommon .ach-badge-rim {
  background: linear-gradient(145deg, #f0b27a 0%, #b8733a 45%, #7a4318 100%);
}
.ach-badge.ach-rarity-rare .ach-badge-rim {
  background: linear-gradient(145deg, #ffffff 0%, #c4ccd6 45%, #7e8896 100%);
}
.ach-badge.ach-rarity-epic .ach-badge-rim {
  background: linear-gradient(145deg, #fff3b0 0%, #f0c24a 45%, #a9761c 100%);
}
.ach-badge.ach-rarity-legendary .ach-badge-rim {
  background: linear-gradient(115deg, #a9761c 0%, #f0c24a 30%, #fffbe0 45%, #f0c24a 60%, #a9761c 100%);
  background-size: 250% 100%;
  animation: achLegendShimmer 2.8s linear infinite;
}
.ach-badge.ach-rarity-legendary:not(.is-locked) {
  filter: drop-shadow(0 0 8px rgba(255, 210, 58, 0.7));
}

/* Achievement colour = face (same palette as the shared badge). */
.ach-color-yellow { background: linear-gradient(to bottom right, #ffeb3b, #fbc02d); }
.ach-color-orange { background: linear-gradient(to bottom right, #ffc107, #f57c00); }
.ach-color-pink { background: linear-gradient(to bottom right, #f48fb1, #d81b60); }
.ach-color-red { background: linear-gradient(to bottom right, #f4511e, #b71c1c); }
.ach-color-purple { background: linear-gradient(to bottom right, #ab47bc, #4527a0); }
.ach-color-teal { background: linear-gradient(to bottom right, #4db6ac, #00796b); }
.ach-color-blue { background: linear-gradient(to bottom right, #4fc3f7, #2196f3); }
.ach-color-blue-dark { background: linear-gradient(to bottom right, #1976d2, #283593); }
.ach-color-green { background: linear-gradient(to bottom right, #cddc39, #8bc34a); }
.ach-color-green-dark { background: linear-gradient(to bottom right, #4caf50, #1b5e20); }
.ach-color-silver { background: linear-gradient(to bottom right, #e0e0e0, #9e9e9e); }
.ach-color-gold { background: linear-gradient(to bottom right, #e6ce6a, #b7892b); }
.ach-badge[class*="ach-color-"] { background: none; }
.ach-badge.ach-color-yellow .ach-badge-face { background: linear-gradient(to bottom right, #ffeb3b, #fbc02d); }
.ach-badge.ach-color-orange .ach-badge-face { background: linear-gradient(to bottom right, #ffc107, #f57c00); }
.ach-badge.ach-color-pink .ach-badge-face { background: linear-gradient(to bottom right, #f48fb1, #d81b60); }
.ach-badge.ach-color-red .ach-badge-face { background: linear-gradient(to bottom right, #f4511e, #b71c1c); }
.ach-badge.ach-color-purple .ach-badge-face { background: linear-gradient(to bottom right, #ab47bc, #4527a0); }
.ach-badge.ach-color-teal .ach-badge-face { background: linear-gradient(to bottom right, #4db6ac, #00796b); }
.ach-badge.ach-color-blue .ach-badge-face { background: linear-gradient(to bottom right, #4fc3f7, #2196f3); }
.ach-badge.ach-color-blue-dark .ach-badge-face { background: linear-gradient(to bottom right, #1976d2, #283593); }
.ach-badge.ach-color-green .ach-badge-face { background: linear-gradient(to bottom right, #cddc39, #8bc34a); }
.ach-badge.ach-color-green-dark .ach-badge-face { background: linear-gradient(to bottom right, #4caf50, #1b5e20); }
.ach-badge.ach-color-silver .ach-badge-face { background: linear-gradient(to bottom right, #e0e0e0, #9e9e9e); }
.ach-badge.ach-color-gold .ach-badge-face { background: linear-gradient(to bottom right, #e6ce6a, #b7892b); }

/* Locked: dark iron with a padlock — still fully readable, never faded. */
.ach-badge.is-locked .ach-badge-face {
  background: linear-gradient(160deg, #565b63 0%, #33373d 55%, #23262a 100%);
}
.ach-badge.is-locked .ach-badge-face i {
  color: #9aa1ab;
  filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.6));
}
.ach-badge.is-locked .ach-badge-rim {
  filter: saturate(0.55) brightness(0.8);
}
.ach-badge.is-locked.ach-rarity-legendary .ach-badge-rim { animation: none; }
.ach-badge-lock {
  position: absolute;
  right: 0;
  bottom: 2px;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #1d1f23;
  border: 2px solid #b8933c;
  color: var(--ach-gold, #ffd23a);
  font-size: 11px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}
.ach-badge-sm .ach-badge-lock { width: 18px; height: 18px; font-size: 8px; border-width: 1px; }

/* ── Progress bar ── */
.ach-progress {
  display: flex;
  flex-direction: column;
  gap: 3px;
  width: 100%;
}
.ach-progress-track {
  height: 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.12);
  overflow: hidden;
}
.ach-progress-fill {
  display: block;
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, #b8860b, #ffd23a);
  box-shadow: 0 0 6px rgba(255, 210, 58, 0.5);
}
.ach-progress-text {
  font: 600 0.72rem/1.2 system-ui, sans-serif;
  color: var(--ach-ink-dim);
}

/* ── Claim chest ── */
.ach-chest {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px 2px 4px;
  border: 1px solid rgba(255, 210, 58, 0.8);
  border-radius: 999px;
  background: linear-gradient(#5a3a10, #2f1e06);
  color: var(--ach-gold, #ffd23a);
  font: 800 0.82rem/1 system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(255, 210, 58, 0.45);
}
.ach-chest img {
  width: 30px;
  height: 30px;
  animation: achChestShake 1.6s ease-in-out infinite;
}
.ach-chest-big {
  padding: 6px 18px 6px 8px;
  font-size: 1rem;
}
.ach-chest-big img { width: 54px; height: 54px; }
.ach-chest:hover img,
.ach-chest:focus-visible img { animation-duration: 0.6s; }
.ach-chest.is-opening img { animation: achChestPop 0.55s ease-out forwards; }
.ach-chest.is-opening { pointer-events: none; }

/* A coin flying from the chest to the navbar balance. */
.ach-flying-coin {
  position: fixed;
  z-index: 100001;
  width: 22px;
  height: 22px;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6b0 0%, #ffd23a 45%, #b8860b 100%);
  box-shadow: 0 0 6px rgba(255, 210, 58, 0.8), inset 0 -2px 0 rgba(0, 0, 0, 0.25);
  pointer-events: none;
}

/* ── Detail card (modal) ── */
.ach-detail-modal {
  position: fixed;
  inset: 0;
  z-index: 10050;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.6);
  animation: achFadeIn 0.18s ease-out;
}
.ach-detail-card {
  position: relative;
  width: min(420px, 100%);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 20px 20px 18px;
  border: 10px solid transparent;
  border-radius: 10px;
  background:
    linear-gradient(rgba(14, 12, 10, 0.7), rgba(14, 12, 10, 0.82)) padding-box,
    url("/gui/backgroundwalltexture.webp") center / 220px auto repeat padding-box,
    url("/gui/wooden_texture.png") center / 300px auto repeat border-box;
  color: #f6e9cc;
  font-family: "Cinzel", serif;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.7);
  animation: achCardIn 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
.ach-detail-close {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.45);
  color: #f6e9cc;
  font-size: 1.1rem;
  cursor: pointer;
}
.ach-detail { display: flex; flex-direction: column; gap: 12px; }
.ach-detail-head { display: flex; align-items: center; gap: 16px; }
.ach-detail-titles { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.ach-detail-title { margin: 0; font-size: 1.3rem; color: #fff3d6; }
.ach-detail-desc { margin: 0; font: 500 0.95rem/1.35 system-ui, sans-serif; color: #e8dcc0; }
.ach-detail-line { margin: 0; font: 500 0.9rem/1.4 system-ui, sans-serif; color: #e8dcc0; }
.ach-detail-line i { color: #ffd23a; width: 1.2em; text-align: center; }
.ach-detail-won { color: #bff0bf; }
.ach-detail-won i { color: #7ee07e; }
.ach-detail-tip { padding: 8px 10px; border-radius: 8px; background: rgba(255, 210, 58, 0.1); }
.ach-detail-reward {
  display: flex;
  justify-content: center;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 220, 160, 0.16);
  font: 700 1rem/1.3 system-ui, sans-serif;
}
.ach-detail-coins .fa-coins { color: #ffd23a; }
.ach-detail-claimed { color: #7ee07e; }
.ach-detail .ach-progress-text { font-size: 0.85rem; }
.ach-rarity-label {
  font: 800 0.72rem/1 system-ui, sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
.ach-rarity-text-common { color: #c9a27a; }
.ach-rarity-text-uncommon { color: #f0a868; }
.ach-rarity-text-rare { color: #d9e2ec; }
.ach-rarity-text-epic { color: #f5cf5a; }
.ach-rarity-text-legendary { color: #ffe27a; text-shadow: 0 0 8px rgba(255, 210, 58, 0.7); }

/* ── Phones ── */
@media (max-width: 600px) {
  .ach-hall { padding: 14px 6px 30px; }
  .ach-hall-frame { padding: 14px 10px 20px; border-width: 9px; }
  .ach-hall-bracket { height: 42px; top: -16px; }
  .ach-hall-bracket-l { left: -16px; }
  .ach-hall-bracket-r { right: -16px; }
  .ach-shelf-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 0;
  }
  .ach-closest-row { grid-template-columns: 1fr; }
  .ach-shield { width: 14px; height: 17px; }
}

/* ── Motion ── */
@keyframes achChestShake {
  0%, 70%, 100% { transform: rotate(0); }
  74% { transform: rotate(-9deg); }
  80% { transform: rotate(8deg); }
  86% { transform: rotate(-6deg); }
  92% { transform: rotate(4deg); }
}
@keyframes achChestPop {
  0% { transform: scale(1); }
  35% { transform: scale(1.35) rotate(-6deg); }
  100% { transform: scale(0.6); opacity: 0; }
}
@keyframes achClaimGlow {
  0%, 100% { box-shadow: 0 0 0 rgba(255, 210, 58, 0); }
  50% { box-shadow: 0 0 16px rgba(255, 210, 58, 0.45); }
}
@keyframes achLegendShimmer {
  from { background-position: 100% 0; }
  to { background-position: -150% 0; }
}
@keyframes achFadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes achCardIn {
  from { opacity: 0; transform: translateY(14px) scale(0.96); }
  to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
  .ach-waiting img,
  .ach-chest img,
  .ach-tile.is-claimable,
  .ach-badge.ach-rarity-legendary .ach-badge-rim,
  .ach-detail-modal,
  .ach-detail-card {
    animation: none;
  }
}

/* Shields take their colour only once won (the colour classes above would
   otherwise paint locked ones too). */
.ach-shield:not(.is-won) {
  background: linear-gradient(#7a808a, #4a4f57);
  opacity: 0.75;
}
