/* styles.css */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at top, #1a2550 0%, #050814 60%, #000000 100%);
  color: #f5f7ff;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

body {
  display: flex;
  align-items: center;
  justify-content: center;
  /* Respect notch/home-bar on modern phones when viewport-fit=cover */
  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));
}

#game-container {
  max-width: 1400px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: stretch;
}

/* HUD */

#hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 16px;
  background: linear-gradient(90deg, rgba(10, 12, 30, 0.9), rgba(30, 40, 80, 0.9));
  border-radius: 999px;
  box-shadow: 0 0 20px rgba(0, 180, 255, 0.35);
  backdrop-filter: blur(10px);
}

.hud-item {
  display: flex;
  flex-direction: column;
  min-width: 70px;
}

.hud-item .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  opacity: 0.7;
}

.hud-item span:last-child {
  font-size: 18px;
  font-weight: 600;
}

/* Play button */

#playButton {
  padding: 10px 20px;
  border-radius: 999px;
  border: none;
  background: radial-gradient(circle at 20% 0%, #4cf0ff 0%, #0a96ff 45%, #1845ff 100%);
  color: #fdfcff;
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  cursor: pointer;
  box-shadow:
    0 0 20px rgba(51, 211, 255, 0.8),
    0 0 40px rgba(19, 118, 255, 0.6);
  transition: transform 0.08s ease, box-shadow 0.08s ease, filter 0.08s ease;
  white-space: nowrap;
}

#playButton:hover {
  transform: translateY(-1px) scale(1.02);
  filter: brightness(1.05);
}

#playButton:active {
  transform: translateY(1px) scale(0.98);
  box-shadow:
    0 0 6px rgba(51, 211, 255, 0.6),
    0 0 12px rgba(19, 118, 255, 0.5);
}

/* Canvas frame */

#canvas-wrapper {
  display: flex;
  justify-content: center;
}

#canvas-frame {
  position: relative;
  padding: 10px;
  border-radius: 32px;
  background:
    radial-gradient(circle at 0% 0%, rgba(0, 255, 255, 0.3), transparent 60%),
    radial-gradient(circle at 100% 100%, rgba(198, 111, 255, 0.25), transparent 60%),
    linear-gradient(145deg, #0e101f, #141a33);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 0 40px rgba(0, 0, 0, 0.9),
    0 0 80px rgba(12, 183, 255, 0.4);
}

#canvas-frame::before {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  pointer-events: none;
  box-shadow:
    inset 0 0 40px rgba(255, 255, 255, 0.06),
    0 0 40px rgba(0, 0, 0, 0.9);
}

#gameCanvas {
  display: block;
  width: 100%;
  height: auto;
  max-width: 1400px;
  border-radius: 20px;
  background: radial-gradient(circle at 20% 0%, #344a7f, #050814 70%);
}

/* Message panel */

#message-panel {
  padding: 14px 16px 16px;
  border-radius: 18px;
  background: radial-gradient(circle at 0 0, rgba(107, 220, 255, 0.2), transparent 55%),
    radial-gradient(circle at 100% 100%, rgba(167, 110, 255, 0.25), transparent 55%),
    rgba(6, 9, 25, 0.9);
  box-shadow: 0 0 26px rgba(0, 0, 0, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

#message-panel h2 {
  font-size: 18px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  opacity: 0.8;
  margin-bottom: 6px;
}

#message-panel p {
  line-height: 1.5;
  font-size: 14px;
  color: #e5edff;
}

/* Mobile controls */

#mobile-controls {
  display: none; /* shown via JS on touch devices */
  margin-top: 12px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  touch-action: none;
}

#joystick-container {
  flex: 1;
  display: flex;
  justify-content: flex-start;
}

#joystick-base {
  position: relative;
  width: 110px;
  height: 110px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: radial-gradient(circle at 30% 0, rgba(255, 255, 255, 0.25), rgba(30, 45, 100, 0.96));
  box-shadow:
    0 6px 14px rgba(0, 0, 0, 0.7),
    0 0 14px rgba(141, 197, 255, 0.7);
  backdrop-filter: blur(10px);
  margin-left: 8px;
  touch-action: none;
}

#joystick-handle {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle at 30% 0, rgba(255, 255, 255, 0.7), rgba(60, 110, 200, 0.95));
  box-shadow:
    0 4px 10px rgba(0, 0, 0, 0.7),
    0 0 10px rgba(141, 197, 255, 0.9);
  pointer-events: none;
}

.control-group {
  display: flex;
  gap: 10px;
}

.control-group-vertical {
  flex-direction: column;
  align-items: flex-end;
}

/* Buttons */

.control-button {
  width: 64px;
  height: 64px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: radial-gradient(circle at 30% 0, rgba(255, 255, 255, 0.3), rgba(40, 60, 130, 0.95));
  color: #fdfcff;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 6px 14px rgba(0, 0, 0, 0.7),
    0 0 10px rgba(141, 197, 255, 0.7);
  backdrop-filter: blur(10px);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.07s ease, box-shadow 0.07s ease, background 0.07s ease;
  margin-right: 8px;
}

.control-button:active,
.control-button.is-pressed {
  transform: translateY(2px) scale(0.96);
  box-shadow:
    0 2px 6px rgba(0, 0, 0, 0.8),
    0 0 4px rgba(141, 197, 255, 0.9);
  background: radial-gradient(circle at 50% 20%, rgba(255, 255, 255, 0.25), rgba(20, 40, 90, 0.95));
}

/* Responsive */

@media (max-width: 900px) {
  #hud {
    flex-wrap: wrap;
    border-radius: 24px;
  }

  #canvas-frame {
    padding: 8px;
    border-radius: 24px;
  }

  #gameCanvas {
    border-radius: 16px;
  }

  #message-panel {
    border-radius: 16px;
    font-size: 13px;
  }

  #mobile-controls {
    display: flex;
  }
}

@media (max-width: 600px) {
  body {
    padding: 8px;
  }

  #hud {
    gap: 6px;
  }

  .hud-item span:last-child {
    font-size: 16px;
  }

  #playButton {
    font-size: 14px;
    padding: 8px 14px;
  }

  .control-button {
    width: 60px;
    height: 60px;
    font-size: 22px;
  }

  #joystick-base {
    width: 96px;
    height: 96px;
  }

  #joystick-handle {
    width: 50px;
    height: 50px;
  }
}

/* ── Game-active state hides DOM chrome ── */
body.game-active #playButton   { display: none; }
body.game-active #message-panel { display: none; }

/* ── Name-entry modal ── */
#name-entry {
  display: none;
  position: fixed; inset: 0; z-index: 9998;
  background: rgba(4, 6, 20, 0.88);
  align-items: center; justify-content: center;
}
#name-entry.visible { display: flex; }
#name-entry-inner {
  background: linear-gradient(145deg, #0e1025, #1a2244);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  padding: 28px 32px;
  text-align: center;
  max-width: 360px; width: 90%;
  box-shadow: 0 0 60px rgba(0,150,255,0.3);
  display: flex; flex-direction: column; gap: 12px;
}
#name-entry-inner h3 { font-size: 1.3rem; letter-spacing: 0.1em; color: #ffcc66; }
#name-entry-inner p  { font-size: 0.9rem; color: #c0c8e8; line-height: 1.5; }
#player-name-input {
  padding: 10px 14px; border-radius: 10px;
  background: rgba(255,255,255,0.08); border: 1px solid rgba(255,255,255,0.2);
  color: #f5f7ff; font-size: 1rem; outline: none; width: 100%;
}
#player-name-input:focus { border-color: rgba(100,180,255,0.6); }
.name-entry-btns { display: flex; gap: 10px; justify-content: center; }
.name-entry-btns button {
  padding: 9px 22px; border-radius: 999px; border: none; cursor: pointer;
  font-weight: 700; font-size: 0.9rem;
}
#name-entry-submit {
  background: radial-gradient(circle at 20% 0%, #4cf0ff 0%, #0a96ff 50%, #1845ff 100%);
  color: #fff;
  box-shadow: 0 0 16px rgba(51,211,255,0.6);
}
#name-entry-skip { background: rgba(255,255,255,0.1); color: #b0bcd0; }

/* ═══════════════════════════════════════════════════════════════════════════
   PHONE LANDSCAPE  (short viewport — typically phones rotated sideways)
   Canvas fills available height; HUD compresses; message panel hidden.
   ═══════════════════════════════════════════════════════════════════════════ */
@media (orientation: landscape) and (max-height: 500px) {
  html, body {
    height: 100%;
    overflow: hidden;
  }

  body {
    align-items: flex-start;
    /* Trim default padding; respect notch insets */
    padding: max(3px, env(safe-area-inset-top))
             max(6px, env(safe-area-inset-right))
             max(3px, env(safe-area-inset-bottom))
             max(6px, env(safe-area-inset-left));
  }

  #game-container {
    height: 100%;
    gap: 3px;
    max-width: 100%;
    /* Prevent bottom overflow */
    overflow: hidden;
  }

  /* Compact HUD bar */
  #hud {
    flex-shrink: 0;
    flex-wrap: nowrap;
    padding: 4px 10px;
    border-radius: 10px;
    gap: 5px;
  }

  .hud-item {
    min-width: 36px;
  }

  .hud-item .label {
    font-size: 8px;
    letter-spacing: 0.04em;
  }

  .hud-item span:last-child {
    font-size: 12px;
  }

  #hud-daughters { gap: 3px; }

  .daughter-dot {
    width: 14px;
    height: 14px;
    font-size: 6px;
  }

  #love-bar-wrap { min-width: 52px; }
  #love-bar-bg   { height: 5px; }
  #spark-label   { font-size: 8px; }

  #playButton {
    font-size: 11px;
    padding: 5px 10px;
  }

  /* Canvas wrapper fills remaining height */
  #canvas-wrapper {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    align-items: stretch;
  }

  #canvas-frame {
    flex: 1;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 3px;
    border-radius: 12px;
  }

  /* Drive size by height so aspect ratio is preserved naturally */
  #gameCanvas {
    width: auto;
    height: 100%;
    max-width: 100%;
    border-radius: 8px;
  }

  /* Story text wastes precious vertical space — hide it */
  #message-panel { display: none; }

  /* Back link overlaps controls — hide on small screens */
  #anaubi-back { display: none; }

  /* Mobile overlay controls are shown by JS; CSS just ensures display is correct */
  #mobile-controls { display: flex; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   TABLET  (portrait & landscape, 601 – 1100 px wide)
   Show touch controls; canvas already scales fine via width: 100%.
   ═══════════════════════════════════════════════════════════════════════════ */
@media (min-width: 601px) and (max-width: 1100px) {
  #mobile-controls { display: flex; }
}