*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --cell-bg:   #C7EDD6;
  --cell-m-bg: #E5F6AE;
  --cell-sel:  #fff;
  --text:      #111;
  --success:   #4caf82;
  --error:     #e05555;
  --cs:  52px;
  --gap:  2px;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  background: #fff;
  color: #111;
  font-family: 'Lato', sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

#app {
  width: 100%;
  max-width: 420px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 20px 140px;
}

/* ── Timer ─────────────────────────────────────────────── */
#timer-area {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 0;
}

.spacer { flex: 1; }

#timer {
  font-family: 'Lato', sans-serif;
  font-size: 28px;
  font-weight: 300;
  color: #111;
  letter-spacing: 0.02em;
}

@keyframes shake {
  0%   { transform: translateX(0); }
  15%  { transform: translateX(-6px); }
  30%  { transform: translateX(6px); }
  45%  { transform: translateX(-5px); }
  60%  { transform: translateX(5px); }
  75%  { transform: translateX(-3px); }
  90%  { transform: translateX(3px); }
  100% { transform: translateX(0); }
}

/* ── Grid ──────────────────────────────────────────────── */
#grid-outer { position: relative; }

/* ── Tutorial overlay ──────────────────────────────────── */
#tut-grid-outer,
#tut-footer { position: absolute; }

#tut-footer {
  left: 0;
  right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0 32px;
}

#tut-grid .cell                { background: #e8e8e8; }
#tut-grid .cell.sel,
#tut-grid .cell.path           { background: var(--cell-sel); }
#tut-grid .cell.sel::before,
#tut-grid .cell.path::before   { background: #e8e8e8; }

#tut-text {
  font-family: 'Lato', sans-serif;
  font-size: 14px;
  font-weight: 400;
  color: #111;
  line-height: 1.6;
}

#tut-btn { margin-top: 40px; }

/* ── Shuffle hint ──────────────────────────────────────── */
#shuffle-hint {
  position: absolute;
  bottom: calc(100% + 16px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: baseline;
  gap: 8px;
  white-space: nowrap;
}

#shuffle-hint.hidden { display: none; }

#shuffle-btn {
  background: none;
  border: none;
  padding: 0;
  font-family: 'Lato', sans-serif;
  font-size: 14px;
  font-weight: 700;
  color: #111;
  cursor: pointer;
  letter-spacing: normal;
  text-transform: none;
  transition: opacity 0.15s;
}

#shuffle-btn:hover  { opacity: 0.5; }
#shuffle-btn:active { opacity: 0.3; }

#shuffle-penalty {
  font-family: 'Lato', sans-serif;
  font-size: 14px;
  font-weight: 400;
  color: #989898;
}

#grid,
#tut-grid {
  display: grid;
  grid-template-columns: repeat(6, var(--cs));
  grid-template-rows:    repeat(6, var(--cs));
  gap: var(--gap);
  position: relative;
}

/* ── Cells ─────────────────────────────────────────────── */
.cell {
  width: var(--cs);
  height: var(--cs);
  background: var(--cell-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Lato', sans-serif;
  font-size: 28px;
  font-weight: 300;
  color: #111;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.12s ease;
  z-index: 1;
}

.cell.lm { background: var(--cell-m-bg); }

.cell.sel,
.cell.path {
  background: var(--cell-sel);
}

.cell.sel::before,
.cell.path::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--cell-bg);
  border-radius: inherit;
  pointer-events: none;
  animation: fill-out 0.22s cubic-bezier(0.4, 0, 0.2, 1) forwards;
}

.cell.lm.sel::before,
.cell.lm.path::before {
  background: var(--cell-m-bg);
}

@keyframes fill-out {
  from { transform: scale(1); opacity: 1; }
  to   { transform: scale(0); opacity: 0; }
}

.cell.sel {
  transform: scale(1.08);
  z-index: 3;
}

.cell.collapsing {
  transition: opacity 0.28s ease !important;
  transform: none !important;
  opacity: 0 !important;
  pointer-events: none;
  z-index: 0;
}

/* ── Missions ──────────────────────────────────────────── */
#missions {
  position: fixed;
  bottom: 40px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(6 * var(--cs) + 5 * var(--gap));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#missions-date {
  font-family: 'Lato', sans-serif;
  font-size: 14px;
  font-weight: 400;
  color: #989898;
  margin-bottom: 4px;
}

.mission {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.mission-label {
  font-family: 'Lato', sans-serif;
  font-size: 14px;
  font-weight: 400;
  color: #111;
  transition: color 0.4s;
}

.mission.done .mission-label { color: #989898; }

.mission-count {
  font-family: 'Lato', sans-serif;
  font-size: 14px;
  font-weight: 400;
  color: #111;
  transition: color 0.4s;
  white-space: nowrap;
  padding-left: 12px;
}

.mission.done .mission-count { color: #989898; }

/* ── Overlays ──────────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(255, 255, 255, 0.96);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.overlay.hidden { display: none; }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

.card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 0 32px;
}

#logo { display: block; }

.card-sub {
  margin-top: 32px;
  font-family: 'Lato', sans-serif;
  font-size: 14px;
  font-weight: 400;
  color: #111;
  line-height: 1.6;
}

.btn {
  margin-top: 48px;
  background: none;
  color: #111;
  border: none;
  padding: 0;
  font-family: 'Lato', sans-serif;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  transition: opacity 0.15s;
}

.btn:hover  { opacity: 0.5; }
.btn:active { opacity: 0.3; }

#victory-time {
  font-family: 'Lato', sans-serif;
  font-size: 56px;
  font-weight: 300;
  color: #111;
  animation: pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

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

#victory-sub {
  font-family: 'Lato', sans-serif;
  font-size: 13px;
  font-weight: 400;
  color: #999;
}

/* ── Mobile ────────────────────────────────────────────── */
@media (max-width: 380px) {
  :root { --cs: 46px; --gap: 4px; }
  .cell { font-size: 24px; }
}

@media (max-width: 320px) {
  :root { --cs: 40px; --gap: 4px; }
  .cell { font-size: 20px; }
}
