:root {
  --spk-red: #e2001a;
  --spk-red-dark: #b40015;
  --gray: #d5d9dd;
  --gray-dark: #b7bcc2;
  --bg: #f4f5f7;
  --text: #1c1f24;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: env(safe-area-inset-top, 12px) 12px calc(env(safe-area-inset-bottom, 12px) + 12px);
  gap: 16px;
  max-width: 480px;
  margin: 0 auto;
}

.topbar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 4px;
}

.brand {
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--spk-red);
  text-align: center;
  flex: 1;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 64px;
}

.stat-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.board-wrap {
  width: 100%;
  display: flex;
  justify-content: center;
}

.board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1 / 1;
}

.cell {
  background: var(--gray);
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  touch-action: manipulation;
  transition: background-color 80ms ease, transform 80ms ease;
  border: none;
  padding: 0;
}

.cell:active {
  transform: scale(0.96);
}

.cell.active {
  background-color: var(--spk-red);
  background-image: url('logo_spk.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.hint {
  text-align: center;
  color: #6b7280;
  font-size: 0.9rem;
  min-height: 1.4em;
  margin: 0;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 26, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 10;
}

.overlay.hidden {
  display: none;
}

.modal {
  background: #fff;
  border-radius: 20px;
  padding: 24px 20px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.modal h2 {
  margin: 0 0 8px;
  color: var(--spk-red);
}

.final-score {
  font-size: 1.1rem;
  margin: 0 0 20px;
}

.final-score span {
  font-weight: 800;
  font-size: 1.4rem;
}

.rules-list {
  text-align: left;
  margin: 0 0 20px;
  padding: 0 0 0 20px;
  color: #374151;
  font-size: 0.95rem;
  line-height: 1.6;
}

.rules-list li + li {
  margin-top: 8px;
}

.rules-list strong {
  color: var(--spk-red);
}

.entry-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.entry-intro {
  font-size: 0.85rem;
  color: #6b7280;
  margin: 0 0 4px;
  text-align: center;
}

.entry-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #374151;
}

.entry-form input {
  border: 1.5px solid var(--gray-dark);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 1rem;
  font-weight: 400;
  color: var(--text);
}

.entry-form input:focus {
  outline: none;
  border-color: var(--spk-red);
}

.form-error {
  color: var(--spk-red);
  font-size: 0.85rem;
  margin: 0;
}

button {
  cursor: pointer;
  font-family: inherit;
}

#submitBtn, #playAgainBtn, #startRulesBtn {
  background: var(--spk-red);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 14px;
  font-size: 1rem;
  font-weight: 700;
  margin-top: 4px;
}

#submitBtn:active, #playAgainBtn:active, #startRulesBtn:active {
  background: var(--spk-red-dark);
}

.previous-result {
  margin-bottom: 16px;
}

.rank-info {
  margin: 10px 0 0;
  padding: 10px 14px;
  background: #fdeaec;
  border-radius: 10px;
  font-size: 0.95rem;
  color: #374151;
}

.rank-info strong {
  color: var(--spk-red);
  font-size: 1.1rem;
}

.rank-info.top-player {
  margin-top: 8px;
  background: #fff6e0;
}

.rank-info.top-player strong {
  color: #b8860b;
}

.thank-you p {
  margin: 4px 0;
}

.thank-you p:first-child {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--spk-red);
}

.hidden {
  display: none !important;
}
