/* ==========================================================================
   WTHelper — shared foundation
   Tokens, fonts, reset and the components every page uses:
   buttons, panels, toasts, service record modal, consent banner, footer.
   ========================================================================== */

/* ---------- Fonts (self-hosted, SIL OFL / Apache 2.0 — see /fonts) ---------- */
@font-face {
  font-family: "Big Shoulders Stencil";
  src: url("../fonts/bigshoulders-stencil-800.woff2") format("woff2");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Big Shoulders Stencil";
  src: url("../fonts/bigshoulders-stencil-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Saira SC";
  src: url("../fonts/saira-sc-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Saira SC";
  src: url("../fonts/saira-sc-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Saira SC";
  src: url("../fonts/saira-sc-600.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Saira SC";
  src: url("../fonts/saira-sc-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root {
  color-scheme: dark;

  /* Hangar UI */
  --ink: #e6ebee;
  --ink-dim: #a3afb8;
  --ink-faint: #6d7a84;
  --panel: rgba(14, 20, 26, 0.8);
  --panel-solid: #12191f;
  --panel-raised: #1a232b;
  --line: rgba(182, 200, 212, 0.14);
  --line-strong: rgba(182, 200, 212, 0.3);
  --ground: #0b1014;

  /* War Thunder vernacular */
  --battle-1: #b92d1b;
  --battle-2: #ee6a1f;
  --gold: #f2c14e;
  --silver: #c7d0d6;
  --rp: #5aaef0;

  /* Render bugs */
  --missing: #ff2bd6;
  --wire: #42f58a;

  --font-ui: "Saira SC", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --font-display: "Big Shoulders Stencil", "Saira SC", Impact, sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;

  --radius: 2px;
  --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);

  --z-stage: 0;
  --z-hud: 10;
  --z-tooltip: 60;
  --z-consent: 65;
  --z-toast: 70;
  --z-modal: 80;
  --z-loader: 100;

  --gutter: clamp(12px, 2vw, 24px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  font-feature-settings: "tnum" 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img,
svg,
canvas {
  display: block;
  max-width: 100%;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

h1,
h2,
h3,
p,
ul,
ol,
dl,
dd {
  margin: 0;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

::selection {
  background: var(--missing);
  color: #fff;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: var(--z-loader);
  padding: 8px 14px;
  background: var(--gold);
  color: #111;
  font-weight: 600;
  text-decoration: none;
}
.skip-link:focus {
  top: 12px;
}

/* ---------- Icons ---------- */
.icon {
  width: 1em;
  height: 1em;
  flex: none;
  fill: currentColor;
}

/* Missing-texture swatch: the house "error" mark */
.swatch-missing {
  display: inline-block;
  width: 0.72em;
  height: 0.72em;
  flex: none;
  background:
    conic-gradient(var(--missing) 0 25%, #000 0 50%, var(--missing) 0 75%, #000 0) 0 0 / 50% 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.18);
}

/* ---------- Panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.04),
    0 12px 32px rgba(0, 0, 0, 0.35);
  -webkit-backdrop-filter: blur(8px) saturate(1.15);
  backdrop-filter: blur(8px) saturate(1.15);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.045);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  letter-spacing: 0.01em;
  text-decoration: none;
  white-space: nowrap;
  transition:
    background-color 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    transform 0.1s ease;
}
.btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(182, 200, 212, 0.55);
}
.btn:active {
  transform: translateY(1px);
}
.btn .icon {
  font-size: 16px;
}

.btn--accent {
  border-color: rgba(238, 106, 31, 0.7);
  background: linear-gradient(180deg, rgba(238, 106, 31, 0.28), rgba(185, 45, 27, 0.28));
}
.btn--accent:hover {
  border-color: var(--battle-2);
  background: linear-gradient(180deg, rgba(238, 106, 31, 0.45), rgba(185, 45, 27, 0.45));
}

.btn--ghost {
  border-color: transparent;
  background: transparent;
  color: var(--ink-dim);
}
.btn--ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: transparent;
  color: var(--ink);
}

/* The big one. Slanted ends, War Thunder red-orange. */
.btn-battle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 40px;
  border: 0;
  background: linear-gradient(180deg, var(--battle-2) 0%, var(--battle-1) 100%);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow: 0 1px 0 rgba(90, 10, 0, 0.6);
  clip-path: polygon(12px 0, 100% 0, calc(100% - 12px) 100%, 0 100%);
  transition: filter 0.15s ease, transform 0.1s ease;
}
.btn-battle::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, 0.28) 45%, transparent 60%);
  background-size: 260% 100%;
  background-position: 120% 0;
  animation: battle-sheen 5.5s var(--ease-in-out) infinite;
  pointer-events: none;
}
.btn-battle:hover {
  filter: brightness(1.12) saturate(1.05);
}
.btn-battle:active {
  transform: translateY(1px);
}
.btn-battle:focus-visible {
  outline: none;
  filter: brightness(1.2);
  box-shadow: inset 0 0 0 2px var(--gold);
}

@keyframes battle-sheen {
  0%,
  70% {
    background-position: 120% 0;
  }
  100% {
    background-position: -40% 0;
  }
}

/* ---------- Brand ---------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}
.brand__mark {
  width: 30px;
  height: 30px;
}
.brand__word {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 23px;
  line-height: 1;
  letter-spacing: 0.05em;
}

/* ---------- Currency counters ---------- */
.wallet {
  display: flex;
  align-items: center;
  gap: 4px;
}
.coin {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  font-weight: 600;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
button.coin:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line);
}
.coin .icon {
  width: 18px;
  height: 18px;
}
.coin--sl {
  color: var(--silver);
}
.coin--ge {
  color: var(--gold);
}
.coin--rp {
  color: var(--rp);
}

.record-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.03);
  color: var(--ink);
  font-weight: 600;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.record-btn:hover {
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.08);
}
.record-btn .icon {
  width: 18px;
  height: 18px;
  color: var(--gold);
}

/* ---------- Toasts (in-game notifications) ---------- */
.toasts {
  position: fixed;
  top: 64px;
  right: var(--gutter);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  width: min(360px, calc(100vw - 2 * var(--gutter)));
  pointer-events: none;
}
.toast {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: start;
  gap: 12px;
  width: 100%;
  padding: 12px 14px 12px 12px;
  border-left: 3px solid var(--ink-faint);
  pointer-events: auto;
  animation: toast-in 0.35s var(--ease-out) both;
}
.toast.is-leaving {
  animation: toast-out 0.3s ease-in both;
}
.toast__icon {
  width: 22px;
  height: 22px;
  margin-top: 1px;
  color: var(--ink-dim);
}
.toast__title {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.3;
}
.toast__text {
  color: var(--ink-dim);
  font-size: 14px;
  line-height: 1.4;
}
.toast--warn {
  border-left-color: var(--gold);
}
.toast--warn .toast__icon {
  color: var(--gold);
}
.toast--error {
  border-left-color: var(--missing);
}
.toast--error .toast__icon {
  color: var(--missing);
}
.toast--achievement {
  border-left-color: var(--gold);
  background:
    radial-gradient(120% 140% at 0% 0%, rgba(242, 193, 78, 0.2), transparent 60%),
    var(--panel);
}
.toast--achievement .toast__icon {
  width: 34px;
  height: 34px;
  color: var(--gold);
  filter: drop-shadow(0 0 10px rgba(242, 193, 78, 0.45));
}
.toast--achievement .toast__title {
  color: var(--gold);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateX(24px);
  }
}

/* ---------- Modal (service record) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: grid;
  place-items: center;
  padding: var(--gutter);
  background: rgba(4, 7, 9, 0.62);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  animation: fade-in 0.2s ease both;
}
.modal__panel {
  position: relative;
  width: min(640px, 100%);
  max-height: min(720px, calc(100dvh - 2 * var(--gutter)));
  overflow: auto;
  padding: 24px;
  background: var(--panel-solid);
  overscroll-behavior: contain;
}
.modal__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 4px;
}
.modal__title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 40px;
  line-height: 1;
  letter-spacing: 0.01em;
}
.modal__sub {
  margin-bottom: 20px;
  color: var(--ink-dim);
  font-size: 15px;
}
.modal__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  padding: 0;
}

.record-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 8px;
}
.record-item {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
}
.record-item .icon {
  width: 34px;
  height: 34px;
  color: #39434b;
}
.record-item__name {
  font-weight: 600;
  font-size: 15px;
  line-height: 1.3;
}
.record-item__text {
  color: var(--ink-faint);
  font-size: 13px;
  line-height: 1.35;
}
.record-item.is-unlocked {
  border-color: rgba(242, 193, 78, 0.35);
  background: linear-gradient(90deg, rgba(242, 193, 78, 0.1), rgba(242, 193, 78, 0.02));
}
.record-item.is-unlocked .icon {
  color: var(--gold);
}
.record-item.is-unlocked .record-item__text {
  color: var(--ink-dim);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

/* ---------- Consent banner ---------- */
.consent {
  position: fixed;
  right: var(--gutter);
  bottom: calc(var(--gutter) + var(--safe-bottom));
  z-index: var(--z-consent);
  width: min(380px, calc(100vw - 2 * var(--gutter)));
  padding: 16px 16px 14px;
  border-top: 2px solid var(--rp);
  background: var(--panel-solid);
  animation: consent-in 0.45s var(--ease-out) both;
}
.consent__title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 16px;
}
.consent__title .icon {
  width: 18px;
  height: 18px;
  color: var(--rp);
}
.consent__text {
  margin-bottom: 14px;
  color: var(--ink-dim);
  font-size: 14px;
  line-height: 1.45;
}
.consent__text a {
  color: var(--ink);
  text-underline-offset: 2px;
}
.consent__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

@keyframes consent-in {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
}

/* ---------- Secondary page chrome ---------- */
.page-bar {
  position: sticky;
  top: 0;
  z-index: var(--z-hud);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 60px;
  padding: 10px var(--gutter);
  background: linear-gradient(180deg, rgba(8, 12, 15, 0.94), rgba(8, 12, 15, 0.78));
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.page-bar__right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.site-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 18px;
  padding: 18px var(--gutter) calc(18px + var(--safe-bottom));
  color: var(--ink-faint);
  font-size: 13px;
  line-height: 1.4;
}
.site-footer a,
.site-footer button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-dim);
  font-size: 13px;
  text-decoration: underline;
  text-decoration-color: rgba(163, 175, 184, 0.35);
  text-underline-offset: 3px;
}
.site-footer a:hover,
.site-footer button:hover {
  color: var(--ink);
  text-decoration-color: currentColor;
}
.site-footer__note {
  margin-right: auto;
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  .brand__word {
    font-size: 20px;
  }
  .consent {
    left: var(--gutter);
    right: var(--gutter);
    bottom: calc(8px + var(--safe-bottom));
    width: auto;
    padding: 12px 14px;
  }
  .consent__title {
    font-size: 15px;
  }
  .consent__text {
    margin-bottom: 10px;
    font-size: 13px;
    line-height: 1.4;
  }
  .consent .btn {
    min-height: 36px;
  }
  .toasts {
    top: 58px;
  }
  .modal__panel {
    padding: 20px 16px;
  }
  .modal__title {
    font-size: 34px;
  }
}
