/*!
 * Parker Data Link — Retro Games
 * style.css
 */

/* ------------------------------------------------------------------ tokens */
:root {
  --bg:        #080a12;
  --bg-2:      #0c1020;
  --panel:     #111524;
  --line:      #ffffff14;
  --line-2:    #ffffff0a;
  --fg:        #e8ecf8;
  --dim:       #7c88a8;
  --dimmer:    #4d566f;
  --good:      #3ddc97;
  --warn:      #ffc857;
  --bad:       #ff5c7a;
  --accent:    #5ef0ff;

  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --r-sm: 8px;
  --r:    14px;
  --r-lg: 20px;

  --pad-h: 0px;             /* height reserved for the touch pad */
  --top-h: 56px;

  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow: hidden;
}

/* Ambient backdrop: two slow-drifting colour blooms over a faint grid. */
body::before {
  content: "";
  position: fixed;
  inset: -30%;
  z-index: -2;
  background:
    radial-gradient(38% 32% at 22% 18%, #5ef0ff26, transparent 70%),
    radial-gradient(36% 30% at 82% 76%, #a78bfa26, transparent 70%),
    radial-gradient(30% 26% at 62% 12%, #3ddc9718, transparent 70%);
  animation: drift 34s ease-in-out infinite alternate;
}
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(#ffffff06 1px, transparent 1px),
    linear-gradient(90deg, #ffffff06 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(80% 70% at 50% 40%, #000 30%, transparent 100%);
}
@keyframes drift {
  from { transform: translate3d(-3%, -2%, 0) scale(1); }
  to   { transform: translate3d(3%, 2%, 0) scale(1.12); }
}

button { font: inherit; color: inherit; }

::selection { background: color-mix(in oklab, var(--accent) 40%, transparent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* --------------------------------------------------------------- app frame */
#app {
  height: 100dvh;
  display: grid;
  grid-template-rows: 1fr;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.view { display: none; min-height: 0; }
.view.is-active { display: grid; }

/* ============================================================ MENU VIEW === */
#menu { grid-template-rows: auto 1fr; overflow: hidden; }

.menu-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 clamp(16px, 4vw, 40px) 48px;
}

.masthead {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: clamp(18px, 4vw, 34px) clamp(16px, 4vw, 40px) 18px;
}

.logo {
  width: 54px; height: 54px;
  flex: 0 0 auto;
  border-radius: 15px;
  background: linear-gradient(150deg, #1a2340, #0c1020);
  border: 1px solid #ffffff1f;
  display: grid; place-items: center;
  box-shadow: 0 10px 30px #0009, inset 0 1px 0 #ffffff1a;
}
.logo svg { width: 34px; height: 34px; display: block; }

.wordmark h1 {
  margin: 0;
  font-size: clamp(20px, 4.4vw, 30px);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.05;
  background: linear-gradient(96deg, #ffffff, #a9d8ff 40%, #7ef0d6 75%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.wordmark p {
  margin: 3px 0 0;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
  font-family: var(--mono);
}

.masthead-actions { margin-left: auto; display: flex; gap: 8px; }

.iconbtn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #ffffff08;
  backdrop-filter: blur(10px);
  cursor: pointer;
  transition: background .16s, border-color .16s, transform .1s;
}
.iconbtn:hover { background: #ffffff12; border-color: #ffffff2e; }
.iconbtn:active { transform: scale(.94); }
.iconbtn svg { width: 19px; height: 19px; }
.iconbtn[aria-pressed="false"] { color: var(--dimmer); }

/* ---- game grid ---- */
.grid {
  display: grid;
  gap: clamp(11px, 1.6vw, 16px);
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 228px), 1fr));
}

.tile {
  --tint: var(--accent);
  position: relative;
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, #ffffff0d, #ffffff05);
  backdrop-filter: blur(14px);
  cursor: pointer;
  overflow: hidden;
  transition: transform .18s cubic-bezier(.2,.8,.2,1), border-color .18s, box-shadow .18s;
  isolation: isolate;
}
.tile::after {
  content: "";
  position: absolute; inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(120% 80% at 50% 0%,
              color-mix(in oklab, var(--tint) 22%, transparent), transparent 62%);
  opacity: 0;
  transition: opacity .22s;
}
.tile:hover, .tile:focus-visible {
  transform: translateY(-4px);
  border-color: color-mix(in oklab, var(--tint) 46%, transparent);
  box-shadow: 0 16px 44px -14px color-mix(in oklab, var(--tint) 46%, transparent),
              0 4px 14px #0007;
}
.tile:hover::after, .tile:focus-visible::after { opacity: 1; }
.tile:active { transform: translateY(-1px) scale(.995); }

.tile-art {
  position: relative;
  aspect-ratio: 16 / 8.4;
  background: #060810;
  border-bottom: 1px solid var(--line-2);
}
.tile-art canvas { display: block; width: 100%; height: 100%; }

.tile-body { padding: 13px 15px 15px; display: flex; flex-direction: column; gap: 5px; flex: 1; }
.tile-title { display: flex; align-items: baseline; gap: 8px; }
.tile-title h3 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.tile-num {
  font-family: var(--mono); font-size: 11px; color: var(--tint);
  opacity: .8; letter-spacing: .06em;
}
.tile-tag { margin: 0; font-size: 12.5px; line-height: 1.42; color: var(--dim); }
.tile-foot {
  margin-top: auto; padding-top: 10px;
  display: flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 11px; color: var(--dimmer);
}
.tile-best {
  color: var(--warn);
  border: 1px solid #ffc85733;
  background: #ffc85714;
  padding: 2px 7px; border-radius: 99px;
}
.tile-play {
  margin-left: auto;
  color: var(--tint);
  font-weight: 700;
  letter-spacing: .08em;
}

.section-head {
  display: flex; align-items: center; gap: 12px;
  margin: 26px 0 14px;
}
.section-head h2 {
  margin: 0; font-size: 12px; letter-spacing: .18em; text-transform: uppercase;
  color: var(--dim); font-family: var(--mono); font-weight: 600;
}
.section-head::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.footnote {
  margin: 34px 0 0; text-align: center;
  font-size: 11.5px; color: var(--dimmer); font-family: var(--mono);
  line-height: 1.8;
}

/* install banner */
.install {
  display: flex; align-items: center; gap: 14px;
  margin: 22px 0 4px; padding: 14px 16px;
  border: 1px solid color-mix(in oklab, var(--good) 32%, transparent);
  background: linear-gradient(100deg, #3ddc9718, #3ddc9705);
  border-radius: var(--r);
}
.install p { margin: 0; font-size: 13px; line-height: 1.45; }
.install p b { display: block; font-size: 13.5px; }
.install p span { color: var(--dim); }
.install .btn { margin-left: auto; flex: 0 0 auto; }
.install[hidden] { display: none; }

/* ============================================================ PLAY VIEW === */
#play { grid-template-rows: var(--top-h) 1fr auto; overflow: hidden; }

#topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 0 10px;
  border-bottom: 1px solid var(--line);
  background: #0a0d18cc;
  backdrop-filter: blur(14px);
  min-width: 0;
}
#gameTitle {
  font-weight: 700; font-size: 15px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
#hud { display: flex; gap: 6px; margin-left: auto; overflow: hidden; }
.chip {
  font-family: var(--mono); font-size: 11px;
  padding: 4px 9px; border-radius: 99px;
  background: #ffffff0d; border: 1px solid var(--line);
  white-space: nowrap;
}
.chip b { color: var(--dim); font-weight: 600; margin-right: 6px; }

#stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  touch-action: none;
  background: #05070e;
}
#gameCanvas { display: block; position: absolute; inset: 0; }

.gamedom {
  position: absolute; inset: 0;
  display: block;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 12px;
  pointer-events: none;               /* children opt back in */
}
.gamedom > * { pointer-events: auto; }
.gamedom.dom-full { display: grid; place-items: center; }
.gamedom.dom-bottom { display: flex; flex-direction: column; justify-content: flex-end; }

/* overlay (pause / result) */
#overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 20px;
  background: #05070ecc;
  backdrop-filter: blur(8px);
  z-index: 5;
  animation: fade .18s ease-out;
}
#overlay[hidden] { display: none; }
@keyframes fade { from { opacity: 0; } }

.ovcard {
  width: min(420px, 100%);
  padding: 26px 24px 22px;
  border-radius: var(--r-lg);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #151a2ef2, #0d1120f2);
  box-shadow: 0 30px 80px -20px #000, inset 0 1px 0 #ffffff12;
  text-align: center;
  animation: pop .22s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes pop { from { transform: scale(.94) translateY(8px); opacity: 0; } }
.ovcard h2 {
  margin: 0 0 12px; font-size: 24px; letter-spacing: -0.02em;
}
.ov-win h2 { color: var(--good); text-shadow: 0 0 26px #3ddc9766; }
.ov-lose h2 { color: var(--bad); text-shadow: 0 0 26px #ff5c7a55; }
.ovbody { margin-bottom: 18px; }
.ovbody p {
  margin: 5px 0; font-size: 13.5px; color: var(--dim);
  font-family: var(--mono); line-height: 1.5;
}
.ovactions { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; }

/* --------------------------------------------------------- shared widgets */
.btn {
  appearance: none;
  padding: 10px 17px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: #ffffff0d;
  font-size: 13.5px; font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .08s;
}
.btn:hover { background: #ffffff18; border-color: #ffffff30; }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .38; cursor: default; transform: none; }
.btn-primary {
  background: color-mix(in oklab, var(--accent) 24%, #ffffff0d);
  border-color: color-mix(in oklab, var(--accent) 55%, transparent);
  color: #eafcff;
}
.btn-primary:hover { background: color-mix(in oklab, var(--accent) 36%, #ffffff0d); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 7px 12px; font-size: 12px; border-radius: 9px; }

.panel {
  border: 1px solid var(--line);
  background: #0d1120d9;
  backdrop-filter: blur(12px);
  border-radius: var(--r);
  padding: 14px;
  box-shadow: 0 12px 36px -16px #000;
  max-width: 640px;
  margin: 0 auto;
}
.panel + .panel { margin-top: 10px; }

.log {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
  color: var(--dim); margin: 0 0 10px;
  max-height: 8.5em; overflow-y: auto;
}
.log b, .log .hit { color: var(--fg); }

.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.col { display: flex; flex-direction: column; gap: 8px; }
.muted { color: var(--dim); }
.big { font-size: 22px; font-weight: 700; letter-spacing: .1em; font-family: var(--mono); }
.stat { font-family: var(--mono); font-size: 12px; color: var(--dim); }

.keys { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.key {
  min-width: 40px; min-height: 40px;
  padding: 0 8px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #ffffff0d;
  font-family: var(--mono); font-size: 14px; font-weight: 700;
  cursor: pointer;
  transition: background .13s, transform .07s, border-color .13s;
}
.key:hover:not(:disabled) { background: #ffffff1c; }
.key:active { transform: scale(.92); }
.key:disabled { cursor: default; }
.key.is-used { opacity: .4; }
.key.is-hit  { background: #3ddc9726; border-color: #3ddc9760; color: var(--good); opacity: 1; }
.key.is-miss { background: #ff5c7a1f; border-color: #ff5c7a4d; color: var(--bad); opacity: .75; }
.key.is-on   { background: color-mix(in oklab, var(--accent) 26%, transparent);
               border-color: var(--accent); color: #eafcff; }

/* battleship-style boards */
.grid-board {
  display: grid;
  gap: 2px;
  justify-content: center;
  font-family: var(--mono);
}
.cellbtn {
  aspect-ratio: 1;
  min-width: 0;
  border: 1px solid #ffffff12;
  background: #0e162b;
  border-radius: 3px;
  padding: 0;
  font-size: 11px;
  cursor: pointer;
  transition: background .12s, transform .07s;
}
.cellbtn:hover:not(:disabled) { background: #1b2542; }
.cellbtn:active { transform: scale(.9); }
.cellbtn.is-ship { background: #2b3a5e; }
.cellbtn.is-miss { background: #0b1020; color: var(--dimmer); }
.cellbtn.is-hit  { background: #ff5c7a33; color: var(--bad); }
.cellbtn.is-sunk { background: #ff5c7a55; color: #fff; }
.board-label { font-family: var(--mono); font-size: 10px; color: var(--dimmer); display: grid; place-items: center; }

/* ------------------------------------------------------------- touch pad */
#pad {
  display: none;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  gap: 14px;
  align-items: flex-end;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  background: #0a0d18;
  user-select: none;
}
#pad.is-on { display: flex; }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 46px);
  grid-template-rows: repeat(3, 46px);
  gap: 4px;
}
.dpad button {
  border: 1px solid var(--line);
  background: #ffffff0d;
  border-radius: 10px;
  display: grid; place-items: center;
  cursor: pointer;
  color: var(--dim);
  transition: background .1s, color .1s;
}
.dpad button:active, .dpad button.is-down {
  background: color-mix(in oklab, var(--accent) 30%, transparent);
  color: #fff;
}
.dpad button svg { width: 16px; height: 16px; }
.dpad .spacer { border: 0; background: transparent; cursor: default; }

.padbtns { display: flex; gap: 10px; align-items: center; }
.padbtn {
  width: 62px; height: 62px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: radial-gradient(circle at 35% 30%, #ffffff1c, #ffffff08);
  font-family: var(--mono); font-size: 11px; font-weight: 700;
  letter-spacing: .04em;
  cursor: pointer;
  transition: transform .08s, background .1s;
}
.padbtn:active, .padbtn.is-down {
  transform: scale(.93);
  background: color-mix(in oklab, var(--accent) 32%, transparent);
}
.padbtn.wide { width: 96px; height: 54px; border-radius: 16px; }

.pad-lr { display: flex; gap: 12px; width: 100%; }
.pad-lr button {
  flex: 1; height: 58px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #ffffff0d;
  display: grid; place-items: center;
  cursor: pointer; color: var(--dim);
}
.pad-lr button:active, .pad-lr button.is-down {
  background: color-mix(in oklab, var(--accent) 30%, transparent); color: #fff;
}
.pad-lr svg { width: 20px; height: 20px; }

/* --------------------------------------------------------------- motion */
@media (prefers-reduced-motion: reduce) {
  body::before { animation: none; }
  .tile, .btn, .key, .iconbtn { transition: none; }
  #overlay, .ovcard { animation: none; }
}

/* --------------------------------------------------------------- narrow */
@media (max-width: 560px) {
  .masthead { gap: 12px; }
  .logo { width: 46px; height: 46px; border-radius: 13px; }
  .logo svg { width: 29px; height: 29px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 158px), 1fr)); gap: 11px; }
  .tile-body { padding: 10px 11px 12px; }
  .tile-title h3 { font-size: 14px; }
  .tile-tag { font-size: 11.5px; }
  .tile-foot { font-size: 10px; }
  .install { flex-wrap: wrap; }
  .install .btn { margin-left: 0; width: 100%; }
}
@media (max-height: 460px) and (orientation: landscape) {
  #pad { padding: 6px 12px; }
  .dpad { grid-template-columns: repeat(3, 40px); grid-template-rows: repeat(3, 40px); }
  .padbtn { width: 54px; height: 54px; }
}
