/* MemoryMatch Stories — senior-friendly, offline-first, warm nostalgia */

:root {
  --accent: #9A3412;
  --accent-hover: #7C2D12;
  --accent-soft: #FEF3C7;
  --accent-ink: #7C2D12;
  --bg: #FBF7F0;
  --surface: #FFFEFB;
  --surface-2: #F3EDE3;
  --text: #1C1917;
  --text-muted: #57534E;
  --border: #D6D0C6;
  --danger: #B91C1C;
  --danger-soft: #FEE2E2;
  --success: #166534;
  --success-soft: #DCFCE7;
  --warn: #92400E;
  --warn-soft: #FEF3C7;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(28, 25, 23, 0.08), 0 4px 16px rgba(28, 25, 23, 0.06);
  --shadow-lg: 0 8px 30px rgba(28, 25, 23, 0.12);
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --space: 1rem;
  --touch: 48px;
  --max: 920px;
  --card-back: #9A3412;
  --card-face: #FFFEFB;
}

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

html {
  font-size: 18px;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -100px;
  z-index: 1000;
  background: var(--accent);
  color: #fff;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 0.75rem;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 0 rgba(28, 25, 23, 0.04);
}

.header-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1rem 1.25rem 0.75rem;
}

.brand {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.45rem;
  font-weight: 700;
  flex-shrink: 0;
  border: 2px solid var(--accent);
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  line-height: 1.2;
  color: var(--accent-ink);
  letter-spacing: -0.02em;
}

.tagline {
  margin: 0.2rem 0 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.main-nav {
  display: flex;
  gap: 0.4rem;
  overflow-x: auto;
  padding-bottom: 0.65rem;
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.nav-btn {
  flex: 0 0 auto;
  min-height: var(--touch);
  padding: 0.55rem 1rem;
  border: 2px solid transparent;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  white-space: nowrap;
}

.nav-btn:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.nav-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.nav-btn.is-active:hover {
  background: var(--accent-hover);
  color: #fff;
}

/* Main */
.main {
  max-width: var(--max);
  margin: 0 auto;
  padding: 1.25rem 1.25rem 2rem;
  width: 100%;
  flex: 1;
}

.view[hidden] {
  display: none !important;
}

.view-header {
  margin-bottom: 1.25rem;
}

.view-header h2 {
  margin: 0 0 0.35rem;
  font-size: 1.45rem;
  color: var(--accent-ink);
}

.view-lead {
  margin: 0;
  color: var(--text-muted);
  max-width: 40rem;
}

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1.15rem;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}

.panel-header h3 {
  margin: 0;
  font-size: 1.1rem;
  color: var(--accent-ink);
}

.panel-note {
  margin: 0 0 0.85rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.danger-panel {
  border-color: #FECACA;
  background: #FFFAFA;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: var(--touch);
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

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

.btn-secondary {
  background: var(--surface);
  color: var(--accent-ink);
  border-color: var(--border);
}

.btn-secondary:hover {
  background: var(--accent-soft);
  border-color: var(--accent);
}

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

.btn-ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover {
  background: #991B1B;
}

.btn-sm {
  min-height: 44px;
  padding: 0.4rem 0.85rem;
  font-size: 0.95rem;
}

.btn-icon {
  min-width: var(--touch);
  min-height: var(--touch);
  padding: 0;
  font-size: 1.5rem;
  line-height: 1;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
}

/* Fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  font-weight: 600;
  color: var(--text);
}

.field input,
.field select,
.field textarea {
  min-height: var(--touch);
  padding: 0.6rem 0.85rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  width: 100%;
}

.field textarea {
  min-height: 6rem;
  resize: vertical;
  line-height: 1.45;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.options-grid,
.filter-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}

@media (min-width: 560px) {
  .options-grid,
  .filter-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.filter-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.filter-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 0.9rem;
}

.result-summary {
  margin: 0 0 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Stats */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.15rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.95rem 1rem;
  box-shadow: var(--shadow);
}

.stat-card .stat-value {
  display: block;
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--accent-ink);
  line-height: 1.15;
}

.stat-card .stat-label {
  display: block;
  margin-top: 0.2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 600;
}

/* Decade picker */
.decade-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 520px) {
  .decade-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 780px) {
  .decade-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

.decade-card {
  text-align: left;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.05rem;
  min-height: var(--touch);
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.decade-card:hover {
  border-color: var(--accent);
  background: #FFFBF5;
}

.decade-card.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px var(--accent);
}

.decade-card .decade-era {
  display: block;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--accent-ink);
}

.decade-card .decade-blurb {
  display: block;
  margin-top: 0.25rem;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.4;
}

.decade-card .decade-meta {
  display: block;
  margin-top: 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

/* Item cards */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.item-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}

.item-card-header {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: flex-start;
  flex-wrap: wrap;
}

.item-card h3,
.item-card h4 {
  margin: 0;
  font-size: 1.08rem;
  color: var(--text);
}

.item-meta {
  margin: 0.35rem 0 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.item-body {
  margin: 0.55rem 0 0;
  color: var(--text);
  white-space: pre-wrap;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.85rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent-ink);
  border: 1px solid #F59E0B;
}

.badge-sample {
  background: #E0E7FF;
  color: #3730A3;
  border-color: #A5B4FC;
}

.badge-success {
  background: var(--success-soft);
  color: var(--success);
  border-color: #86EFAC;
}

.badge-muted {
  background: var(--surface-2);
  color: var(--text-muted);
  border-color: var(--border);
}

.empty-state {
  text-align: center;
  padding: 2rem 1.25rem;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

.empty-title {
  margin: 0 0 0.35rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
}

/* Memory board */
.play-board-wrap {
  margin-top: 0.25rem;
}

.board-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
  align-items: flex-start;
}

.board-meta h3 {
  margin: 0.15rem 0;
  font-size: 1.25rem;
  color: var(--accent-ink);
}

.board-decade {
  margin: 0;
  font-weight: 700;
  color: var(--accent);
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.board-stats {
  margin: 0.25rem 0 0;
  color: var(--text-muted);
  font-weight: 600;
}

.board-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.match-announce {
  min-height: 1.5rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
  color: var(--success);
}

.card-grid {
  display: grid;
  gap: 0.65rem;
  margin-bottom: 1rem;
}

.card-grid.cols-4 {
  grid-template-columns: repeat(2, 1fr);
}

.card-grid.cols-6 {
  grid-template-columns: repeat(3, 1fr);
}

.card-grid.cols-8 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 520px) {
  .card-grid.cols-6,
  .card-grid.cols-8 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 700px) {
  .card-grid.cols-4 {
    grid-template-columns: repeat(4, 1fr);
  }
  .card-grid.cols-6 {
    grid-template-columns: repeat(4, 1fr);
  }
  .card-grid.cols-8 {
    grid-template-columns: repeat(4, 1fr);
  }
}

.mem-card {
  position: relative;
  min-height: 100px;
  border: none;
  padding: 0;
  border-radius: 12px;
  background: transparent;
  perspective: 800px;
}

.mem-card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100px;
  transform-style: preserve-3d;
  transition: transform 0.35s ease;
  border-radius: 12px;
}

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

.mem-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: 12px;
  border: 2px solid var(--border);
  padding: 0.5rem;
  text-align: center;
}

.mem-back {
  background: linear-gradient(145deg, #B45309 0%, #9A3412 55%, #7C2D12 100%);
  color: #FFFBEB;
  border-color: #7C2D12;
  font-weight: 700;
  font-size: 1.4rem;
  letter-spacing: 0.06em;
}

.mem-front {
  background: var(--card-face);
  color: var(--text);
  transform: rotateY(180deg);
  border-color: var(--accent);
}

.mem-card.is-matched .mem-front {
  background: var(--success-soft);
  border-color: #86EFAC;
}

.mem-card.is-hint .mem-back {
  box-shadow: 0 0 0 3px #FBBF24, 0 0 12px rgba(251, 191, 36, 0.5);
}

.mem-emoji {
  font-size: 1.65rem;
  line-height: 1;
}

.mem-label {
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.2;
  max-width: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.mem-card:disabled {
  cursor: default;
}

.board-help {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.92rem;
}

/* Complete */
.play-complete {
  margin-top: 0.5rem;
}

.complete-card {
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.5rem 1.35rem;
  box-shadow: var(--shadow-lg);
}

.complete-kicker {
  margin: 0;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.85rem;
}

.complete-card h3 {
  margin: 0.35rem 0;
  font-size: 1.45rem;
  color: var(--accent-ink);
}

.complete-summary {
  margin: 0 0 1rem;
  color: var(--text-muted);
}

.unlock-list {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin-bottom: 1.15rem;
}

.unlock-chip {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.75rem 0.85rem;
  background: var(--accent-soft);
  border-radius: var(--radius-sm);
  border: 1px solid #F59E0B;
}

.unlock-chip .chip-emoji {
  font-size: 1.4rem;
  line-height: 1;
}

.unlock-chip .chip-title {
  font-weight: 700;
  color: var(--text);
}

.unlock-chip .chip-sub {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Bars */
.bar-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.bar-row {
  display: grid;
  grid-template-columns: 5.5rem 1fr 2.5rem;
  gap: 0.65rem;
  align-items: center;
}

.bar-label {
  font-weight: 700;
  color: var(--text);
  font-size: 0.95rem;
}

.bar-track {
  height: 14px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #D97706, #9A3412);
  border-radius: 999px;
  min-width: 0;
}

.bar-value {
  font-weight: 700;
  color: var(--text-muted);
  text-align: right;
  font-size: 0.95rem;
}

.suggestion-list {
  margin: 0;
  padding-left: 1.25rem;
  color: var(--text);
}

.suggestion-list li {
  margin-bottom: 0.45rem;
}

/* Modal */
.modal {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  max-width: min(520px, calc(100vw - 2rem));
  width: 100%;
  box-shadow: var(--shadow-lg);
  background: var(--surface);
  color: var(--text);
}

.modal::backdrop {
  background: rgba(28, 25, 23, 0.45);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem 1.15rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 1.2rem;
  color: var(--accent-ink);
}

.modal-body {
  padding: 1rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.55rem;
  padding: 0.75rem 1.15rem 1.15rem;
  border-top: 1px solid var(--border);
}

.moment-hero {
  display: flex;
  gap: 0.85rem;
  align-items: flex-start;
}

.moment-hero .moment-emoji {
  font-size: 2.5rem;
  line-height: 1;
}

.moment-section {
  margin: 0;
}

.moment-section strong {
  display: block;
  color: var(--accent-ink);
  margin-bottom: 0.2rem;
  font-size: 0.95rem;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 1.5rem;
  transform: translateX(-50%);
  z-index: 200;
  max-width: min(480px, calc(100vw - 2rem));
  background: var(--accent-ink);
  color: #fff;
  padding: 0.85rem 1.15rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-weight: 600;
  text-align: center;
}

.toast[hidden] {
  display: none !important;
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: 1.25rem 1.25rem 1.75rem;
  text-align: center;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.app-footer p {
  margin: 0;
  font-size: 0.95rem;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .mem-card-inner {
    transition: none;
  }
  * {
    scroll-behavior: auto !important;
  }
}
