:root {
  --bg-top: #050b14;
  --bg-bottom: #0b2a3f;
  --card: rgba(10, 24, 38, .82);
  --line: rgba(140, 200, 230, .18);
  --text: #eaf4f8;
  --muted: #93aebd;
  --accent: #4fd1c5;
  --accent-ink: #032420;
  --paper: #f4ead2;
  --paper-ink: #2d2416;
  --paper-line: #e2d3ae;
  --bad: #ff6b6b;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: linear-gradient(var(--bg-top), var(--bg-bottom) 70%, #0d3a52);
  background-attachment: fixed;
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
a { color: var(--accent); }

/* ---------- Sky & sea ---------- */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.moon {
  position: absolute; top: 7%; inset-inline-end: 12%;
  width: 70px; height: 70px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fffbe8, #e9dfb8 60%, #cfc39a);
  box-shadow: 0 0 60px 12px rgba(255, 246, 200, .18);
}
.stars {
  position: absolute; inset: 0 0 40% 0;
  background-image:
    radial-gradient(1px 1px at 10% 20%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 30% 8%, #cfe 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 55% 25%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 70% 12%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 85% 35%, #dff 50%, transparent 51%),
    radial-gradient(1px 1px at 20% 45%, #fff 50%, transparent 51%),
    radial-gradient(1.5px 1.5px at 42% 52%, #eef 50%, transparent 51%),
    radial-gradient(1px 1px at 92% 6%, #fff 50%, transparent 51%),
    radial-gradient(1px 1px at 5% 60%, #fff 50%, transparent 51%);
  opacity: .8;
  animation: twinkle 6s ease-in-out infinite alternate;
}
@keyframes twinkle { to { opacity: .45; } }
@media (max-width: 640px) { .moon { width: 38px; height: 38px; top: 54px; inset-inline-end: 6%; } }

.sea { position: fixed; left: 0; right: 0; bottom: 0; height: 22vh; min-height: 120px; pointer-events: none; z-index: 0; }
.wave { position: absolute; left: 0; bottom: 0; width: 200%; height: 100%; }
.wave path { fill: #0e4a66; }
.w1 { opacity: .55; animation: drift 14s linear infinite; bottom: 18px; }
.w1 path { fill: #136182; }
.w2 { opacity: .75; animation: drift 10s linear infinite reverse; bottom: 8px; }
.w3 { animation: drift 7s linear infinite; }
.w3 path { fill: #0a3a52; }
@keyframes drift { from { transform: translateX(0); } to { transform: translateX(-50%); } }

/* ---------- Layout ---------- */
#app {
  position: relative; z-index: 1;
  max-width: 1000px; margin: 0 auto;
  padding: calc(16px + var(--safe-top)) 16px calc(28vh + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 16px;
}
.hero { text-align: center; position: relative; padding-top: 12px; }
.logo { width: 64px; height: 64px; animation: bob 4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(6deg); } }
h1 { margin: 4px 0 2px; font-size: 32px; letter-spacing: .5px; }
.tagline { margin: 0; color: var(--muted); }
.sea-count { margin: 6px 0 0; color: var(--accent); font-size: 14px; min-height: 1.5em; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(6px);
  display: flex; flex-direction: column; gap: 14px;
  animation: fade-in .3s ease both;
}
@keyframes fade-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.card h2 { margin: 0; font-size: 20px; }
.muted { color: var(--muted); margin: 0; }
.small { font-size: 13px; }
.center { text-align: center; }
.write-form { display: flex; flex-direction: column; gap: 14px; }
/* Honeypot field: off-screen, not focusable, skipped by screen readers. */
.hp { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* ---------- Panels: find + throw side by side on wide screens, stacked on phones ---------- */
.panels { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr)); gap: 16px; align-items: start; }

/* ---------- Form ---------- */
.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
select {
  font: inherit; color: var(--text); background: #0b1c2b; border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; max-width: 100%;
}
.paper-wrap { position: relative; }
.paper {
  width: 100%; resize: vertical; min-height: 220px;
  font: 17px/28px Georgia, "Times New Roman", serif;
  color: var(--paper-ink);
  background: var(--paper) repeating-linear-gradient(transparent 0 27px, var(--paper-line) 27px 28px);
  background-attachment: local;
  border: 0; border-radius: 6px; padding: 14px 16px 30px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .35), inset 0 0 40px rgba(160, 120, 60, .15);
  outline: none;
}
.paper::placeholder { color: #9c8a66; font-style: italic; }
.paper:focus { box-shadow: 0 8px 30px rgba(0, 0, 0, .35), 0 0 0 3px rgba(79, 209, 197, .45); }
.counter { position: absolute; bottom: 10px; inset-inline-end: 14px; font-size: 12px; color: #8d7a55; pointer-events: none; }
.counter.near { color: #b0602a; font-weight: 700; }

.btn {
  font: inherit; font-weight: 700; font-size: 17px;
  border: 0; border-radius: 12px; padding: 14px 18px;
  background: var(--accent); color: var(--accent-ink); cursor: pointer;
  transition: transform .1s, filter .2s, opacity .2s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.small-btn { font-size: 15px; padding: 10px 16px; }
.danger-btn { background: var(--bad); color: #2a0606; }
.link-btn { font: inherit; font-size: 14px; background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; text-decoration: underline; text-underline-offset: 3px; }
.link-btn.danger { color: var(--bad); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

/* ---------- Language chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(79, 209, 197, .14); color: var(--text);
  border: 1px solid rgba(79, 209, 197, .4); border-radius: 999px;
  padding: 4px 6px 4px 12px; font-size: 14px;
}
.chip button { border: 0; background: rgba(255, 255, 255, .1); color: var(--text); width: 22px; height: 22px; border-radius: 50%; cursor: pointer; line-height: 1; }
.chip .n { color: var(--muted); font-size: 12px; }
.add-lang { align-self: flex-start; }

/* ---------- Found letter ---------- */
.found { display: flex; flex-direction: column; gap: 10px; }
.letter {
  background: var(--paper) repeating-linear-gradient(transparent 0 27px, var(--paper-line) 27px 28px);
  color: var(--paper-ink);
  border-radius: 4px; padding: 16px 18px 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4), inset 0 0 50px rgba(150, 110, 50, .2);
  transform-origin: top center;
  animation: unroll .7s cubic-bezier(.2, .8, .2, 1) both;
}
@keyframes unroll { from { transform: scaleY(.05) rotate(-2deg); opacity: 0; } 60% { opacity: 1; } to { transform: none; } }
.meta { margin: 0 0 6px; font-size: 13px; color: #8d7a55; font-style: italic; }
.letter-text { margin: 0; font: 17px/28px Georgia, "Times New Roman", serif; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 60vh; overflow-y: auto; }

/* ---------- Animation stage ---------- */
.stage { position: fixed; inset: 0; z-index: 20; pointer-events: none; }
.stage-bottle { position: absolute; width: 90px; height: 90px; left: calc(50% - 45px); top: 45%; }
.stage.throw .stage-bottle { animation: throw 1.6s cubic-bezier(.3, .1, .4, 1) forwards; }
@keyframes throw {
  0% { transform: translate(0, 0) scale(.3) rotate(0); opacity: 0; }
  15% { transform: translate(0, 0) scale(1) rotate(-10deg); opacity: 1; }
  60% { transform: translate(25vw, -25vh) scale(.6) rotate(320deg); }
  100% { transform: translate(35vw, 40vh) scale(.25) rotate(540deg); opacity: .9; }
}
.stage.fish .stage-bottle { animation: fish 1.5s ease-out forwards; }
@keyframes fish {
  0% { transform: translate(-30vw, 42vh) scale(.3) rotate(-30deg); opacity: 0; }
  20% { opacity: 1; }
  45% { transform: translate(-15vw, 38vh) scale(.5) rotate(20deg); }
  70% { transform: translate(0, 10vh) scale(.9) rotate(-10deg); }
  100% { transform: translate(0, 0) scale(1.15) rotate(0); opacity: 0; }
}
.splash {
  position: absolute; width: 120px; height: 40px; left: calc(50% + 35vw - 60px); bottom: 10vh;
  border-radius: 50%; border: 3px solid rgba(200, 255, 250, .8); opacity: 0;
}
.stage.throw .splash { animation: splash .7s ease-out 1.45s forwards; }
@keyframes splash { from { transform: scale(.2); opacity: 1; } to { transform: scale(1.6); opacity: 0; } }
.paper.rolling { animation: roll .5s ease-in forwards; }
@keyframes roll { to { transform: scale(.2, .05) translateY(200px); opacity: 0; } }

/* ---------- Dialog & toast ---------- */
dialog {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: #0c1f2f; color: var(--text); padding: 18px; width: min(92vw, 380px);
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog form { display: flex; flex-direction: column; gap: 10px; }
dialog h3 { margin: 0 0 4px; }
dialog label { display: flex; gap: 10px; align-items: center; cursor: pointer; }
dialog input { accent-color: var(--bad); width: 18px; height: 18px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%);
  z-index: 30; max-width: min(92vw, 480px);
  background: #102c3f; border: 1px solid var(--accent); color: var(--text);
  padding: 12px 18px; border-radius: 12px; box-shadow: 0 8px 30px rgba(0, 0, 0, .4);
  animation: fade-in .25s ease both; text-align: center;
}
.toast.error { border-color: var(--bad); }

/* ---------- Footer ---------- */
.foot { text-align: center; display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.langs { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 12px; font-size: 13px; }
.langs a { color: var(--muted); text-decoration: none; }
.langs a:hover { color: var(--text); }
.langs span { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
