/* ============================================================ base ==== */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #0d1b24;
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#app { position: relative; width: 100%; height: 100%; overflow: hidden; }

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;      /* no page scroll / pinch while dragging */
  cursor: crosshair;
}

.hidden { display: none !important; }

/* ========================================================== buttons == */
.btn {
  appearance: none;
  border: 2px solid rgba(255, 255, 255, .22);
  background: linear-gradient(#4a6f8a, #33526a);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  padding: 10px 18px;
  border-radius: 12px;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .28), 0 6px 14px rgba(0, 0, 0, .22);
  transition: transform .08s ease, filter .12s ease, box-shadow .12s ease;
  min-height: 42px;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { filter: brightness(1.12); transform: translateY(-1px); }
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.28); }
.btn:focus-visible { outline: 3px solid #ffe07a; outline-offset: 2px; }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

.btn-primary { background: linear-gradient(#ff9f43, #f2711c); border-color: rgba(255,255,255,.35); }
.btn-danger  { background: linear-gradient(#e35d5b, #b83230); }
.btn-ghost   { background: rgba(12, 24, 33, .55); border-color: rgba(255,255,255,.18); }
.btn-lg { font-size: 18px; padding: 14px 26px; min-height: 52px; }
.btn-sm { font-size: 13px; padding: 7px 14px; min-height: 34px; }
.btn.off { opacity: .72; }

kbd {
  background: rgba(255,255,255,.16);
  border: 1px solid rgba(255,255,255,.28);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 1px 6px;
  font-size: .88em;
  font-family: ui-monospace, monospace;
}

/* ============================================================= HUD === */
.hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 10px 12px;
  z-index: 5;
}
.hud-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.hud-bottom { align-items: flex-end; }
.hud-group { display: flex; gap: 8px; flex-wrap: wrap; pointer-events: auto; }
.hud-group .btn { padding: 8px 12px; min-height: 38px; font-size: 13px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(10, 22, 31, .62);
  border: 1px solid rgba(255, 255, 255, .16);
  border-radius: 999px;
  padding: 7px 14px;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: .3px;
  backdrop-filter: blur(3px);
}
.chip-score { color: #ffe27a; min-width: 92px; justify-content: center; }

.bird-rail { display: flex; gap: 6px; align-items: center; pointer-events: none; }
.bird-pip {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.55);
  display: inline-block;
  box-shadow: 0 2px 4px rgba(0,0,0,.3);
}
.bird-pip.red    { background: #e8453c; }
.bird-pip.yellow { background: #f7d02c; }
.bird-pip.black  { background: #2f3338; }
.bird-pip.used   { opacity: .22; filter: grayscale(1); }
.bird-pip.cur    { transform: scale(1.22); border-color: #fff; }

.hint {
  pointer-events: none;
  max-width: 62%;
  margin-left: auto;
  text-align: right;
  background: rgba(10, 22, 31, .55);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.45;
  color: #e8f4ff;
}

/* ========================================================= screens == */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  z-index: 20;
  background: radial-gradient(ellipse at 50% 30%, rgba(10,28,42,.55), rgba(4,12,20,.86));
  backdrop-filter: blur(2px);
  overflow: auto;
}

.panel {
  background: linear-gradient(160deg, rgba(28,52,72,.96), rgba(15,30,44,.97));
  border: 2px solid rgba(255,255,255,.14);
  border-radius: 20px;
  padding: 26px 28px;
  box-shadow: 0 18px 50px rgba(0,0,0,.5);
  max-width: 92vw;
  max-height: 92vh;
  overflow: auto;
}
.panel-narrow { width: 420px; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 16px; flex-wrap: wrap;
}
.panel-title { margin: 0; font-size: 22px; letter-spacing: 1px; }

.game-title {
  margin: 0 0 4px;
  font-size: 54px;
  letter-spacing: 4px;
  text-shadow: 0 4px 0 rgba(0,0,0,.28), 0 10px 26px rgba(0,0,0,.4);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.game-title .title-sub {
  font-size: 15px; letter-spacing: 8px; opacity: .72; font-weight: 600;
}
.tagline { margin: 0 0 18px; text-align: center; opacity: .85; font-size: 15px; }
.foot { margin: 18px 0 0; text-align: center; opacity: .6; font-size: 13px; }
.btn-col { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row-center { justify-content: center; margin-top: 18px; }
.panel-home { text-align: center; width: 460px; }

/* ------------------------------------------------------ level select - */
.level-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(96px, 1fr));
  gap: 12px;
}
.level-card {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 12px 8px 10px;
  border-radius: 14px;
  border: 2px solid rgba(255,255,255,.18);
  background: linear-gradient(160deg, #3f6a86, #24445c);
  color: #fff;
  cursor: pointer;
  min-height: 108px;
  transition: transform .1s ease, filter .12s ease;
  box-shadow: 0 4px 0 rgba(0,0,0,.25);
}
.level-card:hover:not(:disabled) { transform: translateY(-2px); filter: brightness(1.12); }
.level-card:active:not(:disabled) { transform: translateY(2px); box-shadow: none; }
.level-card:focus-visible { outline: 3px solid #ffe07a; outline-offset: 2px; }
.level-card.locked { background: linear-gradient(160deg, #33414c, #222c34); opacity: .62; cursor: not-allowed; }
.lv-num { font-size: 24px; font-weight: 800; line-height: 1; }
.lv-name { font-size: 13px; opacity: .92; text-align: center; }
.lv-stars { font-size: 14px; letter-spacing: 1px; }
.lv-stars .star { color: rgba(255,255,255,.25); }
.lv-stars .star.on { color: #ffd75e; text-shadow: 0 0 8px rgba(255,215,94,.55); }
.lv-score { font-size: 12px; opacity: .7; color: #ffe27a; }
.lv-lock { position: absolute; top: 8px; right: 10px; font-size: 14px; }

/* ---------------------------------------------------------- result -- */
.panel-result { width: 460px; text-align: center; }
.title { margin: 0 0 8px; font-size: 30px; }
.title.win { color: #8ce99a; text-shadow: 0 3px 0 rgba(0,0,0,.25); }
.title.lose { color: #ff9b9b; }
.stars { display: flex; justify-content: center; gap: 10px; margin: 6px 0 10px; }
.big-star { font-size: 40px; color: rgba(255,255,255,.2); transition: transform .2s ease; }
.big-star.on {
  color: #ffd75e;
  text-shadow: 0 0 14px rgba(255,215,94,.7);
  animation: pop .38s ease both;
}
@keyframes pop {
  0% { transform: scale(.2) rotate(-25deg); opacity: 0; }
  70% { transform: scale(1.25) rotate(6deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); }
}
.score-big { font-size: 40px; font-weight: 800; color: #ffe27a; line-height: 1.1; }
.score-best { font-size: 13px; opacity: .7; margin-bottom: 14px; }
.breakdown {
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;
  padding: 10px 14px;
  text-align: left;
}
.bd-row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 14px; }
.bd-row + .bd-row { border-top: 1px dashed rgba(255,255,255,.12); }
.bd-row b { color: #ffe27a; }

.panel-complete { text-align: center; }
.complete-stats { display: flex; gap: 18px; justify-content: center; margin: 16px 0 20px; }
.complete-stats > div { display: flex; flex-direction: column; }
.cs-num { font-size: 34px; font-weight: 800; color: #ffe27a; }
.cs-label { font-size: 12px; opacity: .7; }

/* ========================================================= modals === */
.modal {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 10, 16, .72);
  z-index: 40;
  padding: 16px;
}
.modal-card {
  background: linear-gradient(160deg, rgba(30,56,78,.98), rgba(16,32,46,.98));
  border: 2px solid rgba(255,255,255,.16);
  border-radius: 18px;
  padding: 22px 24px;
  max-width: 560px;
  width: 100%;
  max-height: 88vh;
  overflow: auto;
  box-shadow: 0 18px 50px rgba(0,0,0,.55);
}
.modal-card h3 { margin: 0 0 12px; font-size: 20px; }
.modal-card p { margin: 0 0 16px; opacity: .9; line-height: 1.6; }
.help-list { margin: 0 0 18px; padding-left: 20px; line-height: 1.8; font-size: 14px; }
.help-list li { margin-bottom: 4px; }

/* ========================================================== toast === */
.toast {
  position: absolute;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%) translateY(20px);
  background: rgba(8, 20, 30, .88);
  border: 1px solid rgba(255,255,255,.2);
  color: #eaf6ff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
  z-index: 60;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ==================================================== responsive ==== */
@media (max-width: 900px) {
  .level-grid { grid-template-columns: repeat(4, minmax(84px, 1fr)); }
  .game-title { font-size: 42px; }
  .hint { max-width: 58%; font-size: 12px; }
}

@media (max-width: 640px) {
  .panel { padding: 18px 16px; border-radius: 16px; }
  .panel-home, .panel-result, .panel-narrow { width: 100%; }
  .btn-row > .btn { flex: 1 1 0; }
  .game-title { font-size: 32px; letter-spacing: 2px; }
  .game-title .title-sub { font-size: 12px; letter-spacing: 5px; }
  .level-grid { grid-template-columns: repeat(3, minmax(78px, 1fr)); gap: 8px; }
  .level-card { min-height: 92px; }
  .lv-name { font-size: 12px; }
  .hud { padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  .hud-group { gap: 6px; }
  .hud-group .btn { padding: 7px 10px; font-size: 12px; min-height: 38px; }
  .chip { padding: 5px 10px; font-size: 12px; }
  .hint { max-width: 100%; margin-left: 0; font-size: 12px; }
  .hud-bottom { flex-direction: column; align-items: stretch; gap: 6px; }
  .score-big { font-size: 32px; }
  .big-star { font-size: 32px; }
  .btn-lg { font-size: 16px; padding: 12px 18px; min-height: 46px; }
}

/* Short viewports (landscape phones): keep everything reachable */
@media (max-height: 460px) {
  .panel { padding: 14px 16px; }
  .game-title { font-size: 26px; margin-bottom: 2px; }
  .tagline { margin-bottom: 10px; font-size: 13px; }
  .foot { display: none; }
  .btn-col { gap: 8px; }
  .btn-lg { min-height: 42px; padding: 10px 16px; font-size: 15px; }
  .complete-stats { margin: 8px 0 12px; }
}

/* Portrait phones: the play field is small, so nudge the player to rotate
   but keep every control usable either way. */
@media (max-width: 520px) and (orientation: portrait) {
  .screen { align-items: flex-start; }
  .panel { margin-top: 8px; }
}
