:root {
  --bg: #f4f8fb;
  --panel: #ffffff;
  --ink: #10243a;
  --muted: #4a6177;
  --blue: #3f78b5;
  --blue-border: #2e5d8e;
  --red: #d63c33;
  --yellow: #f4cf40;
  --cell-size: 52px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 20% -10%, #dbeeff 0%, transparent 60%),
    radial-gradient(900px 500px at 95% 10%, #ffe7d1 0%, transparent 55%),
    var(--bg);
  display: grid;
  place-items: center;
  padding: 20px;
}

.app {
  width: min(100%, 620px);
  background: var(--panel);
  border-radius: 22px;
  padding: 26px 22px 30px;
  box-shadow: 0 18px 42px rgba(16, 36, 58, 0.14);
}

h1 {
  margin: 0;
  text-align: center;
  letter-spacing: 0.08em;
}

.subtitle,
.rules {
  margin: 10px 0 0;
  text-align: center;
  color: var(--muted);
}

.grid {
  margin-top: 24px;
  display: grid;
  gap: 10px;
}

.row {
  display: grid;
  grid-template-columns: repeat(7, var(--cell-size));
  justify-content: center;
  gap: 8px;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 2px solid var(--blue-border);
  border-radius: 10px;
  background: #ffffff;
  color: var(--ink);
  font-size: 1.45rem;
  font-weight: 700;
  text-align: center;
  text-transform: uppercase;
  outline: none;
  transition: transform 0.15s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.cell:focus {
  transform: translateY(-1px);
  border-color: #1b3a5a;
  box-shadow: 0 0 0 3px rgba(63, 120, 181, 0.25);
}

.cell:disabled {
  cursor: default;
}

.cell.fixed {
  background: var(--red);
  border-color: var(--red);
  color: #ffffff;
}

.cell.correct {
  background: var(--red);
  border-color: var(--red);
  color: #ffffff;
}

.cell.present {
  background: var(--yellow);
  border-color: #c6a010;
  color: #222222;
  border-radius: 50%;
}

.cell.absent {
  background: var(--blue);
  border-color: var(--blue-border);
  color: #ffffff;
}

.status {
  min-height: 24px;
  margin: 14px 0 0;
  text-align: center;
  color: #10324f;
  font-weight: 600;
}

.reopen-btn {
  display: none;
  margin-top: 16px;
  width: 100%;
}

.reopen-btn:not(.hidden) {
  display: block;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 24, 39, 0.55);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal.hidden {
  display: none;
}

.modal-content {
  width: min(100%, 520px);
  background: #ffffff;
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 16px 36px rgba(10, 24, 39, 0.2);
}

.modal-content h2 {
  margin: 0 0 8px;
  font-size: 1.5rem;
  color: var(--ink);
}

#winMessage {
  margin: 6px 0 16px;
  font-size: 1rem;
  color: var(--muted);
}

.result-preview {
  background: linear-gradient(135deg, #f0f7ff 0%, #fef9f0 100%);
  border: 2px solid var(--blue);
  border-radius: 14px;
  padding: 16px;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  font-family: monospace;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: center;
  letter-spacing: 2px;
  color: var(--ink);
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

button {
  flex: 1;
  border: 0;
  border-radius: 12px;
  background: var(--blue);
  color: #ffffff;
  padding: 12px 16px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(63, 120, 181, 0.3);
}

button:active {
  transform: translateY(0);
}

.copy-status {
  min-height: 20px;
  margin: 10px 0 0;
  color: #1b5d2a;
  font-weight: 600;
}

@media (max-width: 560px) {
  :root {
    --cell-size: 42px;
  }

  .app {
    padding: 20px 12px 24px;
  }

  .row {
    gap: 5px;
  }

  .cell {
    font-size: 1.2rem;
  }
}