/* HFS UI closure layer
 *
 * This file is intentionally last. It is a small, semantic visual system on
 * top of the older responsive rules: aviation-console navy, amber action
 * states, restrained cyan telemetry, and clear disclosure for secondary
 * systems. It contains no layout-dependent JS assumptions and stays within
 * Safari 13 CSS features for the bundled iOS entry.
 */

:root {
  --hfs-console: #07131d;
  --hfs-console-2: #0a1d2a;
  --hfs-console-3: #102b3a;
  --hfs-glass: rgba(5, 18, 28, 0.82);
  --hfs-glass-strong: rgba(5, 16, 25, 0.96);
  --hfs-outline: rgba(176, 207, 222, 0.22);
  --hfs-outline-strong: rgba(176, 207, 222, 0.42);
  --hfs-amber: #f2b84b;
  --hfs-cyan: #43c7d7;
  --hfs-green: #60d7ac;
  --hfs-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

/* Shared surface language ------------------------------------------------ */

.panel,
.hud-panel,
#minimap,
#annunciator,
.multiplayer-drawer,
#chat-form {
  border-color: var(--hfs-outline);
  background:
    linear-gradient(135deg, rgba(67, 199, 215, 0.055), transparent 32%),
    linear-gradient(180deg, var(--hfs-glass), rgba(4, 14, 23, 0.9));
  box-shadow:
    0 22px 60px rgba(0, 0, 0, 0.28),
    inset 0 1px rgba(255, 255, 255, 0.06);
}

button,
.link-button,
input,
select,
textarea {
  transition: border-color 150ms ease, background 150ms ease, color 150ms ease,
    box-shadow 150ms ease, transform 150ms ease;
}

button.primary,
.link-button.primary-link {
  border-color: rgba(242, 184, 75, 0.88);
  color: #1b1408;
  background: linear-gradient(135deg, #f5c866, #e6a83e);
  box-shadow: 0 8px 24px rgba(242, 184, 75, 0.16);
}

button.primary:hover,
.link-button.primary-link:hover {
  background: linear-gradient(135deg, #ffd981, #f2b84b);
  box-shadow: 0 10px 30px rgba(242, 184, 75, 0.24);
}

.eyebrow,
.settings-label,
.hud-label,
.auth-feature-label {
  color: var(--hfs-amber);
  font-family: var(--hfs-mono);
  letter-spacing: 0.11em;
}

/* Hangar dispatch board -------------------------------------------------- */

#select-screen {
  grid-template-rows: auto minmax(0, 1fr) clamp(132px, 18vh, 168px);
  gap: 12px;
  background:
    linear-gradient(180deg, rgba(4, 13, 21, 0.68), rgba(4, 13, 21, 0.9)),
    url("assets/ui/hangar-operations-bg-v1.png") center / cover no-repeat;
}

.hangar-environment {
  filter: saturate(0.72) contrast(1.08);
}

#select-header {
  min-height: 60px;
  padding-bottom: 12px;
  border-bottom-color: rgba(176, 207, 222, 0.25);
}

#select-header h1 {
  font-size: clamp(1.85rem, 3.2vw, 2.7rem);
  letter-spacing: -0.04em;
}

#select-header::after {
  color: rgba(176, 207, 222, 0.64);
  font-family: var(--hfs-mono);
  letter-spacing: 0.16em;
}

.select-account {
  gap: 6px;
}

.select-account > span {
  color: var(--hfs-green);
  font-family: var(--hfs-mono);
  font-size: 0.68rem;
  letter-spacing: 0.08em;
}

.select-account .account-action {
  min-height: 38px;
  border-color: rgba(176, 207, 222, 0.2);
  background: rgba(5, 18, 28, 0.58);
}

#aircraft-detail {
  grid-template-columns: minmax(0, 1.5fr) minmax(310px, 0.68fr);
  gap: 20px;
  padding: 16px;
  border-color: rgba(176, 207, 222, 0.32);
  background: rgba(4, 15, 24, 0.84);
}

.aircraft-detail-visual {
  min-height: 0;
  border-color: rgba(176, 207, 222, 0.26);
  background:
    radial-gradient(circle at 50% 42%, rgba(67, 199, 215, 0.14), transparent 45%),
    linear-gradient(180deg, rgba(16, 46, 62, 0.72), rgba(3, 13, 22, 0.9));
}

#aircraft-preview {
  overflow: hidden;
}

#aircraft-preview canvas {
  transition: opacity 180ms ease, filter 180ms ease;
}

#aircraft-preview[data-preview-state="loading"] canvas {
  opacity: 0.26;
  filter: saturate(0.35) blur(0.2px);
}

#aircraft-preview[data-preview-state="error"] canvas {
  opacity: 0.12;
  filter: grayscale(1);
}

.aircraft-preview-status {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 4;
  max-width: min(80%, 280px);
  padding: 7px 10px;
  border: 1px solid rgba(176, 207, 222, 0.25);
  border-radius: 999px;
  color: rgba(239, 248, 252, 0.86);
  background: rgba(4, 14, 23, 0.72);
  font-family: var(--hfs-mono);
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-align: center;
  text-transform: uppercase;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

#aircraft-preview[data-preview-state="ready"] .aircraft-preview-status {
  top: auto;
  right: 12px;
  bottom: 12px;
  left: auto;
  padding: 4px 7px;
  border-color: rgba(96, 215, 172, 0.28);
  color: var(--hfs-green);
  background: rgba(4, 21, 24, 0.64);
  font-size: 0.52rem;
  transform: none;
}

#aircraft-preview[data-preview-state="loading"] .aircraft-preview-status::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 7px;
  border: 1px solid rgba(242, 184, 75, 0.35);
  border-top-color: var(--hfs-amber);
  border-radius: 50%;
  vertical-align: -1px;
  animation: hfs-spin 900ms linear infinite;
}

#aircraft-preview[data-preview-state="error"] .aircraft-preview-status {
  border-color: rgba(255, 101, 116, 0.42);
  color: #ffb2bc;
}

@keyframes hfs-spin {
  to { transform: rotate(360deg); }
}

.aircraft-detail-copy {
  align-content: center;
  gap: 11px;
}

#aircraft-detail h2 {
  max-width: 15ch;
  font-size: clamp(1.8rem, 3vw, 2.75rem);
  letter-spacing: -0.04em;
}

#selected-aircraft-role {
  color: rgba(176, 207, 222, 0.74);
}

.aircraft-capability-grid > div {
  min-height: 62px;
  border-color: rgba(176, 207, 222, 0.2);
  background: rgba(16, 43, 58, 0.48);
}

.aircraft-capability-grid strong,
#selected-aircraft-code,
#flight-ops-summary {
  font-family: var(--hfs-mono);
  font-variant-numeric: tabular-nums;
}

#aircraft-detail .flight-ops-summary {
  min-height: 54px;
  border-color: rgba(120, 199, 255, 0.24);
  background: rgba(8, 28, 42, 0.62);
}

#aircraft-detail .button-row {
  gap: 8px;
}

#aircraft-detail .select-action-card {
  min-height: 62px;
  border-radius: 11px;
}

#aircraft-detail #fly-practice-button {
  border-color: rgba(242, 184, 75, 0.92);
  color: #1b1408;
  background: linear-gradient(135deg, #f5c866, #e6a83e);
}

#aircraft-detail #select-join-button {
  border-color: rgba(67, 199, 215, 0.42);
  color: var(--hfs-cyan);
  background: rgba(10, 34, 47, 0.82);
}

#aircraft-grid {
  grid-auto-columns: clamp(168px, 15vw, 214px);
  gap: 9px;
  padding: 9px;
  border-color: rgba(176, 207, 222, 0.24);
  background: rgba(4, 15, 24, 0.84);
}

#aircraft-grid .aircraft-card {
  height: 116px;
  grid-template-rows: minmax(58px, 1fr) auto;
  gap: 6px;
  padding: 8px;
  border-color: rgba(176, 207, 222, 0.2);
  background: linear-gradient(180deg, rgba(13, 37, 52, 0.94), rgba(5, 17, 27, 0.96));
}

#aircraft-grid .aircraft-card:hover {
  transform: translateY(-2px);
  border-color: rgba(176, 207, 222, 0.55);
}

#aircraft-grid .aircraft-card.active {
  border-color: var(--hfs-amber);
  background: linear-gradient(180deg, rgba(60, 46, 22, 0.96), rgba(19, 28, 31, 0.96));
  box-shadow: 0 0 0 1px rgba(242, 184, 75, 0.32), 0 10px 22px rgba(0, 0, 0, 0.2);
}

#aircraft-grid .aircraft-card-preview {
  min-height: 58px;
  border-color: rgba(176, 207, 222, 0.14);
  background:
    linear-gradient(90deg, transparent 49.5%, rgba(176, 207, 222, 0.1) 49.5% 50.5%, transparent 50.5%),
    radial-gradient(circle at 50% 45%, rgba(67, 199, 215, 0.11), transparent 54%);
}

#aircraft-grid .aircraft-card.active .aircraft-card-preview {
  border-color: rgba(242, 184, 75, 0.44);
  background:
    linear-gradient(90deg, transparent 49.5%, rgba(242, 184, 75, 0.13) 49.5% 50.5%, transparent 50.5%),
    radial-gradient(circle at 50% 45%, rgba(242, 184, 75, 0.18), transparent 54%);
}

.aircraft-preview-placeholder::after {
  content: "MODEL / WAIT";
  position: absolute;
  inset: auto 7px 6px auto;
  color: rgba(176, 207, 222, 0.48);
  font-family: var(--hfs-mono);
  font-size: 0.44rem;
  letter-spacing: 0.08em;
}

.aircraft-card-preview[data-thumbnail-state="ready"] .aircraft-preview-placeholder::after {
  content: "READY";
  color: rgba(96, 215, 172, 0.72);
}

.aircraft-card-preview[data-thumbnail-state="error"] .aircraft-preview-placeholder::after,
.aircraft-card-preview[data-thumbnail-state="unavailable"] .aircraft-preview-placeholder::after {
  content: "NO PREVIEW";
  color: rgba(255, 178, 188, 0.76);
}

.aircraft-card-preview[data-thumbnail-state="loading"]::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(67, 199, 215, 0.12), transparent);
  transform: translateX(-100%);
  animation: hfs-scan 1.6s ease-in-out infinite;
}

@keyframes hfs-scan {
  to { transform: translateX(100%); }
}

/* Flight console --------------------------------------------------------- */

#settings-button,
#hud-mode-button {
  min-height: 44px;
  border-color: rgba(176, 207, 222, 0.28);
  background: rgba(5, 18, 28, 0.78);
}

#settings-button:hover,
#hud-mode-button:hover {
  border-color: rgba(67, 199, 215, 0.64);
  background: rgba(10, 34, 47, 0.9);
}

#hud {
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.18));
}

#hud-strip .hud-metric strong,
#hud-heading,
#hud-roll,
#hud-slip,
#mobile-flight-strip strong,
#flight-network-chip strong {
  font-family: var(--hfs-mono);
  font-variant-numeric: tabular-nums;
}

#hud-strip .hud-metric strong {
  color: #edf8fb;
}

#hud-strip .hud-metric:first-child strong {
  color: var(--hfs-cyan);
}

#hud-strip .hud-metric:nth-child(2) strong {
  color: var(--hfs-amber);
}

#minimap {
  border-color: rgba(67, 199, 215, 0.34);
  border-radius: 50%;
  background: rgba(4, 16, 25, 0.76);
  box-shadow: 0 0 0 1px rgba(67, 199, 215, 0.08), 0 18px 38px rgba(0, 0, 0, 0.24);
}

#flight-network-chip {
  border-color: rgba(96, 215, 172, 0.32);
  background: rgba(4, 21, 24, 0.72);
}

#flight-network-chip.is-live {
  box-shadow: 0 0 18px rgba(96, 215, 172, 0.1);
}

#annunciator {
  left: 50%;
  right: auto;
  bottom: auto;
  height: auto;
  border-radius: 999px;
  background: rgba(4, 16, 25, 0.7);
  font-family: var(--hfs-mono);
}

/* FULL is an expanded instrument cluster, not a second cockpit covering the
 * world. Explicit grid sizing also prevents the legacy narrow-width flex
 * rules from wrapping the attitude and data panels into full-width rows. */
#game-screen:not(.mobile-controls-enabled).hud-mode-full #hud {
  left: max(14px, calc(var(--safe-left) + 10px));
  right: auto;
  top: auto;
  bottom: max(14px, calc(var(--safe-bottom) + 10px));
  width: min(398px, calc(100vw - 28px));
  min-width: 0;
  height: 174px;
  display: grid;
  grid-template-columns: 158px minmax(0, 1fr);
  align-items: stretch;
  gap: 7px;
  transform: scale(var(--hfs-desktop-hud-scale, 1));
  transform-origin: left bottom;
}

#game-screen:not(.mobile-controls-enabled).hud-mode-full #hud #attitude-card {
  width: auto;
  min-width: 0;
  min-height: 0;
  height: 174px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 5px;
  padding: 7px;
  flex: none;
}

#game-screen:not(.mobile-controls-enabled).hud-mode-full #attitude-canvas {
  width: auto;
  max-width: 116px;
  max-height: 116px;
  align-self: center;
  justify-self: center;
}

#game-screen:not(.mobile-controls-enabled).hud-mode-full #hud #hud-strip {
  width: auto;
  min-width: 0;
  min-height: 0;
  height: 174px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 5px;
  padding: 7px;
  flex: none;
}

#game-screen:not(.mobile-controls-enabled).hud-mode-full #hud-strip .hud-data-header {
  min-height: 24px;
  display: flex;
  padding-bottom: 5px;
}

#game-screen:not(.mobile-controls-enabled).hud-mode-full .hud-label-stack strong {
  display: none;
}

#game-screen:not(.mobile-controls-enabled).hud-mode-full #hud-strip .hud-data-grid {
  height: auto;
  min-height: 0;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 3px 5px;
}

#game-screen:not(.mobile-controls-enabled).hud-mode-full #hud-strip .hud-metric,
#game-screen:not(.mobile-controls-enabled).hud-mode-full #hud-strip .hud-metric-primary,
#game-screen:not(.mobile-controls-enabled).hud-mode-full #hud-strip .hud-metric-advanced {
  min-height: 0;
  padding: 2px 4px;
}

#game-screen:not(.mobile-controls-enabled).hud-mode-full #hud-strip .hud-metric-network,
#game-screen:not(.mobile-controls-enabled).hud-mode-full #hud-strip .hud-lever-bank {
  display: none !important;
}

#game-screen:not(.mobile-controls-enabled).hud-mode-full #hud-strip .hud-metric strong {
  font-size: 0.68rem;
}

#game-screen:not(.mobile-controls-enabled).hud-mode-full #hud-strip .hud-metric span,
#game-screen:not(.mobile-controls-enabled).hud-mode-full .hud-heading-readout span,
#game-screen:not(.mobile-controls-enabled).hud-mode-full .hud-attitude-foot span {
  font-size: 0.49rem;
}

#settings-dialog,
.multiplayer-drawer,
#server-node-dialog {
  border-color: rgba(176, 207, 222, 0.34);
  background:
    linear-gradient(135deg, rgba(67, 199, 215, 0.06), transparent 30%),
    rgba(5, 16, 25, 0.97);
}

#settings-dialog,
.multiplayer-drawer {
  animation: hfs-drawer-in 180ms ease-out both;
}

@keyframes hfs-drawer-in {
  from { opacity: 0; transform: translateX(18px); }
  to { opacity: 1; transform: translateX(0); }
}

.multiplayer-session-status,
.multiplayer-roster-item,
.toggle-row,
.range-row,
.select-row {
  border-color: rgba(176, 207, 222, 0.2);
  background: rgba(10, 34, 47, 0.5);
}

.select-row {
  min-height: 44px;
  padding: 9px 11px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(176, 207, 222, 0.2);
}

.select-row select {
  min-width: 128px;
  border-color: rgba(176, 207, 222, 0.3);
  color: #e8f4f8;
  background: rgba(4, 17, 26, 0.9);
}

.graphics-settings-note {
  margin: 0;
  color: rgba(207, 226, 234, 0.72);
  line-height: 1.4;
}

/* Responsive rules ------------------------------------------------------- */

@media (max-width: 920px) {
  #select-screen {
    grid-template-rows: auto minmax(0, 1fr) 138px;
  }

  #aircraft-detail {
    grid-template-columns: minmax(0, 1fr) minmax(270px, 0.86fr);
    gap: 12px;
    padding: 12px;
  }

  #aircraft-grid {
    grid-auto-columns: 158px;
  }
}

@media (max-width: 700px) and (orientation: portrait) {
  #select-screen {
    grid-template-rows: auto minmax(0, 1fr) 150px;
    gap: 8px;
  }

  #select-header {
    min-height: 52px;
  }

  .account-action-label {
    display: none;
  }

  #aircraft-detail {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(180px, 1fr) auto;
    gap: 10px;
    padding: 10px;
  }

  .aircraft-detail-copy {
    padding: 0 2px 2px;
  }

  #aircraft-detail h2 {
    max-width: 16ch;
    font-size: 1.65rem;
  }

  #aircraft-grid {
    grid-auto-columns: 148px;
    height: 150px;
  }
}

@media (max-width: 700px) and (max-height: 430px) and (orientation: landscape) {
  #select-screen {
    grid-template-columns: 148px minmax(0, 1fr);
    grid-template-rows: 38px minmax(0, 1fr);
    gap: 6px;
    padding: max(8px, calc(var(--safe-top) + 4px)) max(10px, calc(var(--safe-right) + 8px)) max(8px, calc(var(--safe-bottom) + 4px)) max(10px, calc(var(--safe-left) + 8px));
  }

  #select-header {
    grid-column: 1 / -1;
    grid-row: 1;
    min-height: 38px;
    padding: 0;
  }

  #select-header .eyebrow,
  .select-account .account-action {
    display: none;
  }

  #select-header h1 {
    font-size: 1.08rem;
  }

  #aircraft-grid {
    grid-column: 1;
    grid-row: 2;
    display: block;
    height: auto;
    min-height: 0;
    padding: 5px;
    overflow-x: hidden;
    overflow-y: auto;
  }

  #aircraft-grid .aircraft-group,
  #aircraft-grid .aircraft-group-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 5px;
  }

  #aircraft-grid .aircraft-card {
    width: 100%;
    height: 44px;
    min-height: 44px;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: 1fr;
    gap: 5px;
    padding: 6px 7px;
  }

  #aircraft-grid .aircraft-card-preview,
  #aircraft-grid .aircraft-card small,
  #aircraft-grid .aircraft-card-stats,
  #aircraft-grid .aircraft-status,
  #aircraft-grid .aircraft-group-header {
    display: none;
  }

  #aircraft-detail {
    grid-column: 2;
    grid-row: 2;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) 48px;
    min-height: 0;
    gap: 6px;
    padding: 7px;
  }

  #aircraft-detail-visual {
    display: block;
    min-height: 0;
  }

  #aircraft-preview {
    min-height: 0;
  }

  .aircraft-detail-copy {
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(144px, 0.9fr);
    align-items: center;
    gap: 7px;
    padding: 0;
  }

  #selected-aircraft-role,
  #aircraft-detail .aircraft-capability-grid,
  #selected-aircraft-status,
  #select-message,
  #aircraft-detail .flight-ops-summary {
    display: none;
  }

  #aircraft-detail h2 {
    max-width: none;
    font-size: 0.86rem;
    white-space: nowrap;
  }

  #aircraft-detail .button-row {
    gap: 5px;
  }

  #aircraft-detail .select-action-card {
    min-height: 42px;
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-rows: 1fr;
    gap: 4px;
    padding: 4px 6px;
  }

  #aircraft-detail .select-action-icon {
    width: 15px;
    height: 15px;
    grid-row: auto;
  }

  #aircraft-detail .select-action-label {
    font-size: 0.56rem;
  }

  #aircraft-detail .select-action-card small {
    display: none;
  }

  .aircraft-preview-status {
    font-size: 0.48rem;
  }

  #game-screen:not(.mobile-controls-enabled).hud-mode-full #hud {
    width: min(344px, calc(100vw - 176px));
    height: 132px;
    grid-template-columns: 118px minmax(0, 1fr);
    gap: 5px;
  }

  #game-screen:not(.mobile-controls-enabled).hud-mode-full #hud #attitude-card,
  #game-screen:not(.mobile-controls-enabled).hud-mode-full #hud #hud-strip {
    height: 132px;
    padding: 5px;
  }

  #game-screen:not(.mobile-controls-enabled).hud-mode-full #attitude-canvas {
    max-width: 86px;
    max-height: 86px;
  }

  #game-screen:not(.mobile-controls-enabled).hud-mode-full .hud-label-stack strong,
  #game-screen:not(.mobile-controls-enabled).hud-mode-full .hud-attitude-foot span {
    display: none;
  }

  #game-screen:not(.mobile-controls-enabled).hud-mode-full #hud-strip .hud-data-header {
    min-height: 18px;
    padding-bottom: 3px;
  }

  #game-screen:not(.mobile-controls-enabled).hud-mode-full #hud-strip .hud-metric strong {
    font-size: 0.6rem;
  }

  #game-screen:not(.mobile-controls-enabled).hud-mode-full #hud-strip .hud-metric span {
    font-size: 0.43rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
