:root {
  --navy: #0b3d91;
  --blue: #1565c0;
  --sky: #42a5f5;
  --ice: #e3f2fd;
  --paper: #ffffff;
  --ink: #0d1b2a;
  --muted: #5c6b7a;
  --mark: #1565c0;
  --gold: #ffc107;
  --b-red: #E52827;
  --i-blue: #1565c0;
  --n-green: #499B2D;
  --g-yellow: #ffc107;
  --o-purple: #7F14D4;
  --bg: linear-gradient(160deg, #0b3d91 0%, #1565c0 55%, #42a5f5 100%);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: #0b3d91;
}

body {
  background: var(--bg);
  background-attachment: fixed;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overscroll-behavior: none;
}

.hidden {
  display: none !important;
}

main {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 0 10px 16px;
}

.screen {
  width: 100%;
  max-width: 520px;
}

.topbar {
  position: relative;
  display: flex;
  justify-content: center;
  padding: 10px 16px 6px;
  color: #fff;
}

.logo {
  margin: 0;
  line-height: 0;
}
.logo img {
  display: block;
  width: auto;
  height: clamp(96px, 16vh, 150px);
  max-width: 70vw;
  object-fit: contain;
  filter: drop-shadow(0 4px 10px rgba(0, 0, 0, 0.3));
}

.status {
  position: absolute;
  top: 10px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  white-space: nowrap;
  opacity: 0.95;
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ef5350;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}
.dot.online {
  background: #66bb6a;
}

.panel {
  margin-top: 3vh;
  background: var(--paper);
  border-radius: 18px;
  padding: 24px 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.lead {
  margin: 0 0 20px;
  color: var(--muted);
  line-height: 1.45;
}
.lead p {
  margin: 0 0 8px;
}
.lead ul {
  margin: 0;
  padding-left: 20px;
}
.lead li + li {
  margin-top: 4px;
}
.lead strong {
  color: var(--ink);
}

label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
}

input[type=text] {
  width: 100%;
  font-size: 1.1rem;
  padding: 12px 14px;
  border: 2px solid #cfd8e3;
  border-radius: 12px;
  outline: none;
}
input[type=text]:focus {
  border-color: var(--blue);
}

.btn {
  margin-top: 16px;
  width: 100%;
  padding: 14px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #fff;
  background: rgb(58, 123, 36);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}
.btn:active {
  transform: scale(0.98);
}

.banner {
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--navy);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
}

.instructions {
  margin: 0 0 10px;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  font-size: 0.95rem;
  line-height: 1.4;
  text-align: center;
}
.instructions h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1.2;
  color: var(--paper);
}
.instructions p {
  margin: 0;
}
.instructions .mode {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.25);
}
.instructions .mode strong {
  color: var(--gold);
}

.card {
  background: var(--paper);
  border-radius: 16px;
  padding: 6px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.card-head, .grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}

.card-head span {
  text-align: center;
  font-size: 1.6rem;
  font-weight: 900;
  color: var(--navy);
  padding: 2px 0 6px;
  -webkit-text-stroke: 2px var(--ink);
  paint-order: stroke fill;
}
.card-head span:nth-child(1) {
  color: var(--b-red);
}
.card-head span:nth-child(2) {
  color: var(--i-blue);
}
.card-head span:nth-child(3) {
  color: var(--n-green);
}
.card-head span:nth-child(4) {
  color: var(--g-yellow);
}
.card-head span:nth-child(5) {
  color: var(--o-purple);
}

.cell {
  position: relative;
  aspect-ratio: 1/1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border: 2px solid #cfd8e3;
  border-radius: 9px;
  background: var(--ice);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  line-height: 1.1;
  text-align: center;
  overflow: hidden;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.15s, color 0.15s, transform 0.08s;
}
.cell:active {
  transform: scale(0.95);
}
.cell .txt {
  display: block;
  width: 100%;
  max-height: 100%;
  overflow-wrap: normal;
}
.cell.marked {
  background: var(--mark);
  border-color: var(--navy);
  color: #fff;
}
.cell.marked::after {
  content: "";
  position: absolute;
  inset: 12%;
  border-radius: 50%;
  border: 3px solid rgba(255, 193, 7, 0.85);
  pointer-events: none;
}
.cell.free {
  background: var(--navy);
  color: var(--paper);
  font-weight: 800;
  cursor: default;
}
.cell.free::after {
  display: none;
}
.cell.win {
  background: var(--gold);
  border-color: #ff8f00;
  color: var(--ink);
  animation: pulse 0.8s ease-in-out infinite alternate;
}
.cell.win::after {
  border-color: var(--navy);
}

.grid.locked .cell {
  cursor: default;
}

@keyframes pulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.06);
  }
}
.players {
  margin-top: 12px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-radius: 12px;
  padding: 10px 14px;
}
.players summary {
  cursor: pointer;
  font-weight: 600;
}
.players ul {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
}
.players li {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 0.95rem;
}
.players li.away {
  opacity: 0.55;
}
.players li.me {
  font-weight: 700;
  color: var(--gold);
}

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(11, 61, 145, 0.82);
  backdrop-filter: blur(3px);
  z-index: 10;
  animation: fade 0.25s ease-out;
}

.overlay-box {
  width: 100%;
  max-width: 400px;
  background: var(--paper);
  border-radius: 20px;
  padding: 24px 20px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  animation: pop 0.4s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.overlay-title {
  font-size: 3.2rem;
  font-weight: 900;
  color: var(--navy);
  letter-spacing: 2px;
  line-height: 1.05;
}

.overlay-winner {
  font-size: 1.2rem;
  font-weight: 700;
  margin: 4px 0 14px;
}
.overlay-winner.me {
  color: #2e7d32;
}

.overlay-phrases {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
}
.overlay-phrases li {
  background: var(--ice);
  color: var(--navy);
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.85rem;
  font-weight: 600;
}

.overlay-countdown {
  color: var(--muted);
  font-size: 0.95rem;
}

@keyframes fade {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
@keyframes pop {
  from {
    transform: scale(0.6);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
.confetti {
  position: fixed;
  top: -12px;
  width: 9px;
  height: 14px;
  z-index: 11;
  pointer-events: none;
  animation: fall linear forwards;
}

@keyframes fall {
  to {
    transform: translateY(110vh) rotate(720deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .cell.win, .overlay-box, .confetti {
    animation: none;
  }
}
.settings {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 10px);
  right: calc(env(safe-area-inset-right) + 12px);
  z-index: 20;
}

.settings-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s;
}
.settings-btn:hover, .settings-btn[aria-expanded=true] {
  background: rgba(255, 255, 255, 0.28);
}
.settings-btn:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.settings-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 210px;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: var(--paper);
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  animation: fade 0.15s ease-out;
}
.settings-menu button {
  display: block;
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  color: var(--navy);
  background: none;
  border: none;
  border-radius: 8px;
  cursor: pointer;
}
.settings-menu button:hover, .settings-menu button:focus-visible {
  background: var(--ice);
  outline: none;
}

.settings-divider {
  height: 1px;
  margin: 6px 4px;
  background: #cfd8e3;
}

.settings-version {
  padding: 2px 12px 6px;
  font-size: 0.8rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.modal {
  z-index: 30;
}

.modal-box {
  width: 100%;
  max-width: 420px;
  background: var(--paper);
  border-radius: 18px;
  padding: 22px 20px 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
  animation: pop 0.3s cubic-bezier(0.2, 1.4, 0.4, 1);
}
.modal-box h2 {
  margin: 0 0 4px;
  font-size: 1.35rem;
  color: var(--navy);
}
.modal-box label {
  margin-top: 14px;
}
.modal-box textarea {
  width: 100%;
  font: inherit;
  font-size: 1.05rem;
  padding: 10px 12px;
  border: 2px solid #cfd8e3;
  border-radius: 12px;
  outline: none;
  resize: vertical;
}
.modal-box textarea:focus {
  border-color: var(--blue);
}

.modal-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.form-message {
  min-height: 1.3em;
  margin: 10px 0 0;
  font-size: 0.95rem;
  font-weight: 600;
}
.form-message.error {
  color: #c62828;
}
.form-message.success {
  color: #2e7d32;
}

.modal-actions {
  display: flex;
  gap: 10px;
}
.modal-actions .btn {
  margin-top: 10px;
}
.modal-actions .btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.btn-secondary {
  color: var(--navy);
  background: var(--ice);
}
