:root {
  --bg: #1d4ed8;          /* true blue */
  --bg-dark: #163a9e;
  --ink: #111;
  --tile: #fff;
  --gold: #f5b301;
  --gold-ink: #6b4a00;
  --silver: #c9ced6;
  --text: #fff;
  --tile-w: 34px;
  --tile-h: 44px;
  --slot-w: 26px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Peralta", Georgia, serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; }
[hidden] { display: none !important; }

.screen { max-width: 520px; margin: 0 auto; padding: 12px 16px calc(16px + env(safe-area-inset-bottom)); }

/* ---------- Home ---------- */
.logo { font-size: 44px; text-align: center; margin: 16px 0 0; letter-spacing: 1px; text-shadow: 3px 3px 0 var(--bg-dark); }
.tagline { text-align: center; margin: 4px 0 16px; opacity: .9; }
.intro { background: rgba(255,255,255,.1); border-radius: 12px; padding: 8px 14px; margin-bottom: 16px; }
.intro summary { cursor: pointer; font-size: 15px; }
.intro[open] summary { display: none; }
.intro h2 { font-size: 20px; margin: 6px 0; }
.intro p { font-family: Georgia, serif; font-size: 16px; line-height: 1.4; margin: 8px 0; }
.btn { border: 0; border-radius: 10px; background: var(--tile); color: var(--ink); font-size: 16px; padding: 10px 16px; }
.btn.primary { display: block; width: 100%; font-size: 22px; padding: 14px; background: var(--gold); box-shadow: 0 4px 0 var(--gold-ink); margin-bottom: 18px; }
.btn.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--gold-ink); }
.grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.hand-tile { position: relative; aspect-ratio: 1; border: 0; padding: 0; border-radius: 10px; overflow: hidden; background: var(--bg-dark); color: #fff; }
.hand-tile img { width: 100%; height: 100%; object-fit: cover; object-position: center 35%; display: block; }
.hand-tile .num { position: absolute; top: 3px; left: 5px; font-size: 14px; text-shadow: 0 0 4px #000, 0 0 2px #000; }
.hand-tile .state { position: absolute; left: 0; right: 0; bottom: 0; font-size: 12px; padding: 2px 0; background: rgba(0,0,0,.55); }
.hand-tile.done .state { background: var(--gold); color: var(--ink); }
.total { text-align: center; margin-top: 14px; }

/* ---------- Puzzle screen ---------- */
#play.screen { padding-top: 6px; }
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.icon { background: none; border: 2px solid rgba(255,255,255,.7); color: #fff; width: 36px; height: 36px; border-radius: 50%; font-size: 18px; line-height: 1; }
.dots { display: flex; gap: 10px; }
.dot { width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; background: transparent; color: var(--ink); font-size: 13px; padding: 0; }
.dot.current { box-shadow: 0 0 0 3px rgba(255,255,255,.45); }
.dot.gold { background: var(--gold); border-color: var(--gold); }
.dot.silver { background: var(--silver); border-color: var(--silver); }

.photo { position: relative; aspect-ratio: 2 / 3; height: min(48vh, 520px); max-width: 100%; margin: 0 auto; border-radius: 12px; overflow: hidden; background: #fff; touch-action: pan-y; }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; user-select: none; -webkit-user-drag: none; }
.arrow { position: absolute; top: 50%; transform: translateY(-50%); width: 32px; height: 48px; border: 0; border-radius: 8px; background: rgba(0,0,0,.25); color: #fff; font-size: 28px; line-height: 1; opacity: .7; }
.arrow.left { left: 4px; } .arrow.right { right: 4px; }
.arrow:disabled { visibility: hidden; }

/* Give-up reveal: the answer's halves split apart over the photo */
.reveal { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 6px; background: rgba(0,0,0,.35); }
.reveal span { background: var(--silver); color: var(--ink); padding: 6px 10px; border-radius: 8px; font-size: 22px; animation: split .7s ease-out forwards; }
.reveal span.l { --dx: -14px; } .reveal span.r { --dx: 14px; }
@keyframes split { from { transform: translateX(0); } to { transform: translateX(var(--dx, 0)); } }

.slots { display: flex; flex-wrap: wrap; justify-content: center; column-gap: 14px; row-gap: 6px; margin: 12px 0 10px; min-height: 36px; }
.word { display: flex; gap: 3px; }
.slot { width: var(--slot-w); height: 34px; border-bottom: 3px solid #fff; display: flex; align-items: center; justify-content: center; font-size: 20px; text-transform: lowercase; line-height: 1; }
.slot.hint { color: #ffe9a6; }
.slots.gold .slot { color: var(--gold); border-color: var(--gold); }
.slots.silver .slot { color: var(--silver); border-color: var(--silver); }
.slots.shake { animation: shake .45s; }
@keyframes shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-8px); } 40%,80% { transform: translateX(8px); } }
.check { font-size: 22px; color: var(--gold); margin-left: 4px; align-self: center; }

.tray { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 12px; }
.row { display: flex; gap: 5px; }
.tile { width: var(--tile-w); height: var(--tile-h); border: 0; border-radius: 7px; background: var(--tile); color: var(--ink); box-shadow: 0 3px 0 rgba(0,0,0,.3); font-size: 22px; padding: 0; display: flex; align-items: center; justify-content: center; line-height: 1; text-transform: lowercase; }
.tile:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.3); }
.tile.used { opacity: .25; box-shadow: none; pointer-events: none; }
.actions { display: flex; justify-content: center; gap: 10px; }
.btn.small { font-size: 15px; padding: 8px 14px; min-width: 64px; }
.btn.ghost { background: transparent; color: #fff; border: 2px solid rgba(255,255,255,.6); }
.btn:disabled { opacity: .35; }

/* ---------- Popups ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.card { background: #fff; color: var(--ink); border-radius: 16px; padding: 22px 20px; width: 100%; max-width: 380px; text-align: center; }
.card h2 { margin: 0 0 6px; font-size: 26px; }
.card .score { font-size: 30px; margin: 8px 0; letter-spacing: 2px; }
.card p { font-family: Georgia, serif; font-size: 17px; margin: 8px 0 16px; }
.card .btn { display: block; width: 100%; margin-top: 10px; background: var(--bg); color: #fff; font-size: 18px; padding: 12px; }
.card .btn.gold { background: var(--gold); color: var(--ink); }
.card .link { background: none; border: 0; color: var(--bg); text-decoration: underline; margin-top: 12px; font-size: 15px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #000; color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 20; }

/* ---------- Narrow phones: 8 tiles per row ---------- */
@media (max-width: 360px) {
  :root { --tile-w: 31px; --tile-h: 41px; --slot-w: 22px; }
  .logo { font-size: 36px; }
}

/* ---------- Landscape fallback: photo left, controls right ---------- */
@media (orientation: landscape) and (max-height: 560px) {
  .screen { max-width: 900px; }
  .stage { display: flex; gap: 16px; align-items: center; }
  .photo { height: calc(100vh - 70px); }
  .controls-col { flex: 1; }
}
