/* ============================================================
   Pirate's Treasure Hunt — style.css
   Design language inspired by mathsisfun.com/style4.css:
   Verdana body text (16px, line-height 1.52), friendly display
   headings with soft shadows, sand/blue themed cards, centered
   content column, chunky high-contrast buttons.
   ============================================================ */

:root {
  --sea-900: #0b1f3a;
  --sea-800: #123057;
  --sea-700: #1b4a7a;
  --sea-600: #2a6aa8;
  --sand-50: #fdf8ec;
  --sand-100: #f7ecd4;
  --sand-200: #eeddb6;
  --sand-300: #e2cd9d;
  --gold-300: #ffd76e;
  --gold-400: #ffc94d;
  --gold-500: #f6a821;
  --gold-600: #d98b0f;
  --red-500: #e2574c;
  --red-600: #c73f35;
  --green-500: #3fa66a;
  --green-600: #2f8a55;
  --blue-500: #2a7de1;
  --blue-600: #1f63b8;
  --ink: #22303f;
  --muted: #5d6b7a;
  --card-border: rgba(90, 62, 20, 0.14);
  --shadow: 0 6px 18px rgba(6, 20, 40, 0.35);
}

* { box-sizing: border-box; }

html { font-size: 16px; }

body {
  margin: 0;
  font-family: Verdana, Arial, Tahoma, sans-serif;
  line-height: 1.52;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 80% -10%, rgba(42, 106, 168, 0.35), transparent 60%),
    linear-gradient(180deg, var(--sea-900) 0%, var(--sea-800) 45%, #0e2748 100%);
  min-height: 100vh;
}

h1, h2, h3 { font-family: "Trebuchet MS", Verdana, Arial, sans-serif; line-height: 1.2; }

h1 {
  margin: 0 0 1rem;
  font-size: 2.6rem;
  font-weight: normal;
  text-align: center;
  color: var(--gold-400);
  text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35), 0 8px 24px rgba(0, 0, 0, 0.3);
}

h2 { margin: 2.6rem 0 1rem; font-size: 2.1rem; color: #ff9d8a; text-shadow: 0 2px 0 rgba(0,0,0,.35); }
h2.small-h { font-size: 1.4rem; margin-top: 2rem; color: var(--sand-200); }

h3 { margin: 0 0 .7rem; font-size: 1.15rem; color: var(--sea-800); }

p { margin: 0 0 1rem; }
.muted { color: var(--muted); }
.center-text { text-align: center; }
.small { font-size: .8rem; }
.hidden { display: none !important; }

.mid { max-width: 820px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.mid-wide { max-width: 1060px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }

a { color: var(--blue-500); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top navigation ---------- */
#topnav {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1.2rem;
  background: rgba(8, 22, 42, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 3px solid var(--gold-500);
}
.brand {
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: 1.15rem; color: var(--sand-50);
  background: none; border: 0; cursor: pointer; padding: .3rem .6rem;
}
.brand:hover { color: var(--gold-400); }
.nav-links { display: flex; gap: .25rem; }
.nav-links a {
  color: var(--sand-100); font-weight: bold; font-size: .9rem;
  padding: .45rem .85rem; border-radius: 999px;
}
.nav-links a:hover { background: rgba(255, 201, 77, 0.16); color: var(--gold-300); text-decoration: none; }

/* ---------- Buttons (chunky, MathIsFun-style) ---------- */
.btn {
  display: inline-block; cursor: pointer;
  font-family: "Trebuchet MS", Verdana, sans-serif;
  font-size: 1rem; font-weight: bold;
  padding: .65rem 1.4rem; border-radius: 999px;
  border: 0; color: #fff; background: var(--sea-700);
  box-shadow: 0 4px 0 rgba(0, 0, 0, 0.35), 0 8px 16px rgba(0, 0, 0, 0.25);
  transition: transform .06s ease, filter .15s ease;
  text-decoration: none !important;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.35); }
.btn-big { font-size: 1.2rem; padding: .85rem 2rem; }
.small-btn { font-size: .85rem; padding: .45rem 1rem; margin-top: 1rem; }

.btn-gold   { background: linear-gradient(180deg, var(--gold-400), var(--gold-500)); color: #3a2604; box-shadow: 0 4px 0 var(--gold-600), 0 8px 16px rgba(0,0,0,.3); }
.btn-blue   { background: linear-gradient(180deg, #3d8ef0, var(--blue-500)); box-shadow: 0 4px 0 var(--blue-600), 0 8px 16px rgba(0,0,0,.3); }
.btn-green  { background: linear-gradient(180deg, #4cbf7d, var(--green-500)); box-shadow: 0 4px 0 var(--green-600), 0 8px 16px rgba(0,0,0,.3); }
.btn-red    { background: linear-gradient(180deg, #ef6a5f, var(--red-500)); box-shadow: 0 4px 0 var(--red-600), 0 8px 16px rgba(0,0,0,.3); }
.btn-ghost { background: transparent; color: var(--sand-100); border: 2px solid rgba(253, 248, 236, .5); box-shadow: none; }
.btn-ghost:hover { border-color: var(--gold-400); color: var(--gold-300); }
.btn-ghost-light { background: rgba(255,255,255,.12); color: #fff; border: 2px solid rgba(255,255,255,.45); box-shadow: none; }
.btn-ghost-light:hover { background: rgba(255,255,255,.22); }

.btn-row { display: flex; flex-wrap: wrap; gap: .8rem; margin: 1.4rem 0; justify-content: flex-start; }
.btn-row.center { justify-content: center; }

/* ---------- Cards (parchment) ---------- */
.card {
  background: linear-gradient(180deg, var(--sand-50), #fbf2dd);
  border: 2px solid var(--card-border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.3rem 1.4rem;
}

/* ---------- Views ---------- */
.view { animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ============================================================
   LANDING / HERO
   ============================================================ */
.hero {
  position: relative; overflow: hidden;
  padding: 4.5rem 1rem 7.5rem;
  background:
    radial-gradient(900px 320px at 50% -80px, rgba(255, 215, 110, 0.25), transparent 70%),
    linear-gradient(180deg, #143a6b 0%, var(--sea-800) 55%, var(--sea-700) 100%);
}
.hero-inner { position: relative; z-index: 2; text-align: center; }
.hero h1 { font-size: clamp(2.4rem, 6vw, 4rem); margin-bottom: .4rem; }
.tagline { color: var(--sand-100); font-size: 1.25rem; margin-bottom: 1.8rem; text-shadow: 0 2px 8px rgba(0,0,0,.4); }
.hero-btns { justify-content: center; }

.hero-art { position: relative; height: 130px; margin-bottom: .5rem; }
.floaty { display: inline-block; filter: drop-shadow(0 10px 12px rgba(0,0,0,.4)); }
.floaty svg { width: 96px; height: 96px; display: block; }
.ship-float { animation: bob 3.2s ease-in-out infinite; margin-right: 2rem; }
.chest-float { animation: bob 3.2s .8s ease-in-out infinite; }
.x-mark {
  position: absolute; left: 50%; top: 46px; transform: translateX(-140%);
  font-size: 2rem; color: rgba(255, 90, 70, .85); text-shadow: 0 2px 6px rgba(0,0,0,.5);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-2deg); } 50% { transform: translateY(-14px) rotate(3deg); } }
@keyframes pulse { 0%,100% { opacity: .5; transform: translateX(-140%) scale(1); } 50% { opacity: 1; transform: translateX(-140%) scale(1.25); } }

.waves { position: absolute; left: 0; right: 0; bottom: -2px; height: 90px; z-index: 1; }
.wave { position: absolute; bottom: 0; width: 200%; height: 100%; }
.wave path { fill: rgba(43, 116, 187, 0.55); }
.wave-front path { fill: var(--sea-900); }
.wave-back { animation: drift 14s linear infinite; }
.wave-front { animation: drift 9s linear infinite reverse; bottom: -6px; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(-50%); } }

/* ---------- How to play ---------- */
.howto .lead { font-size: 1.05rem; color: var(--sand-200); max-width: 640px; margin-left: auto; margin-right: auto; text-align: center; }
.howto-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 1rem; margin-top: 1.5rem; }
.how-card { text-align: left; }
.how-icon { font-size: 2rem; display: block; margin-bottom: .4rem; }
.how-card p { font-size: .88rem; color: #4a5560; margin: 0; }

.scoring-card { margin-top: 1.6rem; }
.score-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.score-table td { padding: .5rem .3rem; border-bottom: 1px dashed var(--sand-300); }
.score-table tr:last-child td { border-bottom: 0; }
.score-table .num { text-align: right; font-weight: bold; white-space: nowrap; }
.num.good { color: var(--green-600); }
.num.bad { color: var(--red-600); }

/* ============================================================
   ADMIN / SETUP
   ============================================================ */
.admin-tag {
  display: inline-block; vertical-align: middle; margin-left: .5rem;
  font-size: .7rem; letter-spacing: .12em; color: #3a2604;
  background: var(--gold-400); border-radius: 999px; padding: .2rem .7rem;
}
.setup-card { margin-bottom: 1.2rem; }

.chip-row { display: flex; flex-wrap: wrap; gap: .6rem; margin: .8rem 0 1rem; }
.chip-btn {
  cursor: pointer; font-family: "Trebuchet MS", Verdana, sans-serif; font-weight: bold;
  font-size: 1rem; padding: .5rem 1.2rem; border-radius: 999px;
  border: 2px solid var(--sand-300); background: #fff; color: var(--sea-800);
  transition: all .12s ease;
}
.chip-btn:hover { border-color: var(--gold-500); }
.chip-btn.active {
  background: linear-gradient(180deg, var(--gold-400), var(--gold-500));
  border-color: var(--gold-600); color: #3a2604;
  box-shadow: 0 3px 0 var(--gold-600);
}

.name-list { display: grid; gap: .7rem; margin-top: .4rem; }
.name-field { display: flex; align-items: center; gap: .8rem; }
.name-field label { width: 2.2rem; font-weight: bold; color: var(--sea-700); }
.name-field input {
  flex: 1; max-width: 340px; font-size: 1rem; font-family: inherit;
  padding: .55rem .9rem; border-radius: 10px; border: 2px solid var(--sand-300);
  background: #fff; color: var(--ink);
}
.name-field input:focus { outline: none; border-color: var(--gold-500); box-shadow: 0 0 0 3px rgba(246, 168, 33, .25); }

.slider-row { display: flex; align-items: center; gap: 1rem; margin-top: .4rem; }
.slider-row input[type="range"] { flex: 1; max-width: 420px; accent-color: var(--gold-500); height: 28px; }
.big-value { font-family: "Trebuchet MS", Verdana, sans-serif; font-size: 1.6rem; color: var(--sea-800); min-width: 4.5rem; text-align: center; }

/* ============================================================
   GAME
   ============================================================ */
.game-top { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; padding: .9rem 1.3rem; margin-bottom: 1rem; }
.round-pill {
  font-family: "Trebuchet MS", Verdana, sans-serif; font-weight: bold; color: #fff;
  background: var(--sea-700); border-radius: 999px; padding: .45rem 1.1rem; white-space: nowrap;
}
.turn-name { flex: 1; min-width: 160px; font-family: "Trebuchet MS", Verdana, sans-serif; font-size: 1.35rem; color: var(--sea-800); }
.timer { display: flex; align-items: center; gap: .7rem; min-width: 240px; flex: 1; max-width: 380px; }
.timer-bar { flex: 1; height: 16px; border-radius: 999px; background: var(--sand-200); overflow: hidden; box-shadow: inset 0 2px 4px rgba(0,0,0,.15); }
#g-timer-fill { height: 100%; width: 100%; border-radius: 999px; background: var(--green-500); transition: width .1s linear; }
#g-timer-fill.warn { background: var(--gold-500); }
#g-timer-fill.danger { background: var(--red-500); animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { filter: brightness(1.35); } }
#g-timer-text { font-size: 1.05rem; color: var(--sea-800); min-width: 4.2rem; text-align: right; }

.game-main { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; align-items: start; }
@media (max-width: 860px) { .game-main { grid-template-columns: 1fr; } }

.map-card { padding: 1.2rem; }

.chips { display: flex; flex-wrap: wrap; gap: .55rem; margin-bottom: 1rem; min-height: 44px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem;
  font-family: "Trebuchet MS", Verdana, sans-serif; font-weight: bold; font-size: .95rem;
  background: #fff; border: 2px solid var(--sand-300); color: var(--sea-800);
  padding: .4rem .8rem; border-radius: 12px; transition: all .15s ease;
}
.chip .dir { line-height: 1; }
.chip.active { background: linear-gradient(180deg, var(--gold-300), var(--gold-400)); border-color: var(--gold-600); color: #3a2604; transform: scale(1.07); box-shadow: 0 3px 0 var(--gold-600); }
.chip.done { opacity: .45; text-decoration: line-through; }

.map-wrap { position: relative; }
.grid {
  display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px;
  background: var(--sea-700); padding: 8px; border-radius: 12px;
  box-shadow: inset 0 3px 10px rgba(0,0,0,.35);
}
.cell {
  position: relative; aspect-ratio: 1; border: 0; padding: 0; cursor: pointer;
  background: var(--sand-100); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: transform .08s ease, box-shadow .08s ease;
}
.cell:nth-child(even) { background: #f2e4c4; }
.cell:hover { transform: scale(1.06); box-shadow: 0 0 0 3px rgba(255, 201, 77, .8); z-index: 2; }
.cell.trail::after { content: ""; position: absolute; width: 26%; height: 26%; border-radius: 50%; background: rgba(246, 168, 33, .55); }
.cell.wrong-flash { animation: wrongShake .3s ease; box-shadow: 0 0 0 4px var(--red-500) !important; }
@keyframes wrongShake { 25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.cell .token { width: 86%; height: 86%; display: block; pointer-events: none; filter: drop-shadow(0 3px 4px rgba(0,0,0,.35)); z-index: 1; }
.cell.ship-cell .token { animation: bob 2.4s ease-in-out infinite; }
.cell.found-cell .token { animation: popIn .45s cubic-bezier(.2, 1.6, .4, 1) both; }
.skull-token { font-size: clamp(1rem, 3vw, 1.9rem); line-height: 1; pointer-events: none; z-index: 1; animation: popIn .4s ease both; filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); }
@keyframes popIn { from { transform: scale(0) rotate(-30deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }

.turn-banner {
  position: absolute; inset: 8px; z-index: 5; border-radius: 12px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem;
  background: rgba(10, 26, 48, 0.88); color: #fff; text-align: center; padding: 1rem;
}
#g-banner-icon { font-size: 3rem; line-height: 1; animation: popIn .4s cubic-bezier(.2, 1.6, .4, 1) both; }
#g-banner-text { font-family: "Trebuchet MS", Verdana, sans-serif; font-size: clamp(1.2rem, 3vw, 1.8rem); font-weight: bold; text-shadow: 0 2px 6px rgba(0,0,0,.5); }

.side-card { position: sticky; top: 74px; }
.scoreboard { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.scoreboard li {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
  background: #fff; border: 2px solid var(--sand-300); border-radius: 12px; padding: .5rem .8rem;
}
.scoreboard li.active { border-color: var(--gold-500); background: linear-gradient(180deg, #fff8e6, #ffefc4); box-shadow: 0 3px 0 var(--gold-500); }
.sb-name { font-weight: bold; color: var(--sea-800); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sb-score { font-family: "Trebuchet MS", Verdana, sans-serif; font-size: 1.15rem; color: var(--sea-700); white-space: nowrap; }
.sb-found { font-size: .8rem; color: var(--muted); white-space: nowrap; }

/* ============================================================
   RESULTS
   ============================================================ */
.results-wrap { position: relative; padding-top: 2.5rem; }
#r-title { font-size: clamp(2rem, 5vw, 3rem); }
.result-table { margin-top: 1.4rem; }
.save-note { min-height: 1.4em; font-weight: bold; color: var(--green-600); }
.save-note.error { color: var(--red-600); }

#confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 90; }
.confetto { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px; animation: confettiFall linear forwards; }
@keyframes confettiFall { to { transform: translateY(105vh) rotate(720deg); opacity: .9; } }

/* ============================================================
   LEADERBOARD TABLE (shared by results + leaderboard views)
   ============================================================ */
.lb-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); font-size: .95rem; }
.lb-table th, .lb-table td { padding: .65rem .8rem; text-align: left; border-bottom: 1px solid var(--sand-200); }
.lb-table thead th { background: linear-gradient(180deg, var(--sea-700), var(--sea-800)); color: #fff; font-family: "Trebuchet MS", Verdana, sans-serif; letter-spacing: .04em; }
.lb-table tbody tr:nth-child(even) { background: var(--sand-50); }
.lb-table td.num, .lb-table th.num { text-align: right; }
.rank-medal { font-size: 1.2rem; }
.player-cell { font-weight: bold; color: var(--sea-800); }

.recent-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .45rem; font-size: .9rem; }
.recent-list li { display: flex; flex-wrap: wrap; gap: .3rem .8rem; align-items: baseline; border-bottom: 1px dashed var(--sand-300); padding-bottom: .4rem; }
.recent-list li:last-child { border-bottom: 0; }
.recent-list .rw { font-weight: bold; color: var(--sea-800); }
.recent-list .rd { color: var(--muted); margin-left: auto; white-space: nowrap; }

/* ---------- Footer ---------- */
#site-footer { text-align: center; padding: 1.4rem 1rem 2rem; color: rgba(253, 248, 236, .55); font-size: .78rem; }

/* ============================================================
   PRINT (leaderboard only)
   ============================================================ */
@media print {
  body { background: #fff !important; }
  #topnav, #site-footer, .no-print, #view-landing, #view-admin, #view-game, #view-results { display: none !important; }
  #view-leaderboard { display: block !important; }
  .lb-wrap h1 { color: var(--sea-800); text-shadow: none; font-size: 2rem; }
  .lb-wrap p.muted, .small-h, .recent-card { color: #333; }
  .card { box-shadow: none; border-color: #bbb; background: #fff; }
  .lb-table th, .lb-table td { border-bottom: 1px solid #ccc; }
}
