/* profile — page styles. Tokens and shared components only (see docs/DESIGN.md). */
@layer pages {
  /* ── Cover: the profile's header (h1, one line about the citizen, the page's own actions) ── */
  .cover { display: flex; align-items: center; justify-content: flex-start; flex-wrap: nowrap; gap: var(--sp-6); padding: var(--sp-6); overflow: hidden; isolation: isolate; }
  /* A survey map (assets/backdrop.svg) drawn in the text colour, fading in from the right. */
  .cover-wash { position: absolute; inset: 0; z-index: -1; pointer-events: none; border-radius: inherit; background: var(--text); opacity: .3;
    -webkit-mask: url("../../assets/backdrop.svg") 100% 40% / 980px auto no-repeat, linear-gradient(90deg, transparent 25%, black 80%);
    -webkit-mask-composite: source-in;
    mask: url("../../assets/backdrop.svg") 100% 40% / 980px auto no-repeat, linear-gradient(90deg, transparent 25%, black 80%);
    mask-composite: intersect; }
  [data-theme="light"] .cover-wash { opacity: .24; }

  /* The picture, or initials on a disc tinted with one of the map tones (see Portrait). */
  .portrait { position: relative; flex: none; display: grid; place-items: center; width: 104px; height: 104px; overflow: hidden;
    border-radius: var(--r-pill); background: var(--surface-raised);
    box-shadow: 0 0 0 4px var(--surface-raised), 0 0 0 5px var(--border), var(--shadow-2); }
  .portrait img { width: 100%; height: 100%; object-fit: cover; }
  .portrait.fallback { background: linear-gradient(150deg, color-mix(in srgb, var(--tone) 52%, var(--surface-raised)), color-mix(in srgb, var(--tone) 18%, var(--surface-raised))); }
  .portrait .initials { font: var(--fw-bold) var(--fs-display) / 1 var(--font-display); letter-spacing: var(--ls-display);
    color: color-mix(in srgb, var(--tone) 30%, var(--text)); }
  .portrait.skeleton { box-shadow: none; }
  /* The same round picture on the newspaper, party and military unit cards, smaller. */
  .portrait.affil { width: 64px; height: 64px; box-shadow: 0 0 0 3px var(--surface-raised), 0 0 0 4px var(--border), var(--shadow-1); }
  .portrait.affil .initials { font-size: var(--fs-h2); }
  .fact .portrait.affil img { width: 100%; height: 100%; object-fit: cover; }

  .cover .who { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
  .cover h1 { overflow-wrap: anywhere; }
  .cover .sub { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-5); margin: 0; color: var(--text-2); font-size: var(--fs-md); font-weight: var(--fw-semibold); }
  .cover .sub-item { display: inline-flex; align-items: center; gap: var(--sp-2); }
  .cover .insignia { width: 22px; height: 22px; object-fit: contain; }
  .cover .xp { display: flex; flex-direction: column; gap: 6px; max-width: 440px; margin-top: var(--sp-2); }
  .cover .xp .split { align-items: baseline; }
  .cover-actions { flex: none; display: flex; gap: var(--sp-2); }

  /* ── Overview ── */
  .profile-tab { display: flex; flex-direction: column; gap: var(--gap); }
  .profile-tab.hidden { display: none; }
  .profile-skeleton-body { height: 120px; margin-top: var(--sp-4); }

  /* Resources: gold, money, prestige and energy in one row. */
  .vitals .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .vitals .stat-energy > div { flex: 1; }
  .vitals .stat-energy .meter { margin-top: var(--sp-1); }

  /* Bio: reading text; the empty state fills the card next to the military attributes. */
  .bio-card { display: flex; flex-direction: column; }
  .bio-card .empty { flex: 1; justify-content: center; padding: var(--sp-4); }
  .bio-card .bio { white-space: pre-wrap; overflow-wrap: anywhere; }
  /* A bio that is ASCII art keeps its columns: monospace, no wrapping, scroll if too wide. */
  .bio-card .bio.ascii { font-family: var(--font-mono); font-size: var(--fs-sm); line-height: var(--lh-snug); white-space: pre; overflow-x: auto;
    padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); background: var(--surface-sunken); border: 1px solid var(--border-subtle); color: var(--text-2); }

  /* Military attributes: two tiles with their art. */
  .military { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-3); }
  .attr { padding: var(--sp-5) var(--sp-4); }
  .attr img { width: 56px; height: 56px; filter: drop-shadow(0 4px 8px color-mix(in srgb, var(--ink) 30%, transparent)); }
  .attr .meter { width: 100%; max-width: 200px; margin-top: var(--sp-1); }
  .attr .pts { font-size: var(--fs-xs); color: var(--text-3); }

  /* ── Achievements: the medal art on a tinted tile, gold-edged once earned ── */
  .achievements { display: grid; grid-template-columns: repeat(auto-fill, minmax(208px, 1fr)); gap: var(--sp-3); }
  .achievements .medal { display: flex; flex-direction: column; align-items: center; gap: var(--sp-1); min-width: 0; padding: var(--sp-6) var(--sp-4) var(--sp-4); text-align: center;
    border-radius: var(--r-md); border: 1px solid var(--border-subtle);
    background: radial-gradient(ellipse 70% 46% at 50% 22%, color-mix(in srgb, var(--text) 5%, transparent), transparent 72%), var(--surface-2);
    transition: transform var(--t-base) var(--ease), border-color var(--t-base), box-shadow var(--t-base); }
  .achievements .medal > img { width: 80px; height: 92px; object-fit: contain; margin-bottom: var(--sp-3); filter: drop-shadow(0 8px 10px color-mix(in srgb, var(--ink) 45%, transparent)); }
  [data-theme="light"] .achievements .medal > img { filter: drop-shadow(0 6px 8px color-mix(in srgb, var(--ink) 22%, transparent)); }
  .achievements .medal p { color: var(--text-2); font-size: var(--fs-sm); line-height: 1.45; }
  /* Your own earned medals open the achievement (with Share on Facebook). */
  .achievements .medal.open { cursor: pointer; transition: transform var(--t-base) var(--ease), border-color var(--t-fast); }
  .achievements .medal.open:hover { transform: translateY(-2px); border-color: var(--brand-border); }
  .achievements .medal.open:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
  .achievements .medal-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--sp-2); margin-top: auto; padding-top: var(--sp-3); }
  .achievements .medal.earned { border-color: color-mix(in srgb, var(--gold) 45%, transparent); box-shadow: var(--shadow-1);
    background: radial-gradient(ellipse 80% 55% at 50% 18%, var(--gold-soft), transparent 75%), var(--surface-2); }
  .achievements .medal.earned:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
  .achievements .medal.earned > img { filter: drop-shadow(0 8px 16px color-mix(in srgb, var(--gold) 40%, transparent)); }

  /* ── Narrow screens ── */
  @media (max-width: 760px) {
    .vitals .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  }
  @media (max-width: 640px) {
    .cover { flex-wrap: wrap; align-items: flex-start; gap: var(--sp-4); padding: var(--sp-5); }
    .portrait { width: 72px; height: 72px; }
    .portrait .initials { font-size: var(--fs-h1); }
    .cover .xp { max-width: none; }
    .cover-actions { width: 100%; }
    .cover-actions .btn { flex: 1; }
  }
  @media (max-width: 560px) {
    /* Five facts in two columns: the last one takes the whole row. */
    .profile-tab .facts-grid > .fact:last-child:nth-child(odd) { grid-column: 1 / -1; }
    .ach-card .card-head { flex-wrap: wrap; }
    /* Medals become compact rows: the art on the left, the text and rewards beside it. */
    .achievements { grid-template-columns: minmax(0, 1fr); gap: var(--sp-2); }
    .achievements .medal { display: grid; grid-template-columns: 48px minmax(0, 1fr); align-items: start; column-gap: var(--sp-3); row-gap: 2px;
      padding: var(--sp-4); text-align: left; }
    .achievements .medal > img { grid-row: 1 / span 3; width: 48px; height: 56px; margin: 0; }
    .achievements .medal > :not(img) { grid-column: 2; }
    .achievements .medal-foot { justify-content: flex-start; margin-top: 0; padding-top: var(--sp-2); }
  }
  @media (max-width: 480px) {
    .vitals .stat { flex-direction: column; align-items: flex-start; gap: var(--sp-2); padding: var(--sp-3); }
    .vitals .stat > div { width: 100%; }
  }

  /* ── Your storage, shown in the profile's Storage tab ── */
  .storage-page.embedded { display: flex; flex-direction: column; gap: var(--gap); }
  .storage-page.embedded .page-head h1 { font-size: var(--fs-h2); }
  /* The donation cards (donate.css) stack their parts like the other cards of the profile. */
  .profile-page :is(.donate-card, .pending-donations) { display: flex; flex-direction: column; gap: var(--sp-3); }

  /* A citizen's or party's name as a link in tables and lists, on every page. */
  a.who { color: inherit; text-decoration: none; }
  a.who:hover { color: var(--brand-text); text-decoration: underline; text-underline-offset: 3px; }

  /* Military attributes: the rank progress under its fact tile. */
  .attr .meter { width: 100%; height: 8px; margin-top: var(--sp-1); }
  .attr .pts { text-transform: none; letter-spacing: 0; }

  /* Online / offline next to the name: a green or grey dot and the word. */
  .presence { display: inline-flex; align-items: center; gap: 6px; font-weight: var(--fw-semibold); }
  .presence .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
  .presence.online { color: var(--green-text); }
  .presence.online .dot { background: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
  .presence.offline { color: var(--text-3); }
  .presence.offline .dot { background: var(--text-disabled); }
}
