:root {
  --page-bg: #efe6d3;
  --panel: #fff9ec;
  --panel-soft: #f7ecd6;
  --border: #d8c49b;
  --text: #2f281c;
  --muted: #665b48;
  --green: #23543a;
  --green-dark: #153924;
  --gold: #b8872f;
  --blue: #245b7a;
  --red: #a23a2d;
  --shadow: 0 18px 42px rgba(31, 35, 24, 0.14);
}

* {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.62), transparent 26%),
    linear-gradient(180deg, #f5ead4 0%, var(--page-bg) 58%, #dfcfaa 100%);
  line-height: 1.65;
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
}

.page-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 max(48px, env(safe-area-inset-bottom));
}

.breadcrumb {
  margin: 0 0 14px;
  font-size: 0.92rem;
  color: var(--muted);
}

.breadcrumb a {
  text-decoration: none;
  border-bottom: 1px solid rgba(102, 91, 72, 0.28);
}

.hero,
.panel,
.game-shell,
.faq-panel,
.related-panel {
  background: rgba(255, 249, 236, 0.92);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.hero {
  padding: 22px 24px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--gold);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.82rem;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.15rem);
  margin-bottom: 10px;
}

h2 {
  font-size: clamp(1.35rem, 2.4vw, 1.8rem);
  margin-bottom: 10px;
}

p {
  margin: 0 0 1rem;
}

.lead {
  max-width: 74ch;
  color: var(--muted);
  font-size: 1.08rem;
}

.hero-actions,
.game-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.button,
.game-button {
  min-height: 46px;
  border-radius: 999px;
  border: 1px solid #cbb78c;
  padding: 12px 18px;
  background: #eadab7;
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
}

.button.primary,
.game-button.primary {
  border-color: transparent;
  background: linear-gradient(180deg, #d7ac52, var(--gold));
  color: #fff9ef;
  box-shadow: 0 9px 18px rgba(184, 135, 47, 0.24);
}

.game-shell {
  position: relative;
  padding: 14px;
  margin-bottom: 20px;
}

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

.status-item {
  background: rgba(255, 255, 255, 0.48);
  border: 1px solid #e3d4af;
  border-radius: 16px;
  padding: 10px 12px;
}

.status-label {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-item strong {
  display: block;
  margin-top: 4px;
  font-size: 1.12rem;
  min-height: 1.35em;
}

.game-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.difficulty-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.difficulty-group legend {
  width: 100%;
  margin-bottom: 4px;
  color: var(--muted);
  font: 700 0.76rem/1.2 system-ui, sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.difficulty-group label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 9px 13px;
  border: 1px solid #d7c49d;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.48);
  cursor: pointer;
}

.difficulty-group input {
  width: 18px;
  height: 18px;
}

.game-note {
  min-height: 1.6em;
  margin: 0 0 12px;
  color: var(--muted);
}

.memory-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(64px, 1fr));
  gap: 10px;
  padding: 18px;
  border-radius: 24px;
  background:
    radial-gradient(circle at top, rgba(255,255,255,0.10), transparent 30%),
    linear-gradient(180deg, #2b7047, var(--green) 38%, var(--green-dark));
  border: 1px solid rgba(21, 57, 36, 0.45);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.16);
}

.memory-board[data-difficulty="easy"] {
  grid-template-columns: repeat(4, minmax(68px, 1fr));
}

.memory-board[data-difficulty="hard"] {
  grid-template-columns: repeat(5, minmax(62px, 1fr));
}

.memory-card {
  position: relative;
  min-height: 92px;
  border: 0;
  border-radius: 16px;
  background: transparent;
  perspective: 800px;
  cursor: pointer;
  touch-action: manipulation;
}

.memory-card:focus-visible {
  outline: 3px solid rgba(255, 231, 159, 0.86);
  outline-offset: 4px;
}

.card-inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.28s ease;
}

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

.card-face {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 16px;
  backface-visibility: hidden;
}

.card-back {
  border: 2px solid rgba(255, 243, 199, 0.86);
  background:
    radial-gradient(circle at center, rgba(255, 243, 199, 0.24) 0 16%, transparent 17%),
    linear-gradient(135deg, #2b7047, #153924);
  box-shadow: 0 10px 20px rgba(12, 24, 14, 0.24);
}

.card-back::after {
  content: "?";
  color: rgba(255, 249, 236, 0.82);
  font-size: 2rem;
  font-weight: 800;
}

.card-front {
  transform: rotateY(180deg);
  border: 1px solid rgba(73, 58, 34, 0.22);
  background: linear-gradient(180deg, #fffef8, #efe3c7);
  box-shadow: 0 8px 16px rgba(12, 24, 14, 0.18);
  color: var(--green-dark);
}

.card-symbol {
  display: block;
  font-size: clamp(1.8rem, 5vw, 2.55rem);
  line-height: 1;
}

.card-label {
  position: absolute;
  bottom: 9px;
  left: 6px;
  right: 6px;
  color: var(--muted);
  font: 700 0.68rem/1.1 system-ui, sans-serif;
  text-align: center;
}

.memory-card.is-matched {
  cursor: default;
}

.memory-card.is-matched .card-front {
  border-color: rgba(184, 135, 47, 0.58);
  background: linear-gradient(180deg, #fff9df, #ead7a8);
}

.content-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.panel,
.faq-panel,
.related-panel {
  padding: 22px 24px;
}

.panel ul,
.panel ol {
  margin: 0;
  padding-left: 1.2rem;
}

.panel li + li {
  margin-top: 8px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid #dfcfaa;
  text-align: left;
}

th {
  color: var(--muted);
  font: 700 0.78rem/1.2 system-ui, sans-serif;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.faq-panel {
  margin-bottom: 20px;
}

.faq-list {
  display: grid;
  gap: 10px;
}

details {
  border: 1px solid #dfcfaa;
  border-radius: 16px;
  background: rgba(255,255,255,0.38);
  padding: 14px 16px;
}

summary {
  cursor: pointer;
  font-weight: 700;
}

details p {
  margin: 10px 0 0;
  color: var(--muted);
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.related-card {
  display: block;
  min-height: 100%;
  padding: 16px;
  border: 1px solid #dfcfaa;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.38);
  text-decoration: none;
}

.related-card strong,
.related-card span {
  display: block;
}

.related-card span {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.94rem;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(14, 30, 20, 0.62);
  backdrop-filter: blur(3px);
}

.overlay[hidden] {
  display: none;
}

.overlay-panel {
  width: min(520px, 100%);
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: rgba(255, 249, 236, 0.97);
  box-shadow: var(--shadow);
  text-align: center;
}

@media (min-width: 960px) {
  .memory-board {
    grid-template-columns: repeat(4, minmax(112px, 1fr));
  }

  .memory-board[data-difficulty="easy"] {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
  }

  .memory-board[data-difficulty="hard"] {
    grid-template-columns: repeat(5, minmax(102px, 1fr));
  }

  .memory-card {
    min-height: 118px;
  }
}

@media (max-width: 780px) {
  .page-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 10px;
  }

  .hero,
  .panel,
  .faq-panel,
  .related-panel {
    border-radius: 20px;
    padding: 18px;
  }

  .content-grid,
  .related-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 420px) {
  .page-shell {
    width: min(100% - 14px, 1180px);
  }

  .game-shell {
    padding: 10px;
    border-radius: 20px;
  }

  .status-bar {
    gap: 8px;
  }

  .status-item {
    padding: 8px 9px;
  }

  .game-toolbar {
    display: block;
  }

  .difficulty-group {
    margin-bottom: 10px;
  }

  .difficulty-group label {
    flex: 1 1 calc(33.333% - 8px);
    justify-content: center;
    padding-inline: 8px;
  }

  .game-button {
    width: 100%;
  }

  .memory-board,
  .memory-board[data-difficulty="easy"],
  .memory-board[data-difficulty="hard"] {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px;
    padding: 10px;
    border-radius: 18px;
  }

  .memory-card {
    min-height: clamp(68px, 20vw, 82px);
    border-radius: 12px;
  }

  .card-face {
    border-radius: 12px;
  }

  .card-symbol {
    font-size: 1.55rem;
  }

  .card-label {
    bottom: 6px;
    font-size: 0.58rem;
  }
}
