/* Animal Explorers — soft watercolour-paper look, large touch targets, no external assets. */
:root {
  --paper: #f7f0e1;
  --paper-2: #fdf9f0;
  --ink: #3d3a35;
  --ink-soft: #6f685d;
  --line: #e4d8c1;
  --heart: #d9576a;
  --dino: #8fb48a;
  --land: #e0b36f;
  --ocean: #7fb2cf;
  --btn: #fffaf1;
  --shadow: 0 2px 0 rgba(120, 100, 70, .12), 0 6px 18px rgba(120, 100, 70, .12);
  --radius: 22px;
  --tap: 60px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --vh: 100vh;
  --zh: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
}
@supports (height: 100dvh) { :root { --vh: 100dvh; } }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at 20% 0%, #fffaf0 0%, var(--paper) 55%, #f1e6d0 100%) fixed;
  color: var(--ink);
  font: 18px/1.3 ui-rounded, "SF Pro Rounded", "Avenir Next", "Nunito", system-ui, -apple-system, var(--zh);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
img { -webkit-user-drag: none; }
.zh { font-family: var(--zh); }
.py { color: var(--ink-soft); font-style: italic; }
.noscript { padding: 2rem; text-align: center; }

.view {
  min-height: var(--vh);
  padding: calc(16px + var(--safe-t)) calc(20px + var(--safe-r)) calc(24px + var(--safe-b)) calc(20px + var(--safe-l));
}

/* ---------- buttons ---------- */
.btn {
  min-height: var(--tap); min-width: var(--tap);
  padding: 8px 20px;
  border: 2px solid var(--line); border-radius: 999px;
  background: var(--btn); box-shadow: var(--shadow);
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  cursor: pointer; touch-action: manipulation;
  font-size: 20px; line-height: 1.1; white-space: nowrap;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(120,100,70,.15); }
.btn:disabled { opacity: .35; cursor: default; box-shadow: none; }
.btn:disabled:active { transform: none; }
.btn .zh { font-size: 18px; }
.btn .ico { font-size: 26px; line-height: 1; }
.btn:focus-visible, .tile-open:focus-visible, .heart:focus-visible, .section-btn:focus-visible { outline: 4px solid #6a9bc3; outline-offset: 3px; }

.heart {
  width: var(--tap); height: var(--tap); flex: 0 0 auto;
  border-radius: 50%; border: 2px solid var(--line);
  background: var(--btn); box-shadow: var(--shadow);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; touch-action: manipulation; padding: 0;
}
.heart svg { width: 32px; height: 32px; fill: none; stroke: var(--heart); stroke-width: 2.2; }
.heart[aria-pressed="true"] svg { fill: var(--heart); }
.heart[aria-pressed="true"] { background: #fde9ec; border-color: #f0b9c2; }

/* ---------- top bar ---------- */
.bar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.bar .title { flex: 1 1 auto; min-width: 0; text-align: center; margin: 0; }
.bar .title .en { font-size: 30px; font-weight: 700; }
.bar .title .zh { font-size: 26px; margin-left: 10px; }
.bar .spacer { flex: 0 0 var(--tap); }
.grid-view .bar { flex-wrap: nowrap; }
.grid-view .bar > .btn { flex: 0 0 auto; }
.grid-view .bar .title { line-height: 1.15; }

.save-notice {
  margin: 0 auto 14px; max-width: 900px; padding: 10px 16px; border-radius: 16px;
  background: #fff3d6; border: 2px solid #ecc97a; font-size: 17px; text-align: center;
}
.save-notice .zh { display: block; margin-top: 2px; }

/* ---------- home: three big section tiles fill the screen, actions below ---------- */
.home {
  --home-gap: 18px;
  height: var(--vh); min-height: 0; display: flex; flex-direction: column;
  padding-top: calc(12px + var(--safe-t)); padding-bottom: calc(16px + var(--safe-b));
}
.home-head { text-align: center; margin: 0 0 12px; flex: 0 0 auto; }
.home-head h1 { margin: 0; font-size: 36px; letter-spacing: .5px; }
.home-head .zh { font-size: 32px; margin-left: 8px; font-weight: 600; }
.home .save-notice { flex: 0 0 auto; font-size: 15px; padding: 6px 12px; margin-bottom: 10px; }
.sections {
  flex: 1 1 auto; min-height: 0; display: grid; gap: var(--home-gap);
  grid-template-columns: 1fr; grid-template-rows: repeat(3, minmax(0, 1fr));
  width: 100%; max-width: 1200px; margin: 0 auto;
}
.section-card { position: relative; min-height: 0; min-width: 0; display: flex; }
.section-btn {
  flex: 1 1 auto; min-width: 0; min-height: 0;
  border: 3px solid var(--line); border-radius: 30px; background: var(--paper-2);
  box-shadow: var(--shadow); padding: 14px; cursor: pointer; touch-action: manipulation;
  display: flex; align-items: stretch; gap: 22px; text-align: left;
}
.section-btn:active { transform: translateY(2px); }
.section-btn .pic { position: relative; flex: 0 0 auto; aspect-ratio: 1 / 1; height: 100%; max-width: 55%; border-radius: 22px; overflow: hidden; }
.section-btn .pic img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; }
.section-btn .label { align-self: center; min-width: 0; }
.section-btn .label .en { display: block; font-size: 40px; font-weight: 700; line-height: 1.1; }
.section-btn .label .zh { display: block; font-size: 38px; margin-top: 6px; }
.section-btn .label .py { display: block; font-size: 22px; margin-top: 4px; }
.section-btn[data-s="dinosaurs"] { border-color: var(--dino); } .section-btn[data-s="dinosaurs"] .pic { background: #e6f0e1; }
.section-btn[data-s="land-animals"] { border-color: var(--land); } .section-btn[data-s="land-animals"] .pic { background: #f8ecd5; }
.section-btn[data-s="ocean-animals"] { border-color: var(--ocean); } .section-btn[data-s="ocean-animals"] .pic { background: #e1eef6; }
.pic-fallback { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 6px; text-align: center; padding: 8px; }
.pic-fallback .fb-ico { font-size: 64px; line-height: 1; }
.pic-fallback .fb-msg { font-size: 15px; color: var(--ink-soft); }
.section-card.failed .pic img { display: none; }
.section-card.failed .pic-fallback { display: flex; }
.home-retry { display: none; position: absolute; top: 12px; right: 12px; min-height: 52px; padding: 6px 14px; font-size: 17px; }
.home-retry .zh { font-size: 16px; }
.section-card.failed .home-retry { display: inline-flex; }
@media (orientation: landscape) {
  .sections { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-template-rows: minmax(0, 1fr); }
  .section-btn { flex-direction: column; text-align: center; gap: 10px; }
  .section-btn .pic { flex: 1 1 auto; min-height: 0; height: auto; width: 100%; max-width: none; aspect-ratio: auto; }
  .section-btn .label { align-self: stretch; }
  .section-btn .label .en { font-size: 32px; }
  .section-btn .label .zh { font-size: 30px; margin-top: 2px; }
  .section-btn .label .py { font-size: 19px; }
  .home-retry { top: 10px; right: 10px; }
}
.home-actions { flex: 0 0 auto; display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; margin: 16px 0 0; }
.btn-big { min-height: 76px; padding: 10px 34px; font-size: 26px; min-width: 260px; }
.btn-big .zh { font-size: 24px; }
.btn-big .ico { font-size: 30px; }

/* ---------- grids: portrait 3, landscape 4 (5 on wider screens) ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (orientation: landscape) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (orientation: landscape) and (min-width: 1150px) { .grid { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.tile { position: relative; min-width: 0; background: var(--paper-2); border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.tile-open {
  display: flex; flex-direction: column; align-items: stretch; width: 100%; height: 100%;
  border: 0; background: none; padding: 10px 10px 12px; cursor: pointer; touch-action: manipulation; text-align: center;
  border-radius: var(--radius);
}
.tile-open .pic { aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center; border-radius: 16px; background: #fbf4e6; overflow: hidden; }
.tile-open .pic img { width: auto; height: auto; max-width: 100%; max-height: 100%; object-fit: contain; display: block; }
.tile-open .en, .tile-open .zh, .tile-open .py { display: block; min-width: 0; overflow-wrap: anywhere; -webkit-hyphens: manual; hyphens: manual; }
.tile-open .en { font-size: 21px; font-weight: 700; margin-top: 8px; line-height: 1.15; }
.tile-open .zh { font-size: 23px; margin-top: 3px; }
.tile-open .py { font-size: 16px; margin-top: 1px; }
.tile .heart { position: absolute; top: 4px; right: 4px; width: 54px; height: 54px; }
.tile .heart svg { width: 28px; height: 28px; }
.empty { text-align: center; font-size: 24px; margin: 60px auto; max-width: 600px; }
.empty .zh { display: block; margin-top: 8px; }

/* ---------- image error ---------- */
.img-error { display: none; flex-direction: column; align-items: center; justify-content: center; gap: 10px; text-align: center; padding: 10px; }
.failed > img { display: none !important; }
.failed > .img-error { display: flex; }
.img-error .msg { font-size: 17px; }
.img-error .btn { min-height: 52px; font-size: 18px; }

/* ---------- card viewer: one compact bar, card gets the rest ---------- */
.viewer {
  height: var(--vh); min-height: 0; display: flex; flex-direction: column;
  padding: calc(8px + var(--safe-t)) calc(10px + var(--safe-r)) calc(8px + var(--safe-b)) calc(10px + var(--safe-l));
  touch-action: manipulation;   /* no double-tap zoom delay; swipes are read from touch events */
  overflow: hidden;
}
.viewer .bar { margin: 0 0 6px; flex-wrap: nowrap; gap: 8px; flex: 0 0 auto; }
.viewer .btn-nav { min-height: 52px; min-width: 52px; padding: 4px 12px; gap: 6px; }
.viewer .btn-nav .lbl { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.05; }
.viewer .btn-nav .en { font-size: 15px; }
.viewer .btn-nav .zh { font-size: 14px; }
.viewer .btn-nav .ico { font-size: 20px; }
.viewer .heart { width: 52px; height: 52px; }
.viewer .heart svg { width: 28px; height: 28px; }
/* the card PNG already shows the name large, so the bar repeats it small, one line */
.viewer .bar .title { font-size: 17px; font-weight: 400; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: left; padding-left: 4px; }
.viewer .bar .title .en { font-size: 18px; font-weight: 700; }
.viewer .bar .title .zh { font-size: 17px; margin-left: 4px; }
.viewer .bar .title .py { font-size: 14px; margin-left: 4px; }
.viewer .pos { flex: 0 0 auto; min-width: 64px; font-size: 16px; color: var(--ink-soft); text-align: center; font-variant-numeric: tabular-nums; }
.viewer .save-notice { flex: 0 0 auto; font-size: 14px; padding: 4px 10px; margin-bottom: 6px; }
.viewer .save-notice .zh { display: inline; margin: 0 0 0 6px; }
.stage { flex: 1 1 auto; min-height: 0; position: relative; }
/* The card always fits inside the stage: absolute box + object-fit: contain keeps the PNG's own
   proportions (never cropped or stretched); nothing overlaps it. */
.stage img {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; object-position: center;
  filter: drop-shadow(0 3px 8px rgba(120, 100, 70, .22));
}
.stage.failed .loading { display: none; }
.stage .img-error { position: absolute; inset: 0; }
.stage .loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 6px; color: var(--ink-soft); font-size: 18px; }
.stage:not(.is-loading) .loading { display: none; }
@media (max-width: 860px) and (orientation: portrait) { .viewer .bar .title .py { display: none; } }
/* boundary feedback when swiping past the first/last card */
@keyframes bump-l { 0%,100% { transform: none; } 40% { transform: translateX(-14px); } }
@keyframes bump-r { 0%,100% { transform: none; } 40% { transform: translateX(14px); } }
.viewer.bump-l .stage img { animation: bump-l .25s ease; }
.viewer.bump-r .stage img { animation: bump-r .25s ease; }
@media (prefers-reduced-motion: reduce) { .viewer.bump-l .stage img, .viewer.bump-r .stage img { animation: none; } }

/* tile picture error: overlay sits outside the open button so Retry is its own tap target */
.tile .tile-error { position: absolute; left: 10px; right: 10px; top: 10px; aspect-ratio: 1 / 1; border-radius: 16px; background: #fbf4e6; }
.tile.failed .tile-error { display: flex; }
.tile.failed .tile-open .pic img { visibility: hidden; }
.tile .tile-error .msg { font-size: 15px; }
