/* Memory Garden styles. Colors come from the theme variables so the high-contrast theme
   only needs to change the variables. */
:root {
  --bg: #FBF7EE;
  --text: #1F3326;
  --muted: #3F5547;
  --panel: #FFFFFF;
  --panel-border: #C9D6CC;
  --accent: #005A5E;
  --accent-text: #FFFFFF;
  --focus: #B04E00;
  --card-back: #3F8F5A;
  --card-back-mark: rgba(255, 255, 255, 0.55);
  --card-face: #FFFFFF;
  --card-border: #2F5D3F;
  --match: #2E9E4F;
  --hint: #B04E00;
  --radius: 18px;
  --gap: 14px;
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="contrast"] {
  --bg: #000000;
  --text: #FFFFFF;
  --muted: #F0F0F0;
  --panel: #111111;
  --panel-border: #FFE600;
  --accent: #FFE600;
  --accent-text: #000000;
  --focus: #00E5FF;
  --card-back: #000000;
  --card-back-mark: #FFE600;
  --card-face: #000000;
  --card-border: #FFE600;
  --match: #00E676;
  --hint: #00E5FF;
  color-scheme: dark;
}

* { box-sizing: border-box; }

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

h1, h2 { line-height: 1.2; }

/* "Skip to the game" link: hidden until a keyboard user tabs to it */
.skip-link {
  position: absolute;
  left: 1rem;
  top: -100px;
  z-index: 30;
  padding: 0.75rem 1.25rem;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus {
  top: 0.75rem;
  outline: 5px solid var(--focus);
  outline-offset: 3px;
}

a:focus-visible {
  outline: 5px solid var(--focus);
  outline-offset: 3px;
}

/* The skip link moves focus to <main>; no need for a ring around the whole page area. */
main:focus {
  outline: none;
}

/* Card faces are hidden from view and from screen readers while the card is face down. */
.card:not(.is-up) .card-face {
  visibility: hidden;
  transition: visibility 0s linear 0.45s;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Buttons: large, high contrast, clear focus ring */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  padding: 0.5rem 1.25rem;
  border: 3px solid var(--accent);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  overflow: hidden;
}

.btn[hidden] {
  display: none;
}

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

.btn:focus-visible,
.card:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 5px solid var(--focus);
  outline-offset: 3px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

/* Hold-to-open: a bar fills along the bottom while the button is held */
.hold-btn {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.hold-btn::after {
  content: "";
  position: absolute;
  left: 0;
  bottom: 0;
  height: 6px;
  width: calc(var(--hold, 0) * 100%);
  background: var(--accent);
}

/* Top bar */
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 2px solid var(--panel-border);
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.25rem);
}

.topbar-actions {
  display: flex;
  gap: 0.75rem;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.5rem 1rem 1rem;
}

.status {
  margin: 0.25rem 0 0;
  min-height: 1.5em;
  font-size: clamp(1.25rem, 3vw, 1.6rem);
  font-weight: 700;
  text-align: center;
}

.progress {
  margin: 0 0 0.75rem;
  color: var(--muted);
  text-align: center;
}

/* Card grid: memory-garden.js sets --cols and --card to fit the screen */
.board {
  display: grid;
  grid-template-columns: repeat(var(--cols, 4), var(--card, 140px));
  gap: var(--gap);
  justify-content: center;
  width: 100%;
}

.card {
  width: var(--card, 140px);
  height: var(--card, 140px);
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: none;
  perspective: 900px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.card-inner {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.45s ease;
}

.card.is-up .card-inner {
  transform: rotateY(180deg);
}

.card-back,
.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 4px solid var(--card-border);
  border-radius: var(--radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}

.card-back {
  background: var(--card-back);
  color: var(--card-back-mark);
}

.card-back svg {
  width: 46%;
  height: auto;
}

.card-face {
  background: var(--card-face);
  transform: rotateY(180deg);
  overflow: hidden;
}

.card-face svg {
  width: 72%;
  height: auto;
}

.card-face.has-name svg {
  width: 60%;
}

.card-name {
  margin-top: 4%;
  font-size: clamp(0.8rem, calc(var(--card, 140px) * 0.11), 1.4rem);
  font-weight: 700;
  color: var(--text);
}

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

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

.card.is-matched .card-face {
  border-color: var(--match);
  box-shadow: inset 0 0 0 4px var(--match);
}

.card.is-matched .card-face::after {
  content: "\2713";
  position: absolute;
  top: 4%;
  right: 7%;
  font-size: calc(var(--card, 140px) * 0.16);
  font-weight: 800;
  line-height: 1;
  color: var(--match);
}

/* Gentle glow for "Show me a pair": slow, soft, no flashing */
.card.is-hint {
  outline: 6px solid var(--hint);
  outline-offset: 4px;
  animation: hint-glow 1.6s ease-in-out 2;
}

@keyframes hint-glow {
  50% { outline-offset: 9px; }
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.25rem;
}

.note {
  padding: 0.75rem 1rem 1rem;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
}

.note p {
  margin: 0.25rem auto;
  max-width: 48rem;
}

.note a {
  color: var(--accent);
  font-weight: 700;
}

/* Finish and break messages */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.55);
  z-index: 10;
}

.overlay[hidden] {
  display: none;
}

.overlay-card {
  max-width: 32rem;
  width: 100%;
  padding: 2rem 1.5rem;
  border: 3px solid var(--panel-border);
  border-radius: 22px;
  background: var(--panel);
  text-align: center;
}

.overlay-card h2 {
  margin: 0.5rem 0;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
}

.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.25rem;
}

.finish-flowers {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.finish-flowers svg {
  width: 72px;
  height: 72px;
  animation: bloom 1.2s ease-out both;
}

.finish-flowers svg:nth-child(2) { animation-delay: 0.2s; }
.finish-flowers svg:nth-child(3) { animation-delay: 0.4s; }

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

/* Caregiver settings */
.settings {
  width: min(36rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 1.5rem;
  border: 3px solid var(--panel-border);
  border-radius: 20px;
  background: var(--panel);
  color: var(--text);
}

.settings::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.settings h2 {
  margin: 0;
}

.settings fieldset {
  margin: 1rem 0;
  padding: 0.75rem 1rem 1rem;
  border: 2px solid var(--panel-border);
  border-radius: 14px;
}

.settings legend {
  padding: 0 0.4rem;
  font-weight: 700;
}

.settings label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.75rem 0;
}

.settings label.check {
  flex-direction: row;
  align-items: center;
  gap: 0.75rem;
}

.settings select {
  min-height: 48px;
  padding: 0.25rem 0.5rem;
  border: 2px solid var(--panel-border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  font: inherit;
}

.settings input[type="checkbox"],
.settings input[type="radio"] {
  width: 1.5rem;
  height: 1.5rem;
  accent-color: var(--accent);
}

.hint {
  margin: 0.25rem 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.file-btn input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.file-btn:focus-within {
  outline: 5px solid var(--focus);
  outline-offset: 3px;
}

.photo-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 0.5rem 0 0;
  padding: 0;
  list-style: none;
}

.photo-list li {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.photo-list img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  border: 2px solid var(--panel-border);
}

.photo-list .btn {
  min-height: 40px;
  padding: 0.2rem 0.6rem;
  font-size: 0.9rem;
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Reduce motion: turn cards and show messages instantly */
:root[data-reduce-motion] *,
:root[data-reduce-motion] *::before,
:root[data-reduce-motion] *::after {
  transition: none !important;
  animation: none !important;
}

@media (max-width: 560px) {
  .topbar { justify-content: center; }
  .topbar h1 { width: 100%; text-align: center; order: -1; }
  :root { --gap: 10px; --radius: 14px; }
}
