* {
  box-sizing: border-box;
}

/* Inner safe margins inside the playable area (matches white guide overlays) */
:root {
  --content-inset-top: 20px;
  --content-inset-right: 20px;
  --content-inset-bottom: 10px;
  --content-inset-left: 10px;
}

body {
  margin: 0;
  font-family:
    "Outfit",
    "Nunito",
    system-ui,
    -apple-system,
    "Segoe UI",
    Roboto,
    Arial,
    sans-serif;
  background: #ffffff;
  color: #0f4756;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  max-width: 100vw;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

.app {
  position: relative;
  width: 100%;
  max-width: 100vw;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  height: 100vh;
  height: 100svh;
  height: 100dvh;
  margin: 0;
  box-sizing: border-box;
  /* White “safe” frame; safe-area is applied here only (not doubled inside) */
  padding-top: max(var(--content-inset-top), env(safe-area-inset-top, 0px));
  padding-right: max(var(--content-inset-right), env(safe-area-inset-right, 0px));
  padding-bottom: max(var(--content-inset-bottom), env(safe-area-inset-bottom, 0px));
  padding-left: max(var(--content-inset-left), env(safe-area-inset-left, 0px));
  background: #ffffff;
  display: flex;
  flex-direction: column;
}

.playfield {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  border-radius: 18px;
  overflow: hidden;
  background-color: #0d5565;
  background-image:
    radial-gradient(
      ellipse 120% 100% at 50% 45%,
      rgba(58, 154, 170, 0.88) 0%,
      rgba(26, 117, 136, 0.9) 48%,
      rgba(13, 85, 101, 0.92) 100%
    ),
    url("./assets/bg.jpeg");
  background-size: cover;
  background-position: center;
  box-shadow:
    0 4px 28px rgba(13, 90, 99, 0.12),
    0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}


.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  /* Above overlays so timer/score placement is visible even on the menu */
  z-index: 15;
}

.hud-stat {
  position: absolute;
  width: min(150px, 30vw);
  pointer-events: none;
  filter: drop-shadow(0 6px 12px rgba(12, 70, 86, 0.4));
  transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.hud-stat__art {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
}

.hud-stat__value {
  position: absolute;
  right: 10%;
  top: 50%;
  transform: translateY(-50%);
  font-size: clamp(14px, 2.2vw, 18px);
  font-weight: 900;
  color: #ffffff;
  letter-spacing: 0.03em;
  text-shadow:
    0 0 4px rgba(12, 141, 177, 0.8),
    0 2px 4px rgba(0, 0, 0, 0.6);
  font-variant-numeric: tabular-nums;
}

.hud-stat__sub {
  position: absolute;
  left: 10%;
  bottom: -4px;
  font-size: clamp(8px, 1.4vw, 11px);
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-shadow:
    0 0 3px rgba(12, 141, 177, 0.9),
    0 2px 3px rgba(0, 0, 0, 0.8);
}

.hud-stat--time .hud-stat__value {
  color: #ffffff;
  font-size: clamp(15px, 2.4vw, 20px);
  right: 11%;
  text-shadow:
    0 0 4px rgba(12, 141, 177, 0.8),
    0 2px 4px rgba(0, 0, 0, 0.6);
}

.hud-stat--time .hud-stat__sub {
  color: #fff;
  font-size: clamp(9px, 1.55vw, 12px);
  text-shadow:
    0 0 3px rgba(12, 141, 177, 0.9),
    0 2px 3px rgba(0, 0, 0, 0.8);
}

.score-bump {
  animation: bump 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes bump {
  0% { transform: scale(1); }
  50% { transform: scale(1.15) rotate(-2deg); }
  100% { transform: scale(1); }
}

/* Insets inside the playfield (outer safe-area is on .app padding) */
.hud-stat--time {
  left: var(--content-inset-left);
  top: var(--content-inset-top);
  width: min(210px, 40vw);
}

.hud-stat--score {
  right: var(--content-inset-right);
  top: var(--content-inset-top);
  left: auto;
  width: min(210px, 40vw);
}

.hud-stat--score .hud-stat__value {
  color: #ffffff;
  font-size: clamp(15px, 2.4vw, 20px);
  right: 11%;
}

.fullscreen-btn {
  position: absolute;
  right: var(--content-inset-right);
  bottom: var(--content-inset-bottom);
  z-index: 16;
  width: auto;
  max-width: min(200px, 45vw);
  margin-top: 0;
  padding: 10px 18px;
  font-size: clamp(11px, 2.4vw, 14px);
  pointer-events: auto;
  text-transform: none;
  letter-spacing: 0.02em;
}

.panel-logo {
  display: block;
  max-width: 180px;
  width: min(60%, 200px);
  height: auto;
  margin: 0 auto 10px;
}

.panel-logo--small {
  max-width: 140px;
  width: min(50%, 160px);
  margin-bottom: 8px;
}

#gameCanvas {
  display: block;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  background: transparent;
  z-index: 1;
}

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(10, 49, 58, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 14;
}

.overlay.visible {
  display: flex;
}

.panel {
  max-width: 520px;
  width: 100%;
  padding: 20px 24px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: 28px;
  color: #15586a;
  box-shadow:
    0 12px 40px rgba(6, 55, 70, 0.15),
    0 24px 60px rgba(6, 76, 95, 0.2),
    inset 0 0 0 1px rgba(255, 255, 255, 0.6);
  max-height: 98vh;
  overflow-y: hidden;
}

.panel h1,
.panel h2 {
  margin-top: 0;
  margin-bottom: 6px;
}

.panel h1 {
  font-size: clamp(1.15rem, 3vw, 1.35rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.panel-subtitle {
  margin: 0 0 6px;
  font-size: clamp(0.85rem, 2.5vw, 0.95rem);
  font-weight: 800;
  color: #0e7a8f;
  letter-spacing: 0.02em;
}

.panel h2 {
  font-size: clamp(1.1rem, 3vw, 1.25rem);
}

.panel p {
  line-height: 1.3;
  margin: 0.3rem 0;
  font-size: 0.9rem;
}

#resultMessage {
  font-weight: 700;
}

.panel ul {
  margin: 6px 0 12px;
  padding-left: 1.15rem;
  line-height: 1.3;
  font-size: 0.85rem;
}

.panel li + li {
  margin-top: 0.2rem;
}

button {
  border: none;
  border-radius: 40px;
  background: linear-gradient(90deg, #1bd1f0, #0c8db1);
  color: white;
  font-weight: 900;
  padding: 14px 24px;
  cursor: pointer;
  font-size: 1.1rem;
  width: 100%;
  max-width: 100%;
  margin-top: 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  box-shadow: 
    0 6px 16px rgba(12, 141, 177, 0.4),
    inset 0 2px 0 rgba(255, 255, 255, 0.3);
}

button:hover {
  background: linear-gradient(90deg, #27e0ff, #0a7a99);
  transform: translateY(-3px);
  box-shadow: 
    0 10px 20px rgba(12, 141, 177, 0.5),
    inset 0 2px 0 rgba(255, 255, 255, 0.4);
}

button:active {
  transform: translateY(2px) scale(0.96);
  box-shadow: 0 2px 8px rgba(12, 141, 177, 0.3);
}

button:focus {
  outline: none;
}

button:focus-visible {
  outline: 3px solid #29b4b7;
  outline-offset: 3px;
}

.hint {
  font-size: 0.9rem;
  color: #2d7c87;
  margin-top: 14px;
  margin-bottom: 0;
  text-align: center;
  line-height: 1.4;
}

.start-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.start-actions button {
  margin-top: 0;
}

kbd {
  display: inline-block;
  padding: 0.1em 0.45em;
  font-family: inherit;
  font-size: 0.88em;
  font-weight: 800;
  line-height: 1.35;
  color: #0f4756;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(20, 120, 140, 0.45);
  border-radius: 6px;
  box-shadow: 0 1px 0 rgba(20, 120, 140, 0.2);
}

.app.keyboard-mode #webcam,
.app.keyboard-mode #handOverlay {
  display: none;
}

#webcam {
  position: absolute;
  right: var(--content-inset-right);
  bottom: var(--content-inset-bottom);
  width: 220px;
  height: 124px;
  border: 1px solid rgba(100, 200, 210, 0.75);
  border-radius: 12px;
  object-fit: cover;
  opacity: 0.96;
  z-index: 5;
  box-shadow:
    0 4px 20px rgba(8, 60, 72, 0.25),
    0 0 0 1px rgba(255, 255, 255, 0.35) inset;
}

#handOverlay {
  position: absolute;
  right: var(--content-inset-right);
  bottom: var(--content-inset-bottom);
  width: 220px;
  height: 124px;
  border-radius: 12px;
  object-fit: cover;
  object-position: center;
  pointer-events: none;
  z-index: 6;
}

@media (prefers-reduced-motion: reduce) {
  button {
    transition: none;
  }

  button:active {
    transform: none;
  }
}

@media (max-width: 700px) {
  .app {
    min-height: 100dvh;
    height: 100dvh;
  }

  #gameCanvas {
    height: 100%;
    max-height: none;
  }

  .hud {
    inset: 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    box-sizing: border-box;
    padding-top: var(--content-inset-top);
    padding-right: var(--content-inset-right);
    padding-left: var(--content-inset-left);
    pointer-events: none;
  }

  .hud-stat {
    position: static;
    width: min(130px, 40vw);
  }

  .hud-stat--time,
  .hud-stat--score {
    width: min(175px, 52vw);
  }

  /* Reset desktop absolute offsets — flex + padding defines placement */
  .hud-stat--time {
    left: auto;
    top: auto;
  }

  .hud-stat--score {
    right: auto;
    top: auto;
  }

  .hud-stat__value {
    font-size: clamp(12px, 3.5vw, 14px);
    right: 12%;
  }

  .hud-stat--time .hud-stat__value,
  .hud-stat--score .hud-stat__value {
    font-size: clamp(13px, 4vw, 16px);
    right: 11%;
  }

  .hud-stat__sub {
    font-size: clamp(8px, 2.5vw, 10px);
    bottom: -2px;
    left: 8%;
  }

  .hud-stat--time .hud-stat__sub {
    font-size: clamp(8px, 2.75vw, 11px);
  }

  #webcam,
  #handOverlay {
    width: 120px;
    height: 68px;
    right: var(--content-inset-right);
    bottom: var(--content-inset-bottom);
    border-radius: 10px;
  }

  .panel {
    margin: 0 12px;
    padding: 24px 20px;
    max-width: none;
  }
}

@media (max-width: 420px) {
  #webcam,
  #handOverlay {
    width: 98px;
    height: 56px;
  }
}
