:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface2: #243044;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --accent: #3d9cf5;
  --accent-hover: #5aadff;
  --success: #3dd68c;
  --warning: #f5b83d;
  --danger: #f55d5d;
  --marked: #2a6e4a;
  --free: #4a3d8f;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: linear-gradient(160deg, #0a0e14 0%, #121c2e 50%, #0f1419 100%);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.container {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.5rem;
}

.container.wide {
  max-width: 560px;
}

@media (max-width: 480px) {
  .container.wide {
    max-width: 100%;
    padding: 0.75rem;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .card-panel {
    padding: 1rem;
  }
}

header {
  text-align: center;
  margin-bottom: 2rem;
}

header h1 {
  margin: 0 0 0.25rem;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

header p {
  margin: 0;
  color: var(--muted);
}

.card-panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

input[type='email'],
input[type='text'],
textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text);
  font-size: 16px; /* prevents iOS zoom on focus */
  margin-bottom: 1rem;
}

textarea {
  min-height: 180px;
  resize: vertical;
  font-family: inherit;
}

button,
.btn {
  display: inline-block;
  padding: 0.75rem 1.25rem;
  min-height: 44px; /* Apple touch target */
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  transition: background 0.15s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button:hover,
.btn:hover {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

button.secondary:hover {
  background: #2d3d56;
}

.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.actions button,
.actions .btn {
  flex: 1 1 auto;
  min-width: min(100%, 140px);
}

.error {
  background: rgba(245, 93, 93, 0.15);
  border: 1px solid var(--danger);
  color: #ffb4b4;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.success {
  background: rgba(61, 214, 140, 0.12);
  border: 1px solid var(--success);
  color: #9ef0c5;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.info-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
  color: var(--muted);
}

.bingo-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin: 1rem 0;
  width: 100%;
}

.bingo-cell {
  aspect-ratio: 1;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  border-radius: 8px;
  background: var(--surface2);
  border: 2px solid transparent;
  font-size: clamp(0.5rem, 2.5vw, 0.75rem);
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, border-color 0.12s;
  word-break: break-word;
  line-height: 1.1;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(61, 156, 245, 0.3);
}

.bingo-cell:active:not(.marked):not(.free):not(.disabled) {
  background: #2d4a6e;
  border-color: var(--accent);
}

.bingo-cell.marked {
  background: var(--marked);
  border-color: var(--success);
}

.bingo-cell.free {
  background: var(--free);
  cursor: default;
  color: #d4c8ff;
}

.bingo-cell.disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  max-width: 400px;
  border: 2px solid var(--warning);
  animation: pop 0.35s ease;
}

.overlay-card h2 {
  margin: 0 0 0.5rem;
  font-size: 2.5rem;
  color: var(--warning);
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.overlay-actions button {
  width: 100%;
}

#overlay-restart-btn {
  font-size: 1.1rem;
  animation: restart-pulse 1.5s ease-in-out infinite;
}

.restart-hint {
  margin: 0.75rem 0 0;
  text-align: center;
  color: var(--warning);
  font-weight: 600;
  font-size: 0.95rem;
}

#restart-btn.restart-attention {
  background: var(--warning);
  color: #1a1200;
  border: none;
  font-size: 1.05rem;
  animation: restart-pulse 1.5s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(245, 166, 35, 0.5);
}

#restart-btn.restart-attention:hover {
  background: #f7b84a;
}

@keyframes restart-pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(245, 166, 35, 0.45);
  }
  50% {
    transform: scale(1.03);
    box-shadow: 0 0 16px 4px rgba(245, 166, 35, 0.35);
  }
}

@keyframes pop {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}

.copy-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

.copy-row input {
  flex: 1;
  margin-bottom: 0;
  font-size: 0.85rem;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

.hidden {
  display: none !important;
}

.contact-section.unavailable {
  opacity: 0.45;
  pointer-events: none;
  user-select: none;
}

.contact-section.unavailable input {
  cursor: not-allowed;
  background: var(--surface);
}

.optional {
  font-weight: 400;
  color: var(--muted);
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
}

.checkbox-row input {
  margin-top: 0.2rem;
  width: auto;
}

.keyword-section {
  margin-bottom: 1rem;
}

.keyword-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.keyword-header label {
  margin-bottom: 0;
}

.keyword-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  max-height: 220px;
  overflow-y: auto;
}

.keyword-list li {
  background: var(--surface2);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  line-height: 1.2;
}

@media (max-width: 400px) {
  .container {
    padding: 0.75rem;
  }

  .info-bar {
    font-size: 0.75rem;
    justify-content: center;
  }

  .bingo-cell {
    font-size: clamp(0.45rem, 2.2vw, 0.65rem);
    min-height: 48px;
  }

  .copy-row {
    flex-direction: column;
  }

  .copy-row button {
    width: 100%;
  }
}
