/* global styles */

@font-face {
  font-family: Silkscreen;
  src: url('/fonts/silkscreen/slkscr-webfont.woff') format('woff');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: Silkscreen;
  src: url('/fonts/silkscreen/slkscrb-webfont.woff') format('woff');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Chrome-only for now but this will allow smooth size transitions */
  interpolate-size: allow-keywords;

  --background-color: #0a100e;
  --accent-color: #00d9a5;
  --text-color: #c5efdf;
  --font-heading: Silkscreen, ui-monospace, 'Courier New', monospace;
}

html {
  box-sizing: border-box;
}

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

body {
  display: flex;
  flex-direction: column;
  padding: 0;
  margin: 0;
  background-color: var(--background-color);
  color: var(--text-color);

  font-family: Futura, 'Trebuchet MS', Arial, sans-serif;
  font-style: normal;
  font-variant: normal;
}

a {
  color: var(--accent-color);
}

a:visited {
  color: #6ae8c8;
}

footer,
header {
  flex: 0;
  min-height: 50px;
  height: 50px;
  display: flex;
  align-items: center;

  img {
    max-height: 40px;
    margin-right: 0.5em;
  }

  h1 {
    flex: 1;
    margin-right: 0;
    text-align: center;
  }
}

.header-back-btn,
footer {
  font-family: Silkscreen, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* Hub / combat key-help entry — matches ? shortcut (see index.js). */
.header-key-help-btn {
  flex-shrink: 0;
  box-sizing: border-box;
  min-width: 2.25rem;
  height: 2.25rem;
  margin: 0;
  padding: 0 0.35rem;
  font-family: Silkscreen, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent-color);
  background: rgba(0, 217, 165, 0.08);
  border: 1px solid var(--accent-color);
  border-radius: 4px;
  cursor: pointer;
}

.header-key-help-btn:hover {
  background: rgba(0, 217, 165, 0.16);
}

.header-key-help-btn:focus-visible {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

header#main-head {
  justify-content: space-between;
  padding: 0 8px;
  border-bottom: 1px solid var(--accent-color);
}

.header-identity {
  text-decoration: none;
  color: inherit;

  h1 {
    font-family: var(--font-heading);
    font-size: 24px;
  }
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-heading);
  font-variant: normal;
}

h1 {
  font-weight: 700;
}

h2,
h3,
h4 {
  font-weight: 400;
}

#main-head > * {
  display: flex;
  flex-direction: row;
  align-items: center;
}

#logo {
  height: 40px;
  margin: 0 10px 0 5px;
}

#main-foot {
  border-top: 1px solid var(--accent-color);
  justify-content: center;
}

main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 80vh;
  max-width: 100vw;
  overflow: hidden;

  padding: 8px;
  overflow-y: auto;
  background-color: #071210;
}

.game-shell {
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  min-height: 0;
}

.game-shell__caption {
  margin: 0;
  max-width: 42rem;
  font-size: 0.9rem;
  opacity: 0.85;
}

.game-shell__status {
  margin: 0;
  max-width: 42rem;
  font-size: 0.85rem;
  letter-spacing: 0.04em;
  text-align: center;

  display: flex;
  flex-direction: column;
  gap: 0.2em;

  /* Four reserved rows: stats, context, and two activity lines. Each row holds
   * its own line so toggling text never reflows the canvas above. Stable rows
   * never wrap - at narrow viewports they ellipsize rather than spilling. */
  .game-shell__stats {
    color: #6ae8c8;
    height: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .game-shell__context {
    color: #b8f5e2;
    height: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.92;
  }

  .status-sep {
    margin: 0 0.55em;
    opacity: 0.55;
  }

  .alert-tag {
    font-weight: 700;
    letter-spacing: 0.1em;
    color: #ff7a66;
  }

  .hazard-tag {
    color: #d45a3a;
    font-weight: 700;
    letter-spacing: 0.1em;
    animation: hazard-pulse 1.2s ease-in-out infinite;
  }

  @keyframes hazard-pulse {
    0%,
    100% {
      opacity: 1;
    }
    50% {
      opacity: 0.55;
    }
  }

  .game-shell__activity {
    height: 1.1rem;
    font-style: italic;
    letter-spacing: 0.03em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;

    &.hint {
      font-style: normal;
      color: #6ae8c8;
      opacity: 0.85;
    }

    .faction-tag {
      font-style: normal;
      font-weight: 700;
      letter-spacing: 0.14em;
    }

    &.corp {
      color: #e8b078;

      .faction-tag {
        color: #ff7a66;
      }
    }
  }
}

.game-stage {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  max-width: min(960px, max(320px, calc((100dvh - 13.25rem) * 1.6)), 100%);
}

.game-canvas-wrap {
  position: relative;
  flex: 1 1 80%;
  min-width: 0;

  & > #game-canvas {
    border-radius: 1rem 0.5rem 0.5rem 2rem;
    corner-shape: bevel;

    &.cyber {
      border-color: rgba(255, 92, 198, 0.5);
      box-shadow: 0 0 12px rgba(255, 92, 198, 0.18);
    }
  }
}

/* P3.M3.7 / P3.M4.5: PIP of the inactive layer while jacked in — meat CCTV by
   default, cyber-tinted (`.pip-cyber`) when the grid is the inactive feed.
   Anchored to the main canvas, not the stage. */
.game-canvas-wrap > #pip-canvas {
  position: absolute;
  right: 0.35rem;
  bottom: 0.35rem;
  z-index: 2;
  pointer-events: none;
  border: 1px solid rgba(0, 217, 165, 0.45);
  border-radius: 0.35rem 0.35rem 0.35rem 0.75rem;
  corner-shape: bevel;
  box-shadow: 0 0 12px rgba(0, 217, 165, 0.15);
  opacity: 0.92;
  image-rendering: pixelated;
}

/* Cyber feed (viewing meat) — magenta to match `// GRID //`. */
.game-canvas-wrap > #pip-canvas.pip-cyber {
  border-color: rgba(255, 92, 198, 0.5);
  box-shadow: 0 0 12px rgba(255, 92, 198, 0.18);
}

.game-canvas-wrap > #pip-canvas[hidden] {
  display: none;
}

.game-canvas-wrap > #pip-canvas.pip-hit {
  animation: pip-hit-pulse 0.45s ease-out;
}

@keyframes pip-hit-pulse {
  0% {
    border-color: #ff7a66;
    box-shadow: 0 0 16px rgba(255, 122, 102, 0.55);
  }
  100% {
    border-color: rgba(0, 217, 165, 0.45);
    box-shadow: 0 0 12px rgba(0, 217, 165, 0.15);
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-canvas-wrap > #pip-canvas.pip-hit {
    animation: none;
    border-color: #ff7a66;
  }
}

@media (max-width: 360px) {
  .game-canvas-wrap > #pip-canvas {
    display: none !important;
  }
}

.game-stage > .game-log {
  display: flex;
  flex-direction: column;
  flex-basis: 20%;
  border: 1px solid var(--accent-color);
  align-self: stretch;
  aspect-ratio: 120 / 240;
  border-radius: 0.5rem 2rem 1rem 0.5rem;
  corner-shape: bevel;
  overflow: hidden;

  transition: all 0.2s cubic-bezier(0.83, 0, 0.17, 1);

  h3 {
    margin: 0;
    padding: 0.5rem;
    text-align: center;
    border-bottom: 1px dashed var(--accent-color);
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.83, 0, 0.17, 1);

    &:before {
      content: '◤\00a0';
    }
  }
  pre {
    margin: 0;
    flex: 1;
    min-height: 0;

    font-size: 0.7rem;
    color: var(--accent-color);
    padding: 0.5rem;
    overflow-y: auto;
    white-space: pre-wrap;
    text-align: left;

    -webkit-mask-image: linear-gradient(to bottom, white, transparent);
    mask-image: linear-gradient(to bottom, white, transparent);
  }

  &.collapsed {
    flex-basis: 1.75rem;
    aspect-ratio: unset;
    border-radius: 0.5rem;
    h3 {
      transform: rotate(-90deg) translate(-50%, -60%);
      width: fit-content;
      border: none;
      &:before {
        content: '◣\00a0';
      }
    }
    pre {
      display: none;
    }
  }
}

.game-stage > run-briefing,
.game-stage > crash-dump,
.game-stage > game-over,
.game-stage > fault-screen,
.game-stage > system-start,
.game-stage > curator-briefing {
  position: absolute;
  inset: 0;
  z-index: 5;
}

.game-stage > #game-canvas[hidden] {
  display: none;
}

/* ---------------------------------------------------------------------------
 * M0 combat feedback animations.
 *
 * Shake translates the whole stage (canvas + any overlay); the damage
 * vignette is a pseudo-element radial gradient that fades in then out. Both
 * are restarted by the JS side via remove-then-re-add of the class so two
 * hits in a row replay rather than coalesce. Durations are mirrored in
 * `src/render/animations.js#ANIMATION_DURATIONS`.
 * ------------------------------------------------------------------------ */

.game-stage.kp-shake {
  animation: kp-shake 150ms ease-out;
}

@keyframes kp-shake {
  0% {
    transform: translate(0, 0);
  }
  20% {
    transform: translate(-3px, 1px);
  }
  40% {
    transform: translate(3px, -1px);
  }
  60% {
    transform: translate(-2px, 2px);
  }
  80% {
    transform: translate(2px, -2px);
  }
  100% {
    transform: translate(0, 0);
  }
}

.game-stage::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(
    circle at center,
    rgba(255, 30, 30, 0) 35%,
    rgba(255, 30, 30, 0.55) 100%
  );
  opacity: 0;
  pointer-events: none;
  z-index: 6;
}

.game-stage.kp-damage-flash::after {
  animation: kp-damage-flash 300ms ease-out;
}

@keyframes kp-damage-flash {
  0% {
    opacity: 0;
  }
  20% {
    opacity: 1;
  }
  100% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-stage.kp-shake,
  .game-stage.kp-damage-flash::after {
    animation: none;
  }
}

#game-canvas {
  display: block;
  width: 100%;
  max-width: min(960px, 100%);
  height: auto;
  aspect-ratio: 640 / 400;
  image-rendering: pixelated;
  background-color: #020403;
  border: 1px solid var(--accent-color);
  box-shadow: 0 0 24px rgba(0, 217, 165, 0.12);
}

.btn,
button,
input[type='file']::file-selector-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.25em 1em;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  font-variant: common-ligatures small-caps;
  text-decoration: none;

  img {
    height: 2em;
    width: 2em;
    margin: 0 0.25rem;
  }

  &:disabled {
    cursor: not-allowed;

    img {
      opacity: 0.5;
    }
  }

  &:not(:disabled):hover,
  &:not(:disabled):focus-visible {
    outline: var(--accent-color) auto 1px;
    background-color: rgba(0, 217, 165, 0.12);
  }
}

input[type='file'] {
  border-radius: 5px;
  border: 1px solid #2a4a42;
  cursor: pointer;

  &::file-selector-button {
    display: inline-flex;
  }

  &:not(:disabled):hover,
  &:not(:disabled):focus-visible {
    outline: var(--accent-color) auto 1px;

    &::file-selector-button {
      background-color: rgba(0, 217, 165, 0.12);
    }
  }
}

a.btn {
  &:not(:disabled):hover,
  &:not(:disabled):focus-visible {
    text-decoration: underline;
  }
}

a:focus-visible {
  outline: var(--accent-color) auto 1px;
}

/* util classes */

.u-hidden {
  display: none !important;
}

.u-sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

.u-flex {
  display: flex;
}

.u-flex-column {
  flex-direction: column;
}

.u-flex-1 {
  flex: 1;
}

.u-left {
  text-align: left;
}

.u-center {
  text-align: center;
}

.u-fill-width {
  width: -webkit-fill-available;
  width: 100%;
}

.u-fill-height {
  height: -webkit-fill-available;
  height: 100vh;
}

.u-stretch-height {
  height: -webkit-fill-available;
  height: 100%;
  flex: 1;
}

/* background scroll fix for dialogs */
dialog {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
}

/* web component placeholders */
update-notification {
  display: none;
}

/* view transitions */

@view-transition {
  navigation: auto;
  types: slide, forwards;
}
