:root {
  color-scheme: dark;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #111318;
  color: #f6f7fb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background: #111318;
}

button, input { font: inherit; }

.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
}

.login-screen {
  width: min(100% - 32px, 410px);
}

.login-card {
  padding: 30px;
  border: 1px solid #343946;
  border-radius: 16px;
  background: #1d2028;
  box-shadow: 0 18px 60px rgb(0 0 0 / .35);
}

.login-card p { color: #aeb4c0; }
.login-card label { display: block; margin: 20px 0 7px; color: #c7cbd4; }
.login-card input {
  width: 100%;
  margin-bottom: 14px;
  border: 1px solid #4b5261;
  border-radius: 9px;
  padding: 12px;
  color: #fff;
  background: #111318;
}
.login-card .button { width: 100%; }
.login-error { margin: 14px 0 0; color: #ff9797 !important; text-align: center; }

.page {
  width: 100%;
  margin: 0 auto;
  padding: 14px 20px 40px;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: clamp(28px, 5vw, 44px); }
.header p { margin-bottom: 0; color: #aeb4c0; }

.header-actions {
  display: flex;
  gap: 9px;
  align-items: center;
}

.game-settings {
  display: flex;
  justify-content: flex-end;
  margin: 7px 0 10px;
}

.pair-preview-setting {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #c7cbd4;
  cursor: pointer;
  user-select: none;
}

.pair-preview-setting input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: #6d5dfc;
}

.button {
  border: 0;
  border-radius: 9px;
  padding: 11px 17px;
  background: #6d5dfc;
  color: white;
  font-weight: 700;
  cursor: pointer;
}

.button:hover { background: #7d6eff; }
.button:disabled { opacity: .55; cursor: wait; }
.button-secondary { background: #303541; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 12px 0 8px;
}

.stats div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #1d2028;
}

.stats span { color: #aeb4c0; }
.stats strong span { color: inherit; }
.status { min-height: 24px; margin-bottom: 8px; color: #c7cbd4; }

.preload-panel {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(100%, 720px);
  margin: 14px auto 22px;
  color: #c7cbd4;
  font-variant-numeric: tabular-nums;
}

.preload-panel[hidden] { display: none; }
.preload-panel progress {
  width: 100%;
  height: 16px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  accent-color: #6d5dfc;
}
.preload-panel span { min-width: 52px; text-align: right; }

.board {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: clamp(2px, .45vw, 5px);
  width: min(100%, calc((100dvh - 180px) * 2));
  margin: 0 auto;
  user-select: none;
}

.card {
  position: relative;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: clamp(3px, .7vw, 8px);
  overflow: hidden;
  background: #292e39;
  cursor: pointer;
  transition: transform .14s ease, opacity .2s ease;
}

.card::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  background: #e7b835 url("assets/card-back.png") center / cover no-repeat;
}

.board.cheat-active .card:not(.revealed):not(.matched)::before {
  content: attr(data-cheat);
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 2;
  display: grid;
  width: clamp(24px, 3.2vw, 42px);
  aspect-ratio: 1;
  place-items: center;
  border: 2px solid rgb(255 255 255 / .9);
  border-radius: 50%;
  color: #111318;
  background: rgb(255 226 84 / .94);
  box-shadow: 0 2px 10px rgb(0 0 0 / .55);
  font-size: clamp(13px, 1.6vw, 21px);
  font-weight: 900;
  line-height: 1;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.card:hover { transform: translateY(-1px); }
.card img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #08090c;
}

.card.revealed::after,
.card.matched::after { display: none; }
.card.matched { opacity: 0; pointer-events: none; }
.card:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

.records {
  margin-top: 28px;
  padding: 18px 22px;
  border-radius: 12px;
  background: #1d2028;
}

.records-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}
.records h2 { margin: 0; }
.records-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}
.records-controls label { color: #aeb4c1; font-size: .9rem; }
.records-controls select {
  border: 1px solid #4b5261;
  border-radius: 8px;
  padding: 8px 10px;
  color: #fff;
  background: #111318;
}
.records-toggle { padding: 8px 12px; font-size: .9rem; }
.records ol { margin: 0; padding-left: 28px; }
.records li { padding: 4px 0 4px 6px; }
.record-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 20px;
  align-items: baseline;
}
.record-moves { color: #d4d7df; font-variant-numeric: tabular-nums; }
.record-date { color: #aeb4c1; font-size: .9rem; font-variant-numeric: tabular-nums; }
.record-time { font-variant-numeric: tabular-nums; }

.pair-preview-open { overflow: hidden; }

.pair-preview {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgb(0 0 0 / .96);
  cursor: pointer;
}

.pair-preview[hidden] { display: none; }
.pair-preview img {
  display: block;
  max-width: 96vw;
  max-height: 88dvh;
  border-radius: 12px;
  object-fit: contain;
  box-shadow: 0 12px 60px rgb(0 0 0 / .6);
}
.pair-preview p {
  position: fixed;
  bottom: max(14px, env(safe-area-inset-bottom));
  left: 50%;
  margin: 0;
  color: #d7dae2;
  font-size: 14px;
  transform: translateX(-50%);
  white-space: nowrap;
}
.pair-preview-close {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 1;
  width: 48px;
  height: 48px;
  border: 1px solid rgb(255 255 255 / .35);
  border-radius: 50%;
  color: #fff;
  background: rgb(31 34 42 / .88);
  font-size: 32px;
  line-height: 1;
  cursor: pointer;
}

dialog {
  width: min(90vw, 430px);
  border: 1px solid #3b414f;
  border-radius: 14px;
  padding: 24px;
  color: #f6f7fb;
  background: #1d2028;
}

dialog::backdrop { background: rgb(0 0 0 / .72); }
dialog label { display: block; margin: 18px 0 7px; color: #c7cbd4; }
dialog input {
  width: 100%;
  border: 1px solid #4b5261;
  border-radius: 8px;
  padding: 11px;
  color: white;
  background: #111318;
}
.dialog-actions { display: flex; gap: 9px; margin-top: 16px; }
.form-error { min-height: 20px; margin: 12px 0 0; color: #ff9797; }

@media (max-width: 620px) {
  .page { padding: 10px 4px 32px; }
  .header { padding: 0 8px; align-items: flex-end; }
  .header p { display: none; }
  .header-actions { gap: 6px; }
  .header-actions .button { padding: 9px 10px; }
  .game-settings { margin: 8px 8px 10px; }
  .pair-preview-setting { font-size: 13px; }
  .stats { margin: 14px 4px 8px; }
  .stats div { display: block; padding: 7px; text-align: center; }
  .stats div > span { display: block; font-size: 11px; }
  .status { margin-left: 6px; font-size: 13px; }
  .preload-panel { width: calc(100% - 12px); margin: 12px auto 18px; }
  .board {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    width: 100%;
  }
  .records { margin: 22px 4px 0; }
  .records-header { align-items: stretch; flex-direction: column; }
  .records-controls { display: grid; grid-template-columns: auto minmax(0, 1fr); }
  .records-controls select { width: 100%; }
  .records-toggle { grid-column: 1 / -1; }
  .record-row {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 2px 12px;
  }
  .record-time { grid-column: 2; grid-row: 1; }
  .record-moves { grid-column: 1; grid-row: 2; font-size: .9rem; }
  .record-date { grid-column: 2; grid-row: 2; }
}
