/* Kirkor Strike — app.css
 *
 * Single stylesheet, organized with @layer so specificity stays predictable as
 * the file grows. Design tokens are custom properties; change the brand by
 * editing the tokens layer, not by hunting hex codes through the file.
 */

@layer tokens, reset, base, layout, components, utilities;

@layer tokens {
  :root {
    --color-bg:        #f6f7f9;
    --color-surface:   #ffffff;
    --color-border:    #dfe3e8;
    --color-text:      #1c2430;
    --color-muted:     #5b6675;
    --color-primary:   #e0621b;
    --color-secondary: #00466b;
    --color-danger:    #b3261e;
    --color-warning:   #a25f00;
    --color-success:   #1a7f47;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-6: 1.5rem;
    --space-8: 2rem;

    --radius:   8px;
    --shadow:   0 1px 2px rgb(0 0 0 / 6%), 0 4px 12px rgb(0 0 0 / 4%);
    --maxw:     72rem;

    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --fs-sm:  0.875rem;
    --fs-base: 1rem;
    --fs-lg:  1.25rem;
    --fs-xl:  1.75rem;
  }
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, h4, p, figure, blockquote, dl, dd { margin: 0; }
  img, svg { display: block; max-width: 100%; }
  button, input, select, textarea { font: inherit; color: inherit; }
}

@layer base {
  body {
    font-family: var(--font);
    font-size: var(--fs-base);
    line-height: 1.55;
    color: var(--color-text);
    background: var(--color-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
  }

  a { color: var(--color-primary); }
  a:hover { text-decoration: none; }

  h1 { font-size: var(--fs-xl); margin-block-end: var(--space-4); }
  h2 { font-size: var(--fs-lg); margin-block-end: var(--space-3); }
  p  { margin-block-end: var(--space-4); }

  :focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
  }
}

@layer layout {
  .main {
    flex: 1;
    width: 100%;
    max-width: var(--maxw);
    margin-inline: auto;
    padding: var(--space-8) var(--space-4);
  }

  .topbar {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface);
    border-block-end: 1px solid var(--color-border);
  }

  .topbar__brand { font-weight: 700; color: var(--color-secondary); text-decoration: none; }
  .topbar__nav   { display: flex; gap: var(--space-4); }
  .topbar__user  { margin-inline-start: auto; display: flex; align-items: center; gap: var(--space-3); }

  .footer {
    padding: var(--space-6) var(--space-4);
    color: var(--color-muted);
    font-size: var(--fs-sm);
    text-align: center;
  }

  .skip-link {
    position: absolute;
    inset-inline-start: -9999px;
  }
  .skip-link:focus {
    inset-inline-start: var(--space-4);
    inset-block-start: var(--space-4);
    z-index: 10;
    background: var(--color-surface);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius);
  }
}

@layer components {
  .card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: var(--space-6);
  }
  .card--narrow   { max-width: 26rem; margin-inline: auto; }
  .card--centered { max-width: 34rem; margin-inline: auto; text-align: center; }

  .btn {
    display: inline-block;
    padding: var(--space-2) var(--space-4);
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--color-border);
    color: var(--color-text);
    text-decoration: none;
    cursor: pointer;
  }
  .btn--primary { background: var(--color-primary); color: #fff; }
  .btn--ghost   { background: transparent; border-color: var(--color-border); }
  .btn:hover    { filter: brightness(0.95); }

  label {
    display: block;
    margin-block: var(--space-4) var(--space-1);
    font-size: var(--fs-sm);
    color: var(--color-muted);
  }

  input[type="text"], input[type="email"], input[type="password"], select, textarea {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
  }

  /* Password field with its show/hide toggle. The input keeps room on the
     right so typed text never runs under the button. */
  .password-field {
    position: relative;
  }

  .password-field input {
    padding-right: 2.75rem;
  }

  .password-field__toggle {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: inline-flex;
    align-items: center;
    padding: 0 var(--space-3);
    border: 0;
    background: transparent;
    color: var(--color-muted, #666);
    cursor: pointer;
  }

  .password-field__toggle:hover,
  .password-field__toggle:focus-visible {
    color: var(--color-text, #222);
  }

  .password-field__toggle[hidden] {
    display: none;
  }

  form .btn { margin-block-start: var(--space-6); }

  .alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
  }
  .alert--error   { background: #fdeceb; border-color: #f2c3bf; color: var(--color-danger); }
  .alert--success { background: #e9f6ee; border-color: #bfe0cc; color: var(--color-success); }

  .error-code {
    font-size: 3rem;
    font-weight: 800;
    color: var(--color-primary);
    margin-block-end: var(--space-2);
  }

  /* Fixed environment badge. Rendered in local and staging only, never in
     production, so a tab or a screenshot in a bug report identifies itself.
     Non-interactive and aria-hidden, so it cannot get in the way of the page. */
  .env-badge {
    position: fixed;
    inset-block-end: 1rem;
    inset-inline-start: 1rem;
    z-index: 2000;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.5rem 0.75rem;
    border-radius: 999px;
    background: var(--env-badge-color, var(--color-secondary));
    color: #fff;
    font: 700 0.72rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    box-shadow: 0 8px 20px -6px rgb(0 0 0 / 55%);
  }
  .env-badge__dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #fff;
    opacity: 0.85;
  }

  @media print {
    .env-badge { display: none; }
  }

  .icon { display: inline-block; vertical-align: -0.15em; }
}

@layer utilities {
  .text-muted  { color: var(--color-muted); }
  .text-center { text-align: center; }
  .u-mt-4 { margin-block-start: var(--space-4); }
  .u-mb-4 { margin-block-end: var(--space-4); }
  .visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* Game page. The canvas is drawn at screen density and Phaser's FIT mode
 * scales it to fill #game (see main.js), so #game must be exactly the
 * visible screen, no taller.
 *
 * On a phone, vh is the height with the browser bar hidden. The base body
 * rule (min-height: 100vh, .main flex: 1) made #game that tall while the
 * bar showed. Upright the picture is width-bound and the extra height was
 * blank; on its side it is height-bound, and the centered picture lost its
 * top and bottom, HUD included. So the body is pinned to dvh here and
 * .main does not flex. main.js also sizes #game from visualViewport after
 * a rotation, for browsers without dvh. */
@layer tokens {
  :root {
    --game-bg:     #050805;
    --game-bg-hi:  #142010;
    --game-text:   #f2f2f2;
    --game-accent: #e0621b;
  }
}

@layer components {
  body.game-page {
    min-height: 0;
    height: 100vh;
    height: 100dvh;
    background: radial-gradient(ellipse at 50% 40%, var(--game-bg-hi), var(--game-bg) 70%) fixed, var(--game-bg);
    color: var(--game-text);
    overflow: hidden;
    /* No double-tap zoom, pull-to-refresh or text selection mid-game. */
    touch-action: none;
    overscroll-behavior: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }

  .game-page .main {
    flex: none;
    max-width: none;
    padding: 0;
    height: 100vh;
    height: 100dvh;
  }

  #game {
    width: 100%;
    height: 100%;
  }

  #game canvas {
    display: block;
    box-shadow: 0 0 60px rgb(0 0 0 / 70%);
  }

  .game-toast {
    position: fixed;
    inset-block-end: 1.5rem;
    inset-inline-start: 50%;
    transform: translateX(-50%);
    padding: 0.5rem 1rem;
    border: 2px solid var(--game-accent);
    background: rgb(0 0 0 / 80%);
    color: var(--game-text);
    font: 700 0.875rem/1.2 ui-monospace, Consolas, monospace;
    letter-spacing: 0.08em;
    pointer-events: none;
  }

  .game-noscript {
    color: var(--game-text);
    text-align: center;
  }

  /* Touch controls (systems/touch.js). Shown only in play and only while
   * touch is the input in use. The layer passes touches through; the
   * window listeners read them. Stick size must match R in touch.js. */
  .touch-ui {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 20;
    pointer-events: none;
    font: 700 0.6875rem/1 system-ui, sans-serif;
    letter-spacing: 0.08em;
    color: rgb(255 255 255 / 55%);
  }

  body.touch-play .touch-ui {
    display: block;
  }

  .tc-stick {
    position: absolute;
    inset-block-start: 0;
    inset-inline-start: 0;
    width: 112px;
    height: 112px;
    border: 2px solid rgb(255 255 255 / 22%);
    border-radius: 50%;
    background: rgb(0 0 0 / 18%);
    opacity: 0.7;
    will-change: transform;
  }

  .tc-stick.is-active {
    border-color: rgb(255 255 255 / 45%);
    opacity: 1;
  }

  .tc-knob {
    position: absolute;
    inset: 28px;
    border-radius: 50%;
    background: rgb(255 255 255 / 35%);
    will-change: transform;
  }

  .tc-aim.is-active .tc-knob {
    background: var(--game-accent);
  }

  .tc-label {
    position: absolute;
    inset-block-start: calc(100% + 8px);
    inset-inline: -20px;
    text-align: center;
  }

  .is-active .tc-label {
    display: none;
  }

  .tc-btn {
    position: absolute;
    display: grid;
    place-items: center;
    border: 2px solid rgb(255 255 255 / 30%);
    border-radius: 50%;
    background: rgb(0 0 0 / 35%);
    color: rgb(255 255 255 / 80%);
    pointer-events: auto;
    touch-action: none;
  }

  .tc-btn svg {
    width: 55%;
    height: 55%;
    fill: currentColor;
  }

  .tc-btn.is-down {
    background: var(--game-accent);
    color: #fff;
  }

  /* Above the resting aim stick: 96px in from the right, 120px up. */
  .tc-grenade {
    inset-inline-end: 62px;
    inset-block-end: 200px;
    width: 68px;
    height: 68px;
  }

  .tc-pause,
  .tc-sound {
    inset-block-start: max(12px, env(safe-area-inset-top));
    inset-inline-end: max(12px, env(safe-area-inset-right));
    width: 44px;
    height: 44px;
  }

  .tc-sound {
    inset-inline-end: calc(max(12px, env(safe-area-inset-right)) + 56px);
  }

  .tc-off,
  .is-muted .tc-on {
    display: none;
  }

  .is-muted .tc-off {
    display: inline;
  }
}

/* Share dialog (partials/share-modal.php). Over the game, in its colors.
 * The game page turns off touch scrolling and text selection; the dialog
 * turns them back on, so the link can be selected and the card scrolled on
 * a short landscape phone. */
@layer components {
  .share[hidden] { display: none; }

  .share {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 1rem;
    background: rgb(0 0 0 / 70%);
    touch-action: auto;
    overflow-y: auto;
  }

  .share__card {
    position: relative;
    width: min(22rem, 100%);
    padding: 1.5rem 1.25rem 1.25rem;
    border: 2px solid var(--game-accent);
    border-radius: 12px;
    background: #0e160c;
    color: var(--game-text);
    text-align: center;
    user-select: text;
    -webkit-user-select: text;
    outline: none;
  }

  .share__close {
    position: absolute;
    inset-block-start: 0.25rem;
    inset-inline-end: 0.5rem;
    width: 2.75rem;
    height: 2.75rem;
    border: 0;
    background: transparent;
    color: #a8b0a0;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
  }
  .share__close:hover,
  .share__close:focus-visible { color: var(--game-text); }

  .share__title {
    margin: 0 0 0.25rem;
    color: var(--game-accent);
    font-size: 1.375rem;
    letter-spacing: 0.04em;
  }

  .share__lede {
    margin: 0 0 1rem;
    color: #a8b0a0;
    font-size: 0.9375rem;
  }

  .share__qr {
    display: block;
    width: min(14rem, 70vw);
    height: auto;
    aspect-ratio: 1;
    margin: 0 auto 1rem;
    border-radius: 8px;
    background: #fff;
    padding: 0.5rem;
    /* Hard square edges when scaled, so a phone camera reads it reliably. */
    image-rendering: pixelated;
  }
  .share__qr--empty {
    display: grid;
    place-items: center;
    background: transparent;
    border: 2px dashed #4a5a42;
    color: #a8b0a0;
    font-size: 0.875rem;
  }

  .share__label {
    margin: 0 0 0.25rem;
    color: #a8b0a0;
    font-size: 0.8125rem;
    text-align: start;
  }

  .share__row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
  }

  .share__url {
    flex: 1;
    min-width: 0;
    padding: 0.625rem 0.75rem;
    border-radius: 6px;
    background: rgb(255 255 255 / 8%);
    font: 0.875rem/1.3 ui-monospace, Consolas, monospace;
    text-align: start;
    /* One line: a break inside ".com" reads as two addresses. The full
       address still copies and selects. */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: all;
    -webkit-user-select: all;
  }

  .share__btn {
    min-height: 2.75rem;
    padding: 0.5rem 1rem;
    border: 1px solid rgb(255 255 255 / 30%);
    border-radius: 6px;
    background: transparent;
    color: var(--game-text);
    font: 700 0.9375rem/1 var(--font);
    letter-spacing: 0.04em;
    cursor: pointer;
  }
  .share__btn--primary {
    border-color: var(--game-accent);
    background: var(--game-accent);
  }
  .share__btn:focus-visible,
  .share__close:focus-visible { outline: 2px solid #ffd75a; outline-offset: 2px; }

  .share__status {
    min-height: 1.25rem;
    margin: 0.5rem 0 0;
    color: #9cff9c;
    font-size: 0.875rem;
  }

  .share__native {
    width: 100%;
    margin-block-start: 0.5rem;
  }
}
