/* Croc Run — game.css
 * Overlays sit on top of a full-viewport WebGL canvas.
 * See spec/06-ui-ux-spec.md
 */

:root {
  --gold: #d4af37;
  --gold-dark: #7a5c14;
  --sand: #f0d49a;
  --sea: #22a1f0;
  --sea-deep: #0a5a8c;
  --danger: #e8443a;
  --ink: #22303a;
  --panel: rgba(255, 253, 246, 0.94);
  --panel-dark: rgba(14, 42, 58, 0.82);
  --shadow: 0 12px 34px rgba(6, 30, 45, 0.32);
  --radius: 18px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Trebuchet MS', 'Helvetica Neue', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #0a5a8c;
  font-family: var(--font);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

#game {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body.is-playing #game { cursor: none; }

/* --- generic overlay ---------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(10px, 2.5vh, 28px);
  overflow: auto;
  background: radial-gradient(circle at 50% 35%, rgba(4, 30, 46, 0.35), rgba(4, 24, 38, 0.72));
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}

.overlay[hidden] { display: none; }

.panel {
  width: min(1040px, 100%);
  max-height: 100%;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 3px solid rgba(255, 255, 255, 0.7);
  padding: clamp(16px, 3vw, 28px);
  overflow: auto;
}

.panel.small { width: min(460px, 100%); text-align: center; }

/* --- headings ----------------------------------------------------------- */

.title {
  font-size: clamp(2.1rem, 6vw, 3.4rem);
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--sea-deep);
  text-align: center;
}

.title .croc { color: #4f9a35; }

.tagline {
  text-align: center;
  font-size: clamp(0.95rem, 2.4vw, 1.1rem);
  color: #55707f;
  margin: 6px 0 16px;
}

h2 {
  font-size: 1.15rem;
  color: var(--sea-deep);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- setup layout ------------------------------------------------------- */

.columns {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 900px) {
  .columns { grid-template-columns: 1.05fr 1fr; align-items: start; }
}

.card {
  background: #fff;
  border-radius: 14px;
  padding: 14px;
  border: 2px solid #eadfc6;
  box-shadow: 0 4px 12px rgba(20, 60, 80, 0.06);
}

.card + .card { margin-top: 14px; }

/* --- player list -------------------------------------------------------- */

#player-list {
  list-style: none;
  max-height: 210px;
  overflow-y: auto;
  margin-bottom: 10px;
  -webkit-overflow-scrolling: touch;
}

#player-list li {
  display: flex;
  align-items: stretch;
  gap: 6px;
  margin-bottom: 6px;
}

#player-list .empty {
  display: block;
  color: #7d8f9a;
  font-size: 0.95rem;
  padding: 10px 4px;
}

.player-row {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-height: 46px;
  padding: 8px 12px;
  border: 2px solid #e6edf2;
  border-radius: 12px;
  background: #f7fbfd;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.player-row:hover { background: #eef7fd; border-color: #bfe0f5; }
.player-row:active { transform: scale(0.995); }

.player-row.is-selected {
  border-color: var(--gold);
  background: #fff8e3;
  box-shadow: inset 0 0 0 1px var(--gold);
}

.player-name { font-weight: 700; font-size: 1.05rem; }
.player-meta { font-size: 0.82rem; color: #6b8090; }

.player-del {
  width: 46px;
  min-height: 46px;
  border: 2px solid #f0dede;
  background: #fff6f6;
  border-radius: 12px;
  font-size: 1rem;
  cursor: pointer;
  color: #b4453c;
}

.player-del:hover { background: #ffe9e9; border-color: #e8b0ab; }

.new-player { display: flex; gap: 8px; flex-wrap: wrap; }

input[type="text"] {
  flex: 1;
  min-width: 150px;
  min-height: 46px;
  padding: 10px 14px;
  font: inherit;
  font-size: 1.05rem;
  border: 2px solid #d8e4ec;
  border-radius: 12px;
  background: #fff;
  color: inherit;
}

input[type="text"]:focus { outline: 3px solid var(--sea); outline-offset: 1px; border-color: var(--sea); }

.error { color: #c0392b; font-size: 0.9rem; min-height: 1.2em; margin-top: 6px; }

.chosen-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 2px dashed #ecdfc4;
}

#look-preview {
  width: 54px;
  height: 54px;
  image-rendering: auto;
  flex: none;
}

#chosen-player { font-weight: 700; font-size: 1.1rem; flex: 1; }
#chosen-player.is-empty { color: #92a4ae; font-weight: 500; }

/* --- buttons ------------------------------------------------------------ */

.btn {
  min-height: 48px;
  padding: 12px 22px;
  border: none;
  border-radius: 14px;
  font: inherit;
  font-size: 1.02rem;
  font-weight: 700;
  cursor: pointer;
  background: #e8eff4;
  color: var(--ink);
  transition: transform 0.1s, filter 0.15s;
}

.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(180deg, #ffc93c, #eda21f);
  color: #4a3200;
  box-shadow: 0 5px 0 #b97c12;
  font-size: 1.2rem;
  width: 100%;
  margin-top: 14px;
}

.btn-primary:active { box-shadow: 0 2px 0 #b97c12; }

.btn-sea { background: linear-gradient(180deg, #4fc3f7, #1d8fd0); color: #fff; box-shadow: 0 4px 0 #14648f; }
.btn-ghost { background: transparent; border: 2px solid #cfdde6; }

.btn-small { min-height: 40px; padding: 8px 14px; font-size: 0.92rem; }

button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 3px solid var(--sea);
  outline-offset: 2px;
}

/* --- crocodile picker --------------------------------------------------- */

.croc-row { display: flex; align-items: center; gap: 10px; }

.round-btn {
  width: 48px; height: 48px;
  flex: none;
  border-radius: 50%;
  border: 2px solid #cfe3d3;
  background: #eef8ee;
  font-size: 1.5rem;
  line-height: 1;
  font-weight: 700;
  cursor: pointer;
  color: #2f6b33;
}

.round-btn:hover { background: #dff2df; }

input[type="range"] {
  flex: 1;
  min-width: 120px;
  height: 40px;
  accent-color: #4f9a35;
  background: transparent;
}

#croc-num {
  font-size: 1.6rem;
  font-weight: 800;
  min-width: 1.6em;
  text-align: center;
  color: #2f6b33;
}

#croc-icons {
  font-size: 1.5rem;
  line-height: 1.5;
  margin-top: 8px;
  word-break: break-all;
  min-height: 1.6em;
}

.croc-meta { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
#croc-label { font-weight: 700; color: #2f6b33; }
#croc-mult { color: #8a6d1f; font-weight: 700; }
.hint { font-size: 0.88rem; color: #6b8090; margin-top: 8px; }

/* --- leaderboard -------------------------------------------------------- */

.tabs { display: flex; gap: 6px; margin-bottom: 10px; }

.tab {
  flex: 1;
  min-height: 40px;
  border: 2px solid #e6edf2;
  background: #f7fbfd;
  border-radius: 10px;
  font: inherit;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  color: #5b7484;
}

.tab.is-active { background: #fff8e3; border-color: var(--gold); color: var(--gold-dark); }

table.board { width: 100%; border-collapse: collapse; font-size: 0.95rem; }

table.board th {
  text-align: left;
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #8ba0ad;
  padding: 4px 6px;
  border-bottom: 2px solid #eef3f6;
}

table.board td { padding: 7px 6px; border-bottom: 1px solid #f0f5f8; }
table.board tr:last-child td { border-bottom: none; }
table.board .rank { width: 2.4em; font-weight: 800; color: #7b8f9c; }
table.board .who { font-weight: 700; max-width: 9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.board .time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--sea-deep); }
table.board .pts { font-variant-numeric: tabular-nums; color: #6b8090; }
table.board .crocs { text-align: right; color: #4f9a35; font-weight: 700; white-space: nowrap; }
table.board .empty { color: #8ba0ad; text-align: center; padding: 18px 6px; }
table.board tr.is-me td { background: #fff8e3; }
table.board tr.is-new td { background: #e8f8e2; animation: flashRow 1.4s ease-out 2; }
table.pinned { margin-top: 6px; border-top: 2px dashed #dde7ee; }

@keyframes flashRow {
  0%, 100% { background: #e8f8e2; }
  50% { background: #c9eebb; }
}

/* --- footer bar --------------------------------------------------------- */

.setup-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 2px solid #eee4cc;
}

.setup-footer a { color: var(--gold-dark); font-weight: 700; text-decoration: none; }
.setup-footer a:hover { text-decoration: underline; }

.note {
  width: 100%;
  text-align: center;
  background: #fff5d8;
  border: 2px solid #f0dca0;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.9rem;
  color: #7a5c14;
  margin-top: 10px;
}

#help-card {
  background: #eef7fd;
  border: 2px solid #cbe6f8;
  border-radius: 14px;
  padding: 14px;
  margin-top: 14px;
  font-size: 0.96rem;
}

#help-card ul { margin: 8px 0 0 18px; }
#help-card li { margin-bottom: 5px; }

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

.hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) 0 env(safe-area-inset-left, 0);
  font-weight: 700;
  color: #fff;
  text-shadow: 0 2px 6px rgba(0, 40, 60, 0.55);
}

.hud[hidden] { display: none; }

.hud-left { position: absolute; top: 12px; left: 14px; }
#hud-time { font-size: clamp(1.7rem, 5vw, 2.4rem); line-height: 1; font-variant-numeric: tabular-nums; }
#hud-time.is-best { color: #ffe066; }
#hud-score { font-size: clamp(0.95rem, 2.6vw, 1.15rem); opacity: 0.95; }

.hud-center {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  width: min(230px, 46vw);
}

#hud-hearts { font-size: clamp(1.1rem, 3.4vw, 1.5rem); letter-spacing: 2px; color: #ff5d73; }
#hud-hearts .heart.is-empty { color: rgba(255, 255, 255, 0.35); }

.stamina {
  height: 7px;
  margin: 4px auto 0;
  width: 100%;
  background: rgba(4, 30, 46, 0.4);
  border-radius: 99px;
  overflow: hidden;
}

#hud-stamina {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, #7bd389, #2ec4b6);
  border-radius: 99px;
  transition: width 0.08s linear;
}

#hud-stamina.is-low { background: linear-gradient(90deg, #ffb03a, #e8443a); }

.hud-right {
  position: absolute;
  top: 12px;
  right: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(0.95rem, 2.6vw, 1.1rem);
}

.icon-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  background: rgba(4, 30, 46, 0.4);
  color: #fff;
  font-size: 1.2rem;
  cursor: pointer;
}

.icon-btn:hover { background: rgba(4, 30, 46, 0.62); }

#toasts {
  position: absolute;
  bottom: 8%;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 6px;
  width: 90%;
}

.toast {
  background: rgba(6, 34, 50, 0.78);
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 99px;
  padding: 7px 18px;
  font-size: clamp(0.95rem, 2.8vw, 1.1rem);
  animation: toastIn 0.28s cubic-bezier(0.2, 1.4, 0.4, 1);
  transition: opacity 0.3s, transform 0.3s;
}

.toast-good { background: rgba(24, 110, 60, 0.82); }
.toast-bad { background: rgba(150, 30, 26, 0.85); }
.toast-gold { background: rgba(160, 116, 12, 0.88); border-color: #ffe066; }
.toast.is-out { opacity: 0; transform: translateY(-14px); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(16px) scale(0.9); }
  to { opacity: 1; transform: none; }
}

#best-banner {
  position: absolute;
  top: 22%;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(180deg, #ffd447, #e5a413);
  color: #4a3200;
  text-shadow: none;
  padding: 10px 26px;
  border-radius: 99px;
  font-size: clamp(1.05rem, 3.4vw, 1.4rem);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.28);
  animation: popIn 0.4s cubic-bezier(0.2, 1.5, 0.4, 1);
}

#best-banner[hidden] { display: none; }

@keyframes popIn {
  from { opacity: 0; transform: translateX(-50%) scale(0.6); }
  to { opacity: 1; transform: translateX(-50%) scale(1); }
}

/* --- countdown ---------------------------------------------------------- */

.countdown {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.countdown[hidden] { display: none; }

#countdown-text {
  font-size: clamp(3.4rem, 16vw, 9rem);
  font-weight: 800;
  color: #fff;
  text-shadow: 0 6px 0 rgba(10, 60, 90, 0.45), 0 14px 30px rgba(0, 0, 0, 0.4);
}

#countdown-text.pop { animation: countPop 0.45s cubic-bezier(0.2, 1.5, 0.4, 1); }

@keyframes countPop {
  from { opacity: 0.2; transform: scale(1.9); }
  to { opacity: 1; transform: scale(1); }
}

/* --- results ------------------------------------------------------------ */

.result-title {
  text-align: center;
  font-size: clamp(1.9rem, 6vw, 2.8rem);
  color: var(--danger);
}

.result-sub { text-align: center; color: #55707f; margin-bottom: 14px; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.stat {
  background: #f7fbfd;
  border: 2px solid #e6edf2;
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
}

.stat b { display: block; font-size: 1.35rem; color: var(--sea-deep); font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.78rem; color: #7b8f9c; text-transform: uppercase; letter-spacing: 0.05em; }

#res-badges { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 12px; }

.badge {
  padding: 7px 14px;
  border-radius: 99px;
  font-weight: 700;
  font-size: 0.95rem;
  animation: popIn2 0.4s cubic-bezier(0.2, 1.5, 0.4, 1);
}

@keyframes popIn2 { from { transform: scale(0.6); opacity: 0; } to { transform: none; opacity: 1; } }

.badge-gold { background: linear-gradient(180deg, #ffd447, #e5a413); color: #4a3200; }
.badge-silver { background: #e6eef3; color: #47606e; }
.badge-best { background: #dff5d6; color: #2f6b33; }

.result-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.result-actions .btn { flex: 1 1 140px; }

/* --- pause -------------------------------------------------------------- */

#pause .panel { display: flex; flex-direction: column; gap: 10px; }

/* --- small screens ------------------------------------------------------ */

@media (max-width: 480px) {
  .panel { padding: 14px; border-radius: 14px; }
  .card { padding: 11px; }
  #player-list { max-height: 168px; }
  table.board { font-size: 0.88rem; }
  table.board td { padding: 6px 4px; }
  .hud-left { top: 8px; left: 10px; }
  .hud-right { top: 8px; right: 10px; gap: 7px; }
}

@media (max-height: 470px) and (orientation: landscape) {
  .title { font-size: 1.6rem; }
  .tagline { margin: 2px 0 8px; font-size: 0.9rem; }
  #player-list { max-height: 120px; }
}

/* --- reduced motion ----------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* --- screen-reader only ------------------------------------------------- */

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