* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #e6f4ff;
  background: radial-gradient(ellipse at top, #1d4e89 0%, #13315c 45%, #0b2545 100%);
  display: flex;
  justify-content: center;
}

main {
  position: relative;
  width: 100%;
  max-width: 560px;
  padding: 24px 16px 40px;
  text-align: center;
}

h1 {
  margin: 0;
  font-size: 2.4rem;
  letter-spacing: 1px;
  color: #ffb4a2;
  text-shadow: 0 2px 12px rgba(255, 127, 80, 0.45);
}

header {
  position: relative;
}

.help-button {
  position: absolute;
  top: -4px;
  right: 0;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 2px solid #9ef0e0;
  color: #9ef0e0;
  background: #0b2545;
  box-shadow: none;
  font-size: 1.2rem;
  line-height: 1;
}

.help-button:hover {
  background: #163b68;
  filter: none;
}

.help-button:active {
  transform: scale(0.95);
  box-shadow: none;
}

.title-octo {
  width: 1.15em;
  height: 1.15em;
  vertical-align: -0.2em;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.3));
}

.rules {
  margin: 8px auto 18px;
  max-width: 440px;
  opacity: 0.8;
  font-size: 0.95rem;
  line-height: 1.4;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  width: min(92vw, 480px);
  margin: 0 auto 14px;
}

select {
  margin-left: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #7fb8e6;
  background: #0b2545;
  color: #e6f4ff;
  font-size: 0.95rem;
}

.stats {
  display: flex;
  gap: 16px;
  font-size: 0.95rem;
}

.stats strong {
  color: #9ef0e0;
  font-variant-numeric: tabular-nums;
}

.mode-switch {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 2px;
}

.mode-switch a {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid #7fb8e6;
  border-radius: 999px;
  color: #e6f4ff;
  font-size: 0.85rem;
  text-decoration: none;
}

.mode-switch a:hover {
  background: rgba(127, 184, 230, 0.18);
}

.level-menu {
  width: min(92vw, 480px);
  margin: 12px auto 14px;
  padding: 12px;
  border: 1px solid rgba(127, 184, 230, 0.5);
  border-radius: 18px;
  background: rgba(11, 37, 69, 0.55);
}

.level-menu-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 0 4px 10px;
}

.level-menu-title h2 {
  margin: 0;
  color: #ffb4a2;
  font-size: 1rem;
}

.level-menu-title span {
  color: #9ef0e0;
  font-size: 0.78rem;
}

.levels-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.level-card {
  min-width: 0;
  padding: 7px 3px;
  border: 1px solid rgba(127, 184, 230, 0.45);
  border-radius: 10px;
  color: #e6f4ff;
  background: rgba(19, 49, 92, 0.8);
  box-shadow: none;
  font-size: 0.72rem;
  line-height: 1.2;
}

.level-card:hover {
  background: #1d4e89;
  filter: none;
}

.level-card:active {
  transform: translateY(1px);
  box-shadow: none;
}

.level-card.current {
  border-color: #ffb4a2;
  color: #0b2545;
  background: #ffb4a2;
}

.level-card.completed {
  border-color: #9ef0e0;
}

.level-card.locked {
  opacity: 0.45;
  cursor: not-allowed;
}

.level-number,
.level-time {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.level-time {
  margin-top: 3px;
  font-size: 0.65rem;
  opacity: 0.8;
}

.levels-previous {
  margin-top: 10px;
  padding: 7px 12px;
  font-size: 0.78rem;
  color: #e6f4ff;
  background: #1d4e89;
  box-shadow: none;
}

.levels-previous:active {
  box-shadow: none;
}

.board-wrap {
  position: relative;
  width: min(92vw, 480px);
  margin: 0 auto;
}

.board {
  --n: 5;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  grid-template-rows: repeat(var(--n), 1fr);
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 6px solid #071a34;
  border-radius: 42px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  background: #0b2545;
  user-select: none;
  -webkit-user-select: none;
}

.cell {
  --c: #ffffff;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--c);
  border: 1px solid rgba(11, 37, 69, 0.12);
  cursor: pointer;
  touch-action: manipulation;
  font-size: calc(min(92vw, 480px) / var(--n) * 0.6);
  line-height: 1;
  transition: background-color 0.15s;
}

.cell:hover { filter: brightness(1.05); }

/* Slim separators where the colored regions meet */
.cell.b-t { border-top: 1px solid #0b2545; }
.cell.b-r { border-right: 1px solid #0b2545; }
.cell.b-b { border-bottom: 1px solid #0b2545; }
.cell.b-l { border-left: 1px solid #0b2545; }

.cell.bad {
  background-color: #ff8fa3;
  box-shadow: inset 0 0 0 3px #e63950;
}

.cell.wrong {
  animation: wrong 0.6s ease-out;
}

@keyframes wrong {
  0%, 40% { background-color: #e63950; }
  100%    { background-color: var(--c); }
}

.board.shake {
  animation: shake 0.4s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

.cell .mark {
  color: #0b2545;
  opacity: 0.55;
  font-size: 0.8em;
  font-weight: 700;
}

.cell .octo {
  display: block;
  width: 76%;
  height: 76%;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.35));
}

.win {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(11, 37, 69, 0.88);
  border-radius: 42px;
  backdrop-filter: blur(3px);
  text-align: center;
}

.win h2 {
  margin: 0;
  font-size: 2rem;
  color: #ffd60a;
}

.hidden { display: none !important; }

.help-panel {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 82px 16px 24px;
  background: rgba(3, 16, 35, 0.7);
  backdrop-filter: blur(4px);
}

.help-card {
  position: relative;
  width: min(92vw, 440px);
  padding: 28px 28px 22px;
  border: 3px solid #071a34;
  border-radius: 28px;
  background: #e6f4ff;
  color: #0b2545;
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.45);
  text-align: left;
  line-height: 1.45;
}

.help-card h2 {
  margin: 0 0 14px;
  color: #d95388;
}

.help-card p {
  margin: 10px 0 0;
}

.help-close {
  position: absolute;
  top: 10px;
  right: 12px;
  padding: 2px 8px;
  color: #0b2545;
  background: transparent;
  box-shadow: none;
  font-size: 1.5rem;
  line-height: 1;
}

.help-close:hover,
.help-close:active {
  background: transparent;
  box-shadow: none;
  filter: none;
}

.buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 18px;
}

button {
  padding: 10px 18px;
  border: none;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  color: #0b2545;
  background: linear-gradient(135deg, #ffb4a2, #ff7f7f);
  box-shadow: 0 4px 0 #c4544f;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}

button:hover { filter: brightness(1.07); }

button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #c4544f;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

.legend {
  margin-top: 22px;
  font-size: 0.85rem;
  opacity: 0.7;
  line-height: 1.5;
}
