/* Chris 30 år — layout & components. Colors/fonts/radii come from theme.css. */

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--fs-base);
  line-height: 1.45;
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3 {
  font-family: var(--font-heading);
  margin: 0 0 var(--space-2);
  color: var(--color-text);
}

a {
  color: inherit;
}

button,
input {
  font-family: inherit;
  font-size: inherit;
}

.container {
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: var(--space-4) var(--space-4) calc(var(--space-7) + var(--space-5));
}

.hidden {
  display: none !important;
}

/* ---------- Top brand header ---------- */

.brand-header {
  text-align: center;
  padding: var(--space-5) var(--space-3) var(--space-3);
}

.brand-header h1 {
  font-size: var(--fs-xxl);
  color: var(--color-primary);
}

.brand-header p {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tester-badge {
  display: inline-block;
  margin-top: var(--space-1);
  background: var(--color-accent);
  color: var(--color-green-950);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
}

.reset-test-btn {
  margin-top: var(--space-3);
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-target);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-pill);
  border: 2px solid transparent;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.1s ease, box-shadow 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--color-accent);
  color: var(--color-green-950);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--color-accent-strong);
}

.btn-secondary {
  background: var(--color-primary);
  color: var(--color-text-on-dark);
}

.btn-ghost {
  background: transparent;
  border-color: var(--color-border-soft);
  color: var(--color-text);
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-lg {
  font-size: var(--fs-md);
  padding: var(--space-4) var(--space-5);
}

/* ---------- Cards / surfaces ---------- */

.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  border: 1px solid var(--color-border-soft);
}

.card + .card {
  margin-top: var(--space-4);
}

/* ---------- Auth ---------- */

.auth-card {
  max-width: 420px;
  margin: var(--space-4) auto 0;
}

.auth-toggle {
  display: flex;
  background: var(--color-surface-raised);
  border-radius: var(--radius-pill);
  padding: 4px;
  margin-bottom: var(--space-4);
  border: 1px solid var(--color-border-soft);
}

.auth-toggle button {
  flex: 1;
  border: none;
  background: transparent;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  font-weight: 600;
  color: var(--color-text-muted);
  cursor: pointer;
  min-height: 40px;
}

.auth-toggle button.active {
  background: var(--color-primary);
  color: var(--color-text-on-dark);
}

.field {
  margin-bottom: var(--space-4);
}

.field label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: 600;
  margin-bottom: var(--space-1);
  color: var(--color-text-muted);
}

.field input {
  width: 100%;
  min-height: var(--tap-target);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border-soft);
  background: var(--color-surface-raised);
  color: var(--color-text);
}

.field input:focus {
  outline: 3px solid var(--color-accent);
  outline-offset: 1px;
}

.form-error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-size: var(--fs-sm);
  margin-bottom: var(--space-4);
}

.form-hint {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  margin-top: calc(-1 * var(--space-2));
  margin-bottom: var(--space-4);
}

/* ---------- Tabs (bottom nav) ---------- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  background: var(--color-primary);
  box-shadow: 0 -4px 14px rgba(0, 0, 0, 0.25);
  z-index: 20;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tabbar button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--color-cream-200);
  opacity: 0.75;
  padding: var(--space-3) var(--space-2);
  font-weight: 600;
  min-height: var(--tap-target);
  cursor: pointer;
  border-top: 3px solid transparent;
}

.tabbar button.active {
  opacity: 1;
  color: var(--color-accent-strong);
  border-top-color: var(--color-accent);
}

/* ---------- Calendar grid ---------- */

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.door {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: var(--radius-md);
  border: 2px solid var(--color-border-soft);
  background: var(--color-surface-raised);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  color: var(--color-text);
  padding: var(--space-1);
  text-align: center;
  min-height: var(--tap-target);
}

.door .door-num {
  font-family: var(--font-heading);
  font-size: var(--fs-md);
  font-weight: 700;
}

.door .door-sub {
  font-size: var(--fs-xs);
  color: var(--color-text-muted);
  line-height: 1.1;
}

.door--locked {
  background: var(--color-locked-bg);
  color: var(--color-locked-fg);
  border-color: var(--color-locked-bg);
  cursor: default;
}

.door--locked .door-sub {
  color: var(--color-locked-fg);
}

.door--today {
  border-color: var(--color-today-ring);
  box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.4), var(--shadow-sm);
  background: var(--color-cream-100);
}

.door--played {
  background: var(--color-primary);
  color: var(--color-text-on-dark);
  border-color: var(--color-primary);
}

.door--played .door-sub {
  color: var(--color-gold-300);
}

.door--soon {
  background: var(--color-surface);
  border-style: dashed;
  color: var(--color-text-muted);
  cursor: default;
}

/* ---------- Leaderboard ---------- */

.leaderboard-list {
  list-style: none;
  margin: var(--space-4) 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.leaderboard-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-md);
  padding: var(--space-3);
}

.leaderboard-rank {
  width: 2.2em;
  height: 2.2em;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-text-on-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.leaderboard-row.rank-1 .leaderboard-rank {
  background: #c9a227;
  color: var(--color-green-950);
}

.leaderboard-row.rank-2 .leaderboard-rank {
  background: #b9c0c4;
  color: var(--color-green-950);
}

.leaderboard-row.rank-3 .leaderboard-rank {
  background: #b07a4e;
  color: var(--color-cream-100);
}

.leaderboard-name {
  flex: 1;
  font-weight: 600;
}

.leaderboard-meta {
  font-size: var(--fs-sm);
  color: var(--color-text-muted);
  text-align: right;
}

/* ---------- Game screens ---------- */

.game-topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--color-primary);
  color: var(--color-text-on-dark);
  padding: var(--space-3) var(--space-4);
}

.game-topbar .back-link {
  font-size: var(--fs-lg);
  text-decoration: none;
  color: var(--color-text-on-dark);
  min-width: var(--tap-target);
  min-height: var(--tap-target);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: calc(-1 * var(--space-2));
}

.game-topbar .game-title {
  flex: 1;
  font-weight: 700;
  font-size: var(--fs-md);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: var(--fs-lg);
  background: rgba(0, 0, 0, 0.25);
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
}

.game-body {
  padding: var(--space-4);
  padding-bottom: var(--space-7);
}

.prestart-intro {
  color: var(--color-text);
  margin: var(--space-3) 0 var(--space-5);
}

.result-time {
  font-size: var(--fs-xxl);
  font-family: var(--font-heading);
  color: var(--color-primary);
  text-align: center;
  margin: var(--space-3) 0;
}

.result-misses {
  text-align: center;
  color: var(--color-text-muted);
  margin-bottom: var(--space-4);
}

/* ---------- Find engine ---------- */

.find-viewport {
  position: relative;
  width: 100%;
  height: 62vh;
  min-height: 320px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--color-green-950);
  touch-action: none;
  border: 2px solid var(--color-border-soft);
}

.find-viewport img {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
  max-width: none;
}

.find-target-card {
  position: absolute;
  left: var(--space-3);
  bottom: var(--space-3);
  background: var(--color-cream-100);
  border: 2px solid var(--color-accent);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  box-shadow: var(--shadow-md);
  z-index: 5;
  text-align: center;
}

.find-target-card img {
  display: block;
  width: 72px;
  height: 72px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.find-target-card span {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 700;
  margin-top: 2px;
  color: var(--color-primary);
}

.find-hint {
  text-align: center;
  color: var(--color-text-muted);
  font-size: var(--fs-sm);
  margin-top: var(--space-2);
}

.marker {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  z-index: 6;
}

.marker-hit {
  border: 4px solid var(--color-success);
  background: rgba(63, 125, 77, 0.25);
  animation: pop-in 0.25s ease;
}

.marker-miss {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  background: var(--color-danger);
  font-weight: 700;
  font-size: var(--fs-sm);
  border-radius: var(--radius-pill);
  padding: 2px 10px;
  animation: float-up-fade 0.9s ease forwards;
  white-space: nowrap;
  transform: translate(-50%, -50%);
}

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

@keyframes float-up-fade {
  0% {
    transform: translate(-50%, -50%);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, calc(-50% - 24px));
    opacity: 0;
  }
}

/* ---------- Diff engine ---------- */

.diff-progress {
  text-align: center;
  font-weight: 700;
  color: var(--color-primary);
  background: var(--color-surface-raised);
  display: inline-block;
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  margin: 0 auto var(--space-4);
  border: 1px solid var(--color-border-soft);
}

.diff-progress-wrap {
  text-align: center;
}

.diff-stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

@media (min-width: 760px) {
  .diff-stack {
    flex-direction: row;
  }
}

.diff-image-wrap {
  position: relative;
  flex: 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid var(--color-border-soft);
  touch-action: manipulation;
}

.diff-image-wrap img {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

/* ---------- Memory engine ---------- */

.memory-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
}

@media (min-width: 620px) {
  .memory-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.memory-grid.blocked {
  pointer-events: none;
}

.memory-card {
  aspect-ratio: 3 / 4.2;
  perspective: 800px;
  cursor: pointer;
}

.memory-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.4s;
  transform-style: preserve-3d;
}

.memory-card.flipped .memory-card-inner,
.memory-card.matched .memory-card-inner {
  transform: rotateY(180deg);
}

.memory-card-face {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid var(--color-border-soft);
}

.memory-card-face img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.memory-card-face.back {
  transform: rotateY(180deg);
}

.memory-card.matched {
  opacity: 0.55;
}

/* ---------- Utility ---------- */

.loading {
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-6) 0;
}

@media (max-width: 360px) {
  .container {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
  }
}

/* ---------- Toast (network error feedback) ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0));
  transform: translate(-50%, 12px);
  background: var(--color-primary);
  color: var(--color-text-on-dark);
  padding: var(--space-3) var(--space-5);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm);
  font-weight: 600;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  max-width: calc(100% - var(--space-6));
  text-align: center;
}

.toast.toast-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}
