/* ============================================================
   JIMOTHY CLICK — styles.css
   Pixel-art UI chrome, responsive layout, accessibility helpers
   ============================================================ */

:root {
  --night: #141428;
  --night-deep: #0c0c1c;
  --moon: #f4f1de;
  --accent: #ffb703;
  --accent-hot: #fb8500;
  --ui-text: #e8e6f0;
  --ui-dim: #9a97b0;
  --panel: rgba(16, 16, 34, 0.88);
  --panel-border: #4a4a72;
  --focus-ring: #7ee8fa;
  --danger: #ef476f;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--night-deep);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: "Courier New", ui-monospace, Menlo, Consolas, monospace;
  color: var(--ui-text);
  display: flex;
  align-items: center;
  justify-content: center;
}

#game-shell {
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game-frame {
  position: relative;
  /* Sized by JS to preserve aspect and integer scaling */
  width: 100%;
  max-width: 1280px;
  line-height: 0;
}

#game-canvas {
  display: block;
  width: 100%;
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--night);
  border-radius: 6px;
}

.canvas-fallback {
  line-height: 1.5;
  padding: 2rem;
  color: var(--ui-text);
  font-size: 1rem;
}

/* ---------- Overlays ---------- */

.overlay {
  position: absolute;
  inset: 0;
  line-height: 1.4;
}

.hidden { display: none !important; }

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2.2vmin, 20px);
  background: radial-gradient(ellipse at center,
              rgba(20, 20, 46, 0.55) 0%, rgba(8, 8, 20, 0.82) 100%);
  text-align: center;
  padding: 4vmin;
  border-radius: 6px;
}

/* ---------- Title ---------- */

.game-title {
  margin: 0;
  font-size: clamp(2rem, 9vmin, 4.5rem);
  letter-spacing: 0.08em;
  color: var(--accent);
  text-shadow:
    3px 3px 0 var(--accent-hot),
    6px 6px 0 rgba(0, 0, 0, 0.55);
  font-weight: 700;
}

.subtitle {
  margin: 0;
  color: var(--ui-dim);
  font-size: clamp(0.85rem, 3vmin, 1.2rem);
  font-style: italic;
}

.screen-heading {
  margin: 0;
  font-size: clamp(1.6rem, 7vmin, 3rem);
  letter-spacing: 0.1em;
  color: var(--moon);
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.6);
}

.hiscore-line, .score-line, .snack-line {
  margin: 0;
  font-size: clamp(0.85rem, 3vmin, 1.15rem);
  letter-spacing: 0.12em;
  color: var(--ui-dim);
}

.score-line { color: var(--ui-text); font-size: clamp(1rem, 4vmin, 1.5rem); }

.new-record {
  margin: 0;
  color: var(--accent);
  font-size: clamp(1rem, 3.6vmin, 1.4rem);
  letter-spacing: 0.15em;
  animation: record-blink 0.9s steps(2, start) infinite;
}

@keyframes record-blink { 50% { opacity: 0.25; } }

.controls-help {
  color: var(--ui-dim);
  font-size: clamp(0.7rem, 2.4vmin, 0.95rem);
}
.controls-help p { margin: 0.3em 0; }

kbd {
  display: inline-block;
  padding: 0.05em 0.45em;
  border: 2px solid var(--panel-border);
  border-bottom-width: 3px;
  border-radius: 4px;
  background: var(--panel);
  font-family: inherit;
  font-size: 0.9em;
  color: var(--ui-text);
}

/* ---------- Buttons ---------- */

.pixel-btn {
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.1em;
  cursor: pointer;
  color: var(--night-deep);
  background: var(--accent);
  border: 0;
  border-radius: 4px;
  box-shadow:
    0 4px 0 var(--accent-hot),
    0 7px 0 rgba(0, 0, 0, 0.45);
  transition: transform 80ms ease, box-shadow 80ms ease;
  min-width: 44px;
  min-height: 44px;
}

.pixel-btn.big {
  font-size: clamp(1rem, 4vmin, 1.5rem);
  padding: 0.6em 1.6em;
}

.pixel-btn.small {
  font-size: clamp(0.7rem, 2.6vmin, 0.95rem);
  padding: 0.5em 1.1em;
  background: var(--panel);
  color: var(--ui-text);
  box-shadow:
    0 3px 0 var(--panel-border),
    0 5px 0 rgba(0, 0, 0, 0.45);
}

.pixel-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--accent-hot);
}
.pixel-btn.small:active { box-shadow: 0 1px 0 var(--panel-border); }

.pixel-btn:focus-visible,
.icon-btn:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 3px;
}

/* ---------- HUD ---------- */

#hud {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: clamp(6px, 1.6vmin, 14px);
  pointer-events: none;
}

#hud-left {
  display: flex;
  gap: clamp(8px, 2.5vmin, 24px);
  font-size: clamp(0.8rem, 3vmin, 1.2rem);
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--moon);
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.7);
}

#hud-hiscore { color: var(--ui-dim); }
#hud-snacks { color: var(--accent); }

#hud-right {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.icon-btn {
  font-family: inherit;
  font-size: clamp(0.9rem, 3vmin, 1.2rem);
  width: clamp(38px, 9vmin, 48px);
  height: clamp(38px, 9vmin, 48px);
  cursor: pointer;
  color: var(--ui-text);
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 6px;
  line-height: 1;
}
.icon-btn:active { transform: translateY(2px); }

/* ---------- Countdown ---------- */

#countdown {
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

#countdown-num {
  font-size: clamp(4rem, 20vmin, 9rem);
  font-weight: 700;
  color: var(--moon);
  text-shadow: 4px 4px 0 rgba(0, 0, 0, 0.6);
  animation: count-pop 1s ease infinite;
}

@keyframes count-pop {
  0%   { transform: scale(1.35); opacity: 0.2; }
  20%  { transform: scale(1);    opacity: 1; }
  85%  { opacity: 1; }
  100% { opacity: 0.1; }
}

/* ---------- Accessibility ---------- */

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  margin: -1px; padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .new-record { animation: none; }
  #countdown-num { animation: none; }
  .pixel-btn, .icon-btn { transition: none; }
}

/* ---------- One-thumb touch controls ---------- */

/* Show touch hints only on touch devices, keyboard hints only elsewhere. */
.touch-help { display: none; }
.key-help   { display: block; }
body.is-touch .touch-help { display: block; }
body.is-touch .key-help   { display: none; }

/* The whole frame is a jump target; the duck button carves out its corner. */
#touch-controls {
  pointer-events: none;               /* taps fall through to the game frame */
}

#tap-hint {
  position: absolute;
  top: 18%;
  left: 0;
  right: 0;
  text-align: center;
  color: var(--ui-text);
  opacity: 0.0;
  font-size: clamp(0.9rem, 4vmin, 1.4rem);
  letter-spacing: 0.18em;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.75);
  animation: tap-hint-fade 3.2s ease forwards;
}

@keyframes tap-hint-fade {
  0%   { opacity: 0; }
  12%  { opacity: 0.95; }
  70%  { opacity: 0.95; }
  100% { opacity: 0; }
}

.duck-btn {
  position: absolute;
  right: clamp(10px, 3vw, 26px);
  bottom: clamp(14px, 5vh, 40px);
  pointer-events: auto;               /* this one DOES take taps */
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.08em;
  font-size: clamp(0.9rem, 3.4vmin, 1.3rem);
  color: var(--ui-text);
  background: rgba(16, 16, 34, 0.72);
  border: 2px solid var(--panel-border);
  border-radius: 999px;
  padding: clamp(0.7em, 2.4vmin, 1em) clamp(1.1em, 4vmin, 1.6em);
  min-width: 88px;
  min-height: 64px;
  backdrop-filter: blur(2px);
  touch-action: none;
  user-select: none;
}
.duck-btn:active,
.duck-btn.held {
  transform: translateY(2px);
  background: var(--accent);
  color: var(--night-deep);
  border-color: var(--accent-hot);
}

/* Only surface the on-screen duck button on touch devices. */
body:not(.is-touch) .duck-btn { display: none; }

/* ---------- Buy me a coffee ---------- */

.title-actions {
  display: flex;
  gap: clamp(8px, 2.4vmin, 16px);
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.coffee-btn {
  display: inline-block;
  font-family: inherit;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
  font-size: clamp(0.7rem, 2.6vmin, 0.95rem);
  padding: 0.5em 1.1em;
  color: var(--night-deep);
  background: #ffdd66;
  border-radius: 4px;
  box-shadow: 0 3px 0 #d9a72a, 0 5px 0 rgba(0, 0, 0, 0.4);
  transition: transform 80ms ease, box-shadow 80ms ease;
  min-height: 44px;
  line-height: 1.9;
}
.coffee-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #d9a72a; }
.coffee-btn:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 3px; }
#link-coffee-go { margin-top: 4px; }

/* ---------- Audio settings panel ---------- */

#settings-panel { gap: clamp(10px, 2.6vmin, 22px); }

.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(88%, 360px);
  font-size: clamp(0.8rem, 3vmin, 1.05rem);
  letter-spacing: 0.1em;
  color: var(--ui-text);
}
.setting-row label {
  width: 4.2em;
  text-align: left;
  font-weight: 700;
  color: var(--moon);
}
.vol-val { width: 2.4em; text-align: right; color: var(--ui-dim); }

.vol-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 8px;
  border-radius: 4px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  outline: none;
  cursor: pointer;
}
.vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--accent-hot);
  cursor: pointer;
}
.vol-slider::-moz-range-thumb {
  width: 22px; height: 22px;
  border: 2px solid var(--accent-hot);
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.vol-slider:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 3px; }

/* ---------- Small landscape phones ---------- */

@media (max-height: 420px) {
  .screen { gap: 6px; padding: 2vmin; }
  .controls-help { display: none; }
  .duck-btn { bottom: 10px; min-height: 52px; }
}

@media (prefers-reduced-motion: reduce) {
  #tap-hint { animation: none; opacity: 0; }
}
