/* Star Duel cockpit: a glass canopy over the arena and a control panel underneath it.
   The panel sits BELOW the arena (it never covers the fight), and the glass is a
   see-through overlay that ignores touches and clicks. Built by starduel-cockpit.js. */

:root {
  --cp-h: 88px; /* control panel height */
}

/* The arena is now: the view (canvas, glass, touch controls) and the panel under it */
.arena {
  display: flex;
  flex-direction: column;
  width: min(100%, 1200px, calc((100vh - 220px - var(--cp-h)) * 1.6));
}

.sd-view {
  position: relative;
  width: 100%;
}

/* ---------- Glass canopy ---------- */

.sd-canopy {
  position: absolute;
  inset: 0;
  border-radius: 10px;
  pointer-events: none;
  overflow: hidden;
  z-index: 2; /* over the canvas, under the buttons and touch controls */
  /* Curved glass: a faint cool sheen towards the edges, clear in the middle */
  background:
    radial-gradient(ellipse 75% 70% at 50% 46%, transparent 62%, rgba(150, 180, 255, 0.07) 88%, rgba(150, 180, 255, 0.13) 100%);
  /* The frame: a thin bevelled rim with a soft inner shadow */
  box-shadow:
    inset 0 0 0 2px rgba(120, 140, 220, 0.35),
    inset 0 0 0 5px rgba(10, 12, 32, 0.55),
    inset 0 0 22px rgba(100, 130, 255, 0.12);
}

/* Glare: two thin diagonal streaks that drift a little as your ship turns */
.sd-canopy::before {
  content: "";
  position: absolute;
  inset: -20%;
  background:
    linear-gradient(118deg,
      transparent 0 28%,
      rgba(255, 255, 255, 0.055) 31%,
      transparent 35%,
      transparent 37%,
      rgba(255, 255, 255, 0.03) 38.5%,
      transparent 40%);
  transform: translateX(var(--cp-glare, 0px));
  transition: transform 0.6s ease-out;
}

/* Corner struts of the canopy frame, and a faint reflection of the panel lights at the bottom */
.sd-canopy::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(140, 160, 240, 0.4) 0 2px, transparent 2px) top left / 26px 26px no-repeat,
    linear-gradient(225deg, rgba(140, 160, 240, 0.4) 0 2px, transparent 2px) top right / 26px 26px no-repeat,
    linear-gradient(45deg, rgba(140, 160, 240, 0.4) 0 2px, transparent 2px) bottom left / 26px 26px no-repeat,
    linear-gradient(315deg, rgba(140, 160, 240, 0.4) 0 2px, transparent 2px) bottom right / 26px 26px no-repeat,
    linear-gradient(to top, rgba(110, 200, 255, 0.07), transparent 9%);
}

/* The glass can be switched off with the Cockpit button */
body.no-cockpit .sd-canopy,
body.no-cockpit .cockpit-panel {
  display: none;
}


/* ---------- Control panel ---------- */

.cockpit-panel {
  position: relative;
  height: var(--cp-h);
  margin-top: 6px;
  padding: 6px 10px;
  box-sizing: border-box;
  display: flex;
  align-items: stretch;
  gap: 10px;
  border-radius: 6px 6px 14px 14px;
  border: 1px solid #2c3270;
  background:
    linear-gradient(to bottom, rgba(150, 165, 255, 0.16), transparent 4px),
    repeating-linear-gradient(90deg, transparent 0 46px, rgba(255, 255, 255, 0.025) 46px 47px),
    linear-gradient(to bottom, #161a3d, #0b0d24);
  box-shadow: inset 0 -3px 8px rgba(0, 0, 0, 0.6);
  color: #c3c8ee;
  font: 700 9px "Orbitron", sans-serif;
  letter-spacing: 0.08em;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

/* Little bolts in the corners */
.cockpit-panel::before,
.cockpit-panel::after {
  content: "";
  position: absolute;
  top: 5px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #3a4180;
  box-shadow: 0 calc(var(--cp-h) - 16px) 0 #3a4180;
}

.cockpit-panel::before { left: 4px; }
.cockpit-panel::after { right: 4px; }

.cp-group {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
  border-radius: 8px;
  background: rgba(5, 6, 20, 0.45);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.7);
}

.cp-name {
  font-size: 9px;
  white-space: nowrap;
}

/* Speed: a half-moon dial with a needle */
.cp-dial {
  position: relative;
  flex: 0 0 auto;
  width: 64px;
  text-align: center;
}

.cp-dial svg {
  display: block;
  width: 64px;
  height: 38px;
  overflow: visible;
}

.cp-dial .track {
  fill: none;
  stroke: #252a5a;
  stroke-width: 5;
  stroke-linecap: round;
}

.cp-dial .fill {
  fill: none;
  stroke: var(--cp-color, #4dabf7);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-dasharray: 0 100;
}

.cp-dial .needle {
  stroke: #ffffff;
  stroke-width: 2;
  stroke-linecap: round;
  transform-origin: 32px 34px;
}

.cp-dial .val {
  display: block;
  margin-top: -2px;
  font-size: 9px;
  color: #e6e9ff;
}

/* Hull and weapon bars */
.cp-bars {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}

.cp-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.cp-row > span {
  flex: 0 0 auto;
  width: 4.2em;
  overflow: hidden;
  white-space: nowrap;
}

.cp-bar {
  position: relative;
  flex: 1 1 auto;
  height: 8px;
  border-radius: 2px;
  background: #1b1e3d;
  overflow: hidden;
  /* Segment marks */
  background-image: repeating-linear-gradient(90deg, transparent 0 9%, rgba(0, 0, 0, 0.55) 9% 10%);
}

.cp-bar > i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--cp-color, #4dabf7);
  box-shadow: 0 0 6px var(--cp-color, #4dabf7);
}

.cp-bar.shielded {
  outline: 1px solid #63e6be;
  box-shadow: 0 0 8px rgba(99, 230, 190, 0.7);
}

.cp-bar.low > i {
  background: #ff922b;
  box-shadow: 0 0 6px #ff922b;
}

/* Indicator lights */
.cp-lights {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 4px 6px;
}

.cp-light {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 7px;
  color: #6b72b0;
  white-space: nowrap;
}

.cp-light::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #262b55;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.6);
}

.cp-light.on {
  color: #e6e9ff;
}

.cp-light.on::before {
  background: var(--lc, #8ce99a);
  box-shadow: 0 0 6px var(--lc, #8ce99a);
}

.cp-light.warn.on::before {
  animation: cp-blink 0.5s steps(2, jump-none) infinite;
}

@keyframes cp-blink {
  50% { background: #3a1010; box-shadow: none; }
}

/* Radar in the middle */
.cp-radar {
  flex: 0 0 auto;
  height: 100%;
  aspect-ratio: 1.6;
  border-radius: 8px;
  background: #050816;
  box-shadow: inset 0 0 0 1px #2c3270, inset 0 0 10px rgba(80, 200, 160, 0.15);
}

/* One pilot: the right-hand side shows ship systems instead of a second pilot */
.cp-systems {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px;
  border-radius: 8px;
  background: rgba(5, 6, 20, 0.45);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.7);
}

.cp-readout {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 8px;
  color: #8f96d6;
}

.cp-readout b {
  font-size: 13px;
  color: #8ce99a;
  text-shadow: 0 0 6px rgba(140, 233, 154, 0.5);
}

.cp-blinkers {
  display: grid;
  grid-template-columns: repeat(4, 8px);
  gap: 5px;
}

.cp-blinkers i {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  background: #1f2350;
}

.cp-blinkers i.on {
  background: var(--lc, #74c0fc);
  box-shadow: 0 0 5px var(--lc, #74c0fc);
}

/* ---------- Full screen: the panel stays under the view ---------- */

body.is-fullscreen .arena {
  flex-direction: column;
}

body.is-fullscreen .sd-view {
  width: auto;
}

body.is-fullscreen #game {
  width: min(100vw, calc((100vh - var(--cp-h) - 6px) * 1.6));
  width: min(100vw, calc((100dvh - var(--cp-h) - 6px) * 1.6));
}

body.is-fullscreen .cockpit-panel {
  width: min(100vw, calc((100vh - var(--cp-h) - 6px) * 1.6));
  width: min(100vw, calc((100dvh - var(--cp-h) - 6px) * 1.6));
}

/* ---------- Phones and tablets: slimmer ---------- */

@media (any-pointer: coarse) {
  :root { --cp-h: 64px; }
  .cp-dial { width: 48px; }
  .cp-dial svg { width: 48px; height: 29px; }
  .cp-lights { grid-template-columns: repeat(2, auto); gap: 2px 4px; }
  .cp-light { font-size: 6px; }
  .cp-readout b { font-size: 11px; }
}

body.touch {
  --cp-h: 64px;
}

/* Narrow phones held upright: drop the lights' words, keep the dots */
@media (max-width: 520px) {
  .cockpit-panel { gap: 6px; padding: 5px 6px; }
  .cp-group { gap: 6px; padding: 0 4px; }
  .cp-light { font-size: 0; gap: 0; }
  .cp-name { display: none; }
  .cp-row > span { width: 3.6em; font-size: 7px; }
  .cp-readout { display: none; }
  .cp-systems { flex: 0 0 auto; padding: 0 6px; }
  .cp-dial { width: 40px; }
  .cp-dial svg { width: 40px; height: 24px; }
  .cp-dial .val { font-size: 7px; }
  .cp-lights { gap: 3px; }
}

/* Phones turned sideways: a slim strip, and the arena shrinks a little to make room */
@media (orientation: landscape) and (max-height: 520px) and (any-pointer: coarse) {
  :root,
  body.touch { --cp-h: 40px; }

  body.ls-play .arena .sd-view #game {
    max-height: calc(100vh - 18px - var(--cp-h)) !important;
    max-height: calc(100dvh - 18px - var(--cp-h)) !important;
  }

  body.ls-play > .arena {
    width: auto !important;
  }

  .cockpit-panel { margin-top: 4px; padding: 3px 6px; gap: 6px; }
  .cp-lights .cp-light:not(.warn), .cp-name, .cp-readout { display: none; }
  /* Speed as words only (no dial), and the low-hull light as a dot (the bar already says HULL) */
  .cp-dial { width: auto; align-self: center; }
  .cp-dial svg { display: none; }
  .cp-dial .val { font-size: 8px; margin: 0; white-space: nowrap; }
  .cp-light.warn { font-size: 0; gap: 0; }
  .cp-bars { gap: 4px; }
  .cp-bar { height: 6px; }
  .cp-row > span { width: 3.6em; font-size: 7px; }
}

/* Cockpit switched off: no panel height anywhere (comes last so it wins) */
body.no-cockpit,
body.touch.no-cockpit {
  --cp-h: 0px !important;
}
