:root {
  --bg: #edf4ff;
  --bg-accent: #dfe9fb;
  --surface: rgba(255, 255, 255, 0.9);
  --surface-strong: rgba(255, 255, 255, 0.96);
  --surface-soft: rgba(255, 255, 255, 0.72);
  --border: rgba(16, 39, 77, 0.1);
  --text: #10274d;
  --muted: #61789e;
  --accent: #17315f;
  --accent-strong: #3c6db5;
  --success: #28906f;
  --danger: #b6516b;
  --shadow: 0 24px 60px rgba(34, 64, 120, 0.12);
}

body[data-theme="dark"] {
  --bg: #071321;
  --bg-accent: #0c1e34;
  --surface: rgba(10, 22, 40, 0.86);
  --surface-strong: rgba(12, 26, 47, 0.94);
  --surface-soft: rgba(18, 33, 58, 0.7);
  --border: rgba(168, 195, 237, 0.12);
  --text: #edf4ff;
  --muted: #9bb0d0;
  --accent: #edf4ff;
  --accent-strong: #8ab1ea;
  --success: #61d8aa;
  --danger: #f08aa3;
  --shadow: 0 28px 68px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at top right, rgba(119, 168, 237, 0.18), transparent 24%),
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.75), transparent 24%),
    linear-gradient(180deg, #fbfdff 0%, var(--bg) 58%, var(--bg-accent) 100%);
  color: var(--text);
  font-family: "Manrope", sans-serif;
}

button,
input,
a {
  font: inherit;
}

img,
video {
  display: block;
  max-width: 100%;
}

video {
  transform: scaleX(-1);
}

a {
  color: inherit;
}

.hidden {
  display: none !important;
}

.app-shell {
  width: min(100%, 460px);
  height: 100vh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 14px calc(env(safe-area-inset-bottom, 0px) + 16px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
}

.app-shell-page {
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
  flex: 0 0 auto;
}

.brand-row {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-link {
  text-decoration: none;
}

.brand-mark,
.footer-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand-title {
  display: block;
  font-size: 1.1rem;
  font-weight: 800;
}

.brand-subtitle {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.desktop-nav {
  display: none;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.theme-toggle,
.icon-button,
.primary-button,
.secondary-button,
.secondary-link,
.desktop-link-button,
.drawer-link,
.footer-button {
  transition:
    transform 160ms ease,
    background-color 160ms ease,
    color 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

.theme-toggle,
.icon-button {
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
}

.theme-toggle {
  min-height: 44px;
  padding: 0 16px;
  font-size: 0.83rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
}

.menu-button {
  flex-direction: column;
}

.menu-button span {
  width: 16px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
}

.desktop-start {
  display: none;
}

.panel,
.camera-card,
.emoji-card,
.save-card,
.score-chip,
.tutorial-card,
.menu-drawer,
.page-panel,
.page-cta {
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.status-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 0;
  flex: 0 0 auto;
}

.score-chip {
  border-radius: 22px;
  padding: 12px;
}

.score-chip span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.score-chip strong,
#timerValue,
#matchValue,
.leaderboard-rank,
.leaderboard-score,
.step-number {
  font-family: "IBM Plex Mono", monospace;
}

.game-layout {
  display: grid;
  gap: 14px;
  flex: 1 1 auto;
  min-height: 0;
}

.game-left,
.game-right {
  display: grid;
  gap: 14px;
  min-height: 0;
}

.camera-card,
.emoji-card,
.save-card,
.metrics-card,
.page-panel,
.page-cta {
  border-radius: 28px;
}

.camera-stage {
  position: relative;
  overflow: hidden;
  border-radius: 28px;
  background:
    radial-gradient(circle at top right, rgba(126, 172, 229, 0.2), transparent 28%),
    #dbe6f8;
}

body[data-theme="dark"] .camera-stage {
  background:
    radial-gradient(circle at top right, rgba(129, 176, 241, 0.22), transparent 30%),
    #122641;
}

#camera {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
}

.camera-topline,
.camera-bottomline {
  position: absolute;
  left: 14px;
  right: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.camera-topline {
  top: 14px;
}

.camera-bottomline {
  bottom: 14px;
  align-items: end;
}

.status-pill,
.face-status,
.panel-label {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  padding: 8px 12px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.status-pill,
.face-status {
  font-size: 10px;
}

.timer-meta span {
  display: block;
  margin-bottom: 6px;
  color: rgba(255, 255, 255, 0.86);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.timer-meta strong {
  color: white;
  font-size: 0.94rem;
}

.timer-rail,
.match-rail,
.metric-rail {
  border-radius: 999px;
  overflow: hidden;
}

.timer-rail {
  flex: 1;
  height: 8px;
  background: rgba(255, 255, 255, 0.24);
}

.timer-bar {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #7eace5, var(--accent-strong), var(--accent));
}

.emoji-card,
.save-card,
.metrics-card,
.page-panel,
.page-cta {
  padding: 16px;
}

.emoji-header,
.section-head-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.emoji-main {
  text-align: center;
  padding: 12px 0 10px;
}

.emoji-value {
  font-size: clamp(4.2rem, 9vw, 5.8rem);
  line-height: 1;
}

.emoji-main h1,
.page-hero h1,
.tutorial-card h2,
.page-cta h2,
.tutorial-step h2 {
  margin: 10px 0 8px;
  line-height: 0.98;
}

.emoji-main h1 {
  font-size: clamp(2rem, 5vw, 3.2rem);
}

.emoji-main p,
.save-card p,
.section-head p,
.empty-state,
.tutorial-list li,
.page-hero p,
.tutorial-step p {
  color: var(--muted);
  line-height: 1.55;
  font-size: 0.95rem;
}

.feedback-text {
  margin-top: 8px;
}

#matchValue {
  color: var(--accent);
  font-size: 0.95rem;
}

.match-rail {
  height: 10px;
  margin-top: 6px;
  margin-bottom: 12px;
  background: rgba(16, 39, 77, 0.08);
}

.match-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #8bc8b2, #49a485, var(--success));
}

.full-width {
  width: 100%;
}

.primary-button,
.secondary-button,
.secondary-link,
.desktop-link-button {
  min-height: 52px;
  border-radius: 999px;
  padding: 0 22px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  text-decoration: none;
  justify-content: center;
  align-items: center;
}

.primary-button,
.desktop-link-button {
  display: inline-flex;
  border: 0;
  background: var(--accent);
  color: white;
  cursor: pointer;
}

body[data-theme="dark"] .primary-button,
body[data-theme="dark"] .desktop-link-button {
  color: #08162b;
}

.secondary-button,
.secondary-link {
  display: inline-flex;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--accent);
}

input {
  width: 100%;
  margin: 10px 0 10px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--text);
  padding: 14px 16px;
}

input::placeholder {
  color: var(--muted);
}

.secondary-button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.section-head {
  margin-bottom: 10px;
}

.section-head p,
.page-hero p,
.save-card p,
.footer-copy {
  margin: 10px 0 0;
}

.metrics-list,
.leaderboard-list,
.page-grid {
  display: grid;
  gap: 10px;
}

.metric-item {
  display: grid;
  gap: 8px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 13px;
}

.metric-rail {
  height: 8px;
  background: rgba(16, 39, 77, 0.1);
}

.metric-fill {
  height: 100%;
  background: linear-gradient(90deg, #7ca9e1, var(--accent-strong));
}

.empty-state {
  border: 1px dashed var(--border);
  border-radius: 20px;
  padding: 14px;
}

.leaderboard-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
}

.leaderboard-rank {
  font-size: 12px;
  color: var(--muted);
}

.leaderboard-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.leaderboard-score {
  font-size: 1.05rem;
  font-weight: 600;
}

.error-banner {
  margin-top: 14px;
  border-radius: 18px;
  padding: 13px 14px;
  border: 1px solid rgba(191, 97, 118, 0.24);
  background: rgba(191, 97, 118, 0.12);
  color: #8a2b41;
}

body[data-theme="dark"] .error-banner {
  color: #ffc1cf;
}

.modal-backdrop,
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(8, 20, 46, 0.38);
  backdrop-filter: blur(10px);
}

.modal-backdrop {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.tutorial-card {
  position: relative;
  z-index: 41;
  width: min(100%, 420px);
  border-radius: 28px;
  padding: 22px;
  background: var(--surface-strong);
  pointer-events: auto;
}

.tutorial-card h2 {
  font-size: clamp(1.9rem, 4vw, 2.5rem);
}

.tutorial-list {
  margin: 0 0 16px;
  padding-left: 18px;
}

.tutorial-actions {
  display: flex;
  justify-content: flex-end;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
}

.menu-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 42;
  width: min(82vw, 320px);
  padding: 18px;
  border-radius: 28px 0 0 28px;
  transform: translateX(100%);
  transition: transform 180ms ease;
}

.menu-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.drawer-title {
  display: block;
  font-size: 1.2rem;
  font-weight: 800;
}

.drawer-subtitle {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.drawer-section {
  display: grid;
  gap: 10px;
}

.drawer-link {
  width: 100%;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--text);
  padding: 14px 16px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.drawer-link-strong {
  background: var(--accent);
  color: white;
}

body[data-theme="dark"] .drawer-link-strong {
  color: #08162b;
}

.page-hero {
  margin: 4px 0 8px;
  flex: 0 0 auto;
}

.page-hero h1 {
  font-size: clamp(2.6rem, 6vw, 4.8rem);
}

.page-panel {
  min-height: 100%;
}

.page-grid {
  grid-template-columns: 1fr;
  flex: 1 1 auto;
  min-height: 0;
}

.tutorial-step h2 {
  font-size: 1.45rem;
}

.step-number {
  color: var(--accent-strong);
  font-size: 0.86rem;
  letter-spacing: 0.14em;
}

.page-cta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 0;
  flex: 0 0 auto;
}

.leaderboard-list-large .leaderboard-item {
  padding: 18px 20px;
}

.site-footer {
  margin-top: 0;
  padding: 8px 4px 10px;
  color: var(--muted);
  flex: 0 0 auto;
}

.footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 1rem;
  font-weight: 800;
}

.footer-email {
  display: inline-block;
  margin-top: 14px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  margin-top: 16px;
}

.footer-nav a,
.footer-button {
  color: var(--text);
  text-decoration: none;
  font-size: 0.95rem;
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.footer-copy {
  font-size: 0.88rem;
  line-height: 1.5;
}

.theme-toggle:hover,
.icon-button:hover,
.primary-button:hover,
.secondary-button:hover,
.secondary-link:hover,
.desktop-link-button:hover,
.drawer-link:hover,
.footer-button:hover {
  transform: translateY(-1px);
}

@media (min-width: 900px) {
  .app-shell {
    width: min(1240px, calc(100vw - 48px));
    padding-left: 0;
    padding-right: 0;
    padding-top: 18px;
    gap: 12px;
  }

  .site-header {
    gap: 24px;
  }

  .desktop-nav {
    display: flex;
    align-items: center;
    gap: 26px;
    margin-left: auto;
  }

  .desktop-nav a {
    color: var(--muted);
    text-decoration: none;
    font-weight: 600;
  }

  .desktop-start {
    display: inline-flex;
  }

  .menu-button,
  .menu-drawer,
  .drawer-backdrop {
    display: none !important;
  }

  .status-row {
    grid-template-columns: repeat(4, minmax(0, 190px));
    justify-content: start;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.7fr);
    gap: 16px;
    align-items: start;
  }

  #camera {
    aspect-ratio: 16 / 9.4;
  }

  .emoji-card {
    min-height: 100%;
  }

  .emoji-main {
    padding-top: 24px;
    padding-bottom: 16px;
  }

  .emoji-value {
    font-size: clamp(5.2rem, 6vw, 6.8rem);
  }

  .emoji-main h1 {
    font-size: clamp(2.8rem, 3.5vw, 4rem);
  }

  .page-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
  }

  .page-cta {
    padding: 18px 20px;
  }

  .site-footer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px 28px;
    align-items: center;
  }

  .footer-email {
    margin-top: 0;
  }

  .footer-nav {
    justify-content: flex-end;
    margin-top: 0;
  }

  .footer-copy {
    grid-column: 1 / -1;
    margin-top: 6px;
  }
}

@media (max-width: 899px) {
  .metrics-card {
    display: none;
  }

  .page-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tutorial-step {
    padding: 14px;
  }

  .tutorial-step h2 {
    font-size: 1.15rem;
  }

  .tutorial-step p,
  .page-hero p {
    font-size: 0.88rem;
  }

  .page-cta {
    padding: 14px;
  }

  .page-cta h2 {
    font-size: 1.3rem;
  }
}
