:root {
  --bg: #faf6f0;
  --card: #ffffff;
  --ink: #3b2f2a;
  --muted: #8a7a6e;
  --brown: #7c5a3c;
  --brown-dark: #5d4026;
  --accent: #a9744f;
  --green: #4e9b4e;
  --line: #e7ddd2;
  --radius: 14px;
}

/* Scale the whole rem-based layout with screen width:
   16px on mobile, ~20px on 1080p, ~22px on 1440p. */
html {
  font-size: clamp(16px, 12px + 0.42vw, 22px);
  min-height: 100%;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  /* decorative forest band: the svg's solid lower fill matches --bg, so the
     darker strip only shows through the transparent top with the silhouettes.
     Tiled horizontally at a fixed size, offset from the top; the area above
     and below the strip stays page-colored. */
  background-image: url("../assets/background.svg"), linear-gradient(var(--line), var(--line));
  background-repeat: repeat-x, no-repeat;
  background-position: center 9rem, 0 0rem;
  background-size: auto 40rem, 100% 20rem;
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-tap-highlight-color: transparent;
  display: flex;
  flex-direction: column;
}

header {
  border-bottom: 2px solid var(--line);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 32.5rem;
  margin: 0 auto;
  padding: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#btn-lang svg {
  display: block;
  width: 1.5rem;
  height: 0.95rem;
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.header-title {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 0;
}
.header-text { text-align: left; min-width: 0; }

#logo { height: 3rem; flex: none; }

h1 {
  margin: 0;
  font-size: 1.75rem;
  letter-spacing: 0.02em;
  color: var(--brown-dark);
  line-height: 1.1;
}

.subtitle {
  font-size: 0.64rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions { display: flex; gap: 4px; }

.icon-btn {
  border: none;
  background: none;
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 0.5rem;
  line-height: 1;
}
.icon-btn:hover { background: var(--line); }

main {
  max-width: 32.5rem;
  width: 100%;
  margin: 0 auto;
  padding: 0.75rem 0.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.site-credit {
  max-width: 32.5rem;
  width: 100%;
  margin: 0 auto;
  margin-top: auto;
  padding: 0 0.75rem 1rem;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
  text-align: center;
}

.site-credit a {
  color: var(--brown-dark);
  font-weight: 600;
  text-decoration: none;
}

.site-credit a:hover {
  text-decoration: underline;
}

#debug-bar { display: flex; gap: 8px; justify-content: center; }

#banner {
  background: #fff3cd;
  border: 1px solid #e8d99b;
  color: #6b5d1f;
  padding: 8px 12px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  text-align: center;
}

.poop-card {
  margin: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(60, 40, 20, 0.07);
}

#poop-frame {
  position: relative;
  overflow: hidden;
  height: clamp(13.75rem, 50vw, 21.25rem);
  cursor: zoom-in;
  user-select: none;
  background: #eee;
}
#poop-frame.zoomed { cursor: grab; }
#poop-frame.zoomed:active { cursor: grabbing; }
#poop-frame.loading { cursor: progress; }
#poop-frame.loading::after {
  content: "";
  position: absolute;
  z-index: 2;
  top: 50%;
  left: 50%;
  width: 2rem;
  height: 2rem;
  margin: -1rem 0 0 -1rem;
  border: 3px solid rgba(124, 90, 60, 0.18);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}
#poop-frame.loading #poop-img {
  opacity: 0;
}
#poop-frame.load-error #poop-img {
  opacity: 0;
}
#poop-frame.loading #zoom-hint,
#poop-frame.loading #zoom-reset {
  display: none !important;
}
#poop-frame.load-error::after {
  content: "!";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2rem;
  height: 2rem;
  margin: -1rem 0 0 -1rem;
  border-radius: 50%;
  background: rgba(124, 90, 60, 0.16);
  color: var(--brown-dark);
  font-weight: 800;
  line-height: 2rem;
  text-align: center;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#poop-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform-origin: 0 0;
  will-change: transform;
}
#poop-img.smooth { transition: transform 0.25s ease; }

#zoom-hint {
  position: absolute;
  bottom: 8px;
  right: 8px;
  font-size: 0.62rem;
  background: rgba(20, 12, 5, 0.5);
  color: #fff;
  padding: 3px 9px;
  border-radius: 999px;
  pointer-events: none;
}
#poop-frame.zoomed #zoom-hint { display: none; }

#zoom-reset {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: rgba(20, 12, 5, 0.55);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
  align-items: center;
}

#photo-credit {
  font-size: 0.7rem;
  color: var(--muted);
  padding: 6px 10px;
}
#photo-credit a { color: var(--accent); }

#grid { display: flex; flex-direction: column; gap: 5px; }

.grid-row {
  display: grid;
  grid-template-columns: 1.35fr repeat(5, 1fr);
  gap: 4px;
}

.grid-head .hcell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
  color: var(--muted);
  padding-bottom: 2px;
}
.hcell-name {
  justify-content: flex-end;
  align-items: flex-start;
  padding-left: 4px;
}
.hicon { width: 1.5rem; height: 1.5rem; }
.hicon svg { width: 100%; height: 100%; fill: currentColor; }
.hlabel, .hcell-name {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  border-radius: 7px;
  padding: 0.4rem 0.2rem;
  min-height: 3rem;
  font-size: 0.62rem;
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
.cell-name {
  background: var(--card);
  border: 1px solid var(--line);
  font-size: 0.74rem;
  font-weight: 700;
}
.cell.v-same { background: var(--green); color: #fff; }
.cell.v-partial { background: #dfae33; color: #45350a; }
.cell.v-diff { background: #c4564b; color: #fff; }
.cell-name.v-same { border: none; animation: pop 0.4s ease 1.3s backwards; }

/* left-to-right flip for the freshly guessed row */
.grid-row.reveal .cell {
  animation: flipin 0.42s ease both;
  animation-delay: calc(var(--d) * 0.18s);
}
.grid-row.reveal .cell-name.v-same {
  animation: flipin 0.42s ease both, pop 0.4s ease 1.3s;
}
@keyframes flipin {
  from { transform: rotateX(92deg); }
  to { transform: rotateX(0); }
}
@keyframes pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.07); }
  100% { transform: scale(1); }
}

.guesses-left {
  text-align: center;
  font-size: 0.8rem;
  color: var(--muted);
}

#guess-form { display: flex; gap: 8px; }

.input-wrap { position: relative; flex: 1; }

#guess-input {
  width: 100%;
  padding: 0.75rem 0.9rem;
  font-size: 1rem;
  border: 2px solid var(--brown);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  outline: none;
}
#guess-input:focus { border-color: var(--brown-dark); }

#suggestions {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 -4px 16px rgba(60, 40, 20, 0.12);
  max-height: 16rem;
  overflow-y: auto;
  z-index: 20;
}
#suggestions li {
  padding: 0.55rem 0.75rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.95rem;
}
#suggestions li:hover, #suggestions li.active { background: var(--line); }

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1.1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn.primary { background: var(--brown); color: #fff; border-color: var(--brown); }
.btn.primary:hover { background: var(--brown-dark); }
.btn.subtle { font-size: 0.82rem; padding: 8px 12px; color: var(--muted); }
.btn:hover { filter: brightness(0.97); }

#after-game {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.after-buttons { display: flex; gap: 8px; }
.answer-line { font-size: 1.05rem; }

/* ------- modal ------- */

#modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(40, 25, 12, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

#modal {
  background: var(--card);
  border-radius: var(--radius);
  max-width: 27.5rem;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 1.25rem;
  position: relative;
  box-shadow: 0 12px 40px rgba(40, 25, 12, 0.3);
}
#modal h2 { margin: 0 36px 12px 0; color: var(--brown-dark); }
#modal-close { position: absolute; top: 12px; right: 12px; }

.help p { margin: 0 0 10px; font-size: 0.92rem; line-height: 1.45; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(4.7rem, 1fr));
  gap: 8px;
  margin: 12px 0;
}
.stat { text-align: center; }
.stat-num { font-size: 1.6rem; font-weight: 800; color: var(--brown-dark); }
.stat-label { font-size: 0.68rem; color: var(--muted); }

.dist { display: flex; flex-direction: column; gap: 4px; }
.dist-row { display: flex; align-items: center; gap: 8px; }
.dist-n { width: 20px; text-align: right; font-size: 0.85rem; }
.dist-bar {
  background: var(--brown);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: 4px;
  padding: 3px 7px;
  text-align: right;
  min-width: 24px;
}
.dist-bar.lose { background: var(--muted); }

.gameover { text-align: center; }
.gameover .btn { margin: 8px 0; }
.answer-reveal { font-size: 1.05rem; }
.share-preview {
  margin: 4px 0 12px;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.45;
  text-align: left;
  white-space: pre-wrap;
  word-break: break-word;
}

.archive { display: flex; flex-direction: column; gap: 6px; }
.archive-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--ink);
}
.archive-row:hover { background: var(--line); }
.archive-row.played { background: var(--card); }
.archive-day { font-weight: 700; color: var(--brown); width: 2.6rem; text-align: left; }
.archive-date { flex: 1; text-align: left; }
.archive-status { font-weight: 600; }

#toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 0.6rem 1.1rem;
  border-radius: 10px;
  font-size: 0.9rem;
  z-index: 100;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

@media (max-width: 460px) {
  h1 { font-size: 1.3rem; }
  #logo { height: 2.4rem; }
}

@media (max-width: 380px) {
  h1 { font-size: 1.2rem; }
  .cell { font-size: 0.56rem; }
  .cell-name { font-size: 0.68rem; }
}

/* AdSense side rails: desktop only, kept clear of the centered game column. */
.ad-rail {
  display: none;
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 160px;
  min-height: 600px;
  z-index: 5;
}

#ad-rail-left { left: max(12px, calc(50% - 16.25rem - 184px)); }
#ad-rail-right { right: max(12px, calc(50% - 16.25rem - 184px)); }

@media (min-width: 1100px) {
  .ad-rail { display: block; }
}
