/* ==========================================================================
   Disgruntled Pigeons — seaside-signwriting styling
   ========================================================================== */

:root {
  --ink:      #23303a;
  --paper:    #fdf6e6;
  --sky:      #7fc0dd;
  --sea:      #35708c;
  --sand:     #e8d3a9;
  --tomato:   #d9503f;
  --mustard:  #f0b431;
  --leaf:     #4f8f5c;
  --shadow:   0 10px 30px rgba(20, 30, 40, .35);
  --font:     "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #12212b;
  font-family: var(--font);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

.app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ── HUD ──────────────────────────────────────────────────────────────── */

#hud {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: linear-gradient(180deg, #2b4356, #22323f);
  color: var(--paper);
  border-bottom: 3px solid #16232c;
  z-index: 6;
  flex: none;
}
#hud.show { display: flex; }

.hud-mid {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#level-name {
  font-weight: 700;
  font-size: clamp(.8rem, 2.4vw, 1rem);
  letter-spacing: .02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: .95;
}

#bird-strip {
  display: flex;
  gap: 2px;
  align-items: center;
  height: 30px;
  overflow: hidden;
}
.bird-chip {
  width: 34px;
  height: 34px;
  flex: none;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.4));
}
.bird-chip:first-child {
  transform: scale(1.18);
  filter: drop-shadow(0 0 6px rgba(255, 220, 120, .8));
}

.hud-score {
  text-align: right;
  line-height: 1;
  flex: none;
}
.hud-score #score {
  display: block;
  font-size: clamp(1.05rem, 3.4vw, 1.5rem);
  font-weight: 700;
  color: var(--mustard);
  font-variant-numeric: tabular-nums;
}
.hud-score small {
  font-size: .6rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  opacity: .6;
}

.icon-btn {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  border: 2px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.10);
  color: var(--paper);
  font-size: 1rem;
  cursor: pointer;
  transition: transform .1s, background .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.2); }
.icon-btn:active { transform: scale(.93); }
.icon-btn.off { opacity: .45; }

/* ── stage & canvas ───────────────────────────────────────────────────── */

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background: #9fd0ea;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}
#game:active { cursor: grabbing; }

/* ── screens ──────────────────────────────────────────────────────────── */

.screen {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: auto;
  z-index: 4;
}
.screen.active { display: flex; }
#screen-play.active { display: none; }

#screen-title {
  background:
    radial-gradient(120% 80% at 50% 0%, #a9dcf0 0%, #7fc0dd 45%, #4d94b4 100%);
}
#screen-levels {
  background:
    radial-gradient(120% 90% at 50% 0%, #2f4a5e 0%, #1d2e3a 70%);
}

.title-card {
  text-align: center;
  color: var(--paper);
  max-width: 460px;
  animation: rise .5s ease-out;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

#title-bird { display: block; margin: 0 auto -6px; }

.title-card h1 {
  margin: 0 0 4px;
  font-size: clamp(2.1rem, 8.5vw, 3.4rem);
  line-height: .95;
  letter-spacing: -.02em;
  text-transform: uppercase;
  color: var(--paper);
  text-shadow: 0 3px 0 #2c5468, 0 6px 16px rgba(0,0,0,.35);
}
.title-card h1 em {
  font-style: normal;
  color: var(--mustard);
  text-shadow: 0 3px 0 #a3701a, 0 6px 16px rgba(0,0,0,.35);
}
.tagline {
  margin: 6px 0 20px;
  font-size: clamp(.85rem, 3vw, 1rem);
  opacity: .92;
  text-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.credit {
  margin-top: 18px;
  font-size: .68rem;
  letter-spacing: .04em;
  opacity: .65;
}

/* ── buttons ──────────────────────────────────────────────────────────── */

.btn-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}
.small-row { margin-top: 10px; }
.btn-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

button {
  font-family: var(--font);
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: transform .1s ease, filter .15s ease;
}
button:active { transform: translateY(2px) scale(.99); }
button:disabled { cursor: not-allowed; }

.big {
  padding: 13px 30px;
  font-size: 1.05rem;
  border-radius: 12px;
  background: linear-gradient(180deg, #e8624f, var(--tomato));
  color: #fff;
  box-shadow: 0 4px 0 #9c3527, 0 8px 18px rgba(0,0,0,.25);
  letter-spacing: .02em;
}
.big:hover { filter: brightness(1.06); }
.big:active { box-shadow: 0 2px 0 #9c3527; }

.ghost {
  padding: 11px 22px;
  font-size: .92rem;
  border-radius: 11px;
  background: rgba(255,255,255,.14);
  border: 2px solid rgba(255,255,255,.35);
  color: var(--paper);
  box-shadow: 0 3px 0 rgba(0,0,0,.18);
}
.ghost:hover { background: rgba(255,255,255,.24); }
.ghost.tiny { padding: 7px 14px; font-size: .76rem; opacity: .7; }

/* ── panels ───────────────────────────────────────────────────────────── */

.panel {
  background: var(--paper);
  color: var(--ink);
  border-radius: 18px;
  padding: 22px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
  border: 3px solid #2b3d4a;
  animation: pop .28s cubic-bezier(.2, 1.4, .5, 1);
}
.panel.wide { max-width: 700px; }
@keyframes pop { from { opacity: 0; transform: scale(.9); } }

.panel h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.panel h3 {
  margin: 18px 0 8px;
  font-size: .95rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  opacity: .6;
}
.panel .ghost { color: var(--ink); border-color: rgba(35,48,58,.3); background: rgba(35,48,58,.07); }
.panel .ghost:hover { background: rgba(35,48,58,.14); }

.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.panel-head h2 { flex: 1; margin: 0; }
.panel-foot { margin-top: 14px; }
.star-count { font-size: .85rem; font-weight: 700; color: #b8862a; white-space: nowrap; }

.muted { font-size: .78rem; opacity: .6; margin: 4px 0 0; }

#result-title.win  { color: var(--leaf); }
#result-title.lose { color: var(--tomato); }

.score-big {
  font-size: 2.4rem;
  font-weight: 700;
  color: #b8862a;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  margin: 6px 0;
}

.stars-big { font-size: 2.4rem; letter-spacing: .1em; height: 1.2em; }
.star { color: rgba(35,48,58,.16); display: inline-block; transition: color .2s; }
.star.on { color: var(--mustard); text-shadow: 0 0 14px rgba(240,180,49,.7); }
.star.pop { animation: starpop .45s cubic-bezier(.2, 1.6, .4, 1); }
@keyframes starpop {
  0%   { transform: scale(0) rotate(-140deg); }
  70%  { transform: scale(1.35) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}

/* ── level grid ───────────────────────────────────────────────────────── */

#level-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 8px;
  max-height: 58vh;
  overflow-y: auto;
  padding: 2px;
}

.level-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 6px 7px;
  border-radius: 12px;
  background: linear-gradient(180deg, #fff, #f0e6d0);
  border: 2px solid #cbb894;
  box-shadow: 0 3px 0 #c3b08c;
  color: var(--ink);
  text-align: center;
}
.level-tile:hover { filter: brightness(1.03); }
.level-tile.locked {
  background: #ded6c6;
  color: rgba(35,48,58,.35);
  box-shadow: none;
  border-color: #cfc5b2;
}
.level-tile.locked .lv-name::after { content: ' 🔒'; }
.lv-num { font-size: 1.15rem; font-weight: 700; line-height: 1; }
.lv-name {
  font-size: .62rem;
  font-weight: 600;
  line-height: 1.15;
  opacity: .75;
  min-height: 2.3em;
  display: flex;
  align-items: center;
}
.lv-stars { font-size: .78rem; letter-spacing: .04em; }

/* ── how-to ───────────────────────────────────────────────────────────── */

.howto {
  text-align: left;
  margin: 0;
  padding-left: 20px;
  font-size: .88rem;
  line-height: 1.55;
}
.howto li { margin-bottom: 7px; }
kbd {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: .78em;
  background: rgba(35,48,58,.1);
  border: 1px solid rgba(35,48,58,.2);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
}

#roster {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 6px;
  text-align: left;
}
.roster-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 10px;
  background: rgba(35,48,58,.05);
}
.roster-row canvas { flex: none; }
.roster-row strong { display: block; font-size: .9rem; }
.roster-row span { font-size: .74rem; opacity: .7; line-height: 1.3; }

/* ── overlays ─────────────────────────────────────────────────────────── */

.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(16, 28, 36, .72);
  backdrop-filter: blur(3px);
  z-index: 8;
  overflow: auto;
}
.overlay.show { display: flex; }

/* ── in-game hint toast ───────────────────────────────────────────────── */

#hint {
  position: absolute;
  left: 50%;
  top: 14px;
  transform: translate(-50%, -140%);
  background: rgba(22, 34, 44, .88);
  color: var(--paper);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 600;
  max-width: 84%;
  text-align: center;
  pointer-events: none;
  transition: transform .45s cubic-bezier(.2, 1.3, .4, 1), opacity .45s;
  opacity: 0;
  z-index: 5;
  border: 2px solid rgba(255,255,255,.18);
}
#hint.show { transform: translate(-50%, 0); opacity: 1; }

/* ── rotate nag ───────────────────────────────────────────────────────── */

#rotate-hint {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: #17262f;
  color: var(--paper);
  text-align: center;
  z-index: 20;
  padding: 24px;
}
.rot-icon { font-size: 3rem; display: block; animation: spin 2.4s ease-in-out infinite; }
@keyframes spin { 0%, 60% { transform: rotate(0); } 80%, 100% { transform: rotate(90deg); } }
#rotate-hint p { line-height: 1.5; }
#rotate-hint small { opacity: .6; }

/* Phone-sized portrait only — tablets are wide enough to cope in portrait. */
@media (orientation: portrait) and (max-width: 700px) {
  #rotate-hint { display: flex; }
}

@media (max-height: 430px) {
  #hud { padding: 4px 10px; }
  #bird-strip { height: 24px; }
  .bird-chip { width: 26px; height: 26px; }
  .icon-btn { width: 34px; height: 34px; }
  .panel { padding: 14px 18px; }
  .panel h2 { font-size: 1.15rem; }
  .score-big { font-size: 1.7rem; }
  .stars-big { font-size: 1.7rem; }
  .big { padding: 9px 22px; font-size: .92rem; }
  .ghost { padding: 8px 16px; font-size: .82rem; }
  #level-grid { max-height: 46vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
