:root {
  --bg: #f3f1e8;
  --paper: #ffffff;
  --ink: #2a2a28;
  --muted: #6b6b65;
  --line: #d8d4c4;
  --leaf: #b9d99c;       /* clover leaf green */
  --leaf-dark: #7eb05a;
  --green: #2e7d4f;
  --green-soft: #c5e6cf;
  --green-dark: #1f5c3a;
  --gold: #d6a648;
  --bad: #b9434f;
  --bad-soft: #fdd5d8;
  --shadow: 0 1px 2px rgba(0,0,0,0.05), 0 4px 12px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}
main { max-width: 980px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }
a { color: var(--green-dark); }
a:hover { color: var(--green); }
h1, h2 { margin-top: 0; }
.muted { color: var(--muted); }
.lede { color: var(--muted); }
.small { font-size: 0.85rem; }
small { color: var(--muted); }

/* topbar */
.topbar {
  background: var(--green-dark);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.2rem;
  gap: 1rem;
}
.topbar a { color: white; text-decoration: none; }
.topbar .brand { font-weight: 700; font-size: 1.05rem; }
.topbar nav { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.topbar nav a { opacity: 0.9; }
.topbar nav a:hover { opacity: 1; text-decoration: underline; }
.topbar .who { opacity: 0.85; font-size: 0.9rem; }
.inline { display: inline; }
.link-btn {
  background: none; border: none; color: white; cursor: pointer;
  text-decoration: underline; padding: 0; font-size: 0.9rem; opacity: 0.8;
}
.link-btn:hover { opacity: 1; }

/* login */
.login-card {
  max-width: 420px; margin: 3rem auto; background: var(--paper);
  padding: 2rem; border-radius: 8px; box-shadow: var(--shadow);
}
.login-card h1 { margin-top: 0; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
label > span { display: block; font-weight: 600; margin-bottom: 0.25rem; }
input[type=text], input[type=password], textarea {
  width: 100%; padding: 0.55rem 0.7rem; border: 1px solid var(--line);
  border-radius: 6px; background: white; font: inherit;
  /* Give breathing room above/below when scrolled into view by the focus handler. */
  scroll-margin-top: 80px;
  scroll-margin-bottom: 80px;
}
input:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: 1px; }
.alert {
  background: var(--bad-soft); border: 1px solid var(--bad); color: var(--bad);
  padding: 0.5rem 0.75rem; border-radius: 6px; margin-bottom: 1rem;
}

/* buttons */
button, .btn {
  font: inherit; padding: 0.55rem 1rem; border-radius: 6px;
  border: 1px solid var(--line); background: white; cursor: pointer;
}
button.primary, .btn.primary {
  background: var(--green-dark); color: white; border-color: var(--green-dark);
}
button.primary:hover, .btn.primary:hover { background: var(--green); border-color: var(--green); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-link { color: var(--muted); text-decoration: underline; font-size: 0.9rem; }

/* feed */
.feed { display: flex; flex-direction: column; gap: 1rem; }
.feed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
}
.hero {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  background: linear-gradient(120deg, var(--leaf) 0%, var(--green-soft) 100%);
  border: 1px solid var(--leaf-dark);
}
.hero h2 { margin: 0 0 0.2rem; color: var(--green-dark); }
.hero-text { flex: 1 1 280px; }
.btn.big { padding: 0.8rem 1.4rem; font-size: 1.05rem; }

/* leaderboard tables */
.lb { width: 100%; border-collapse: collapse; font-size: 0.92rem; margin-top: 0.5rem; }
.lb th, .lb td { padding: 0.45rem 0.6rem; text-align: left; border-bottom: 1px solid var(--line); }
.lb th { background: var(--bg); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
.lb tr.me td { background: rgba(46,125,79,0.08); }
.lb tr:hover td { background: rgba(46,125,79,0.05); }
.pill.you { background: var(--green); color: white; }
.card {
  background: var(--paper); border-radius: 8px; padding: 1.2rem 1.4rem;
  box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.puzzle-list, .activity {
  list-style: none; padding: 0; margin: 0.5rem 0 0;
  display: flex; flex-direction: column; gap: 0.5rem;
}
.puzzle-list li, .activity li {
  padding: 0.5rem 0.75rem; border: 1px solid var(--line);
  border-radius: 6px; display: flex; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap;
}
.meta { color: var(--muted); font-size: 0.85rem; }

.pill {
  display: inline-block; padding: 0.1rem 0.5rem; border-radius: 999px;
  font-size: 0.78rem; background: var(--line); color: var(--ink);
}
.pill.perfect { background: var(--gold); color: white; }
.pill.in-progress { background: var(--bad-soft); color: var(--bad); }

/* ---- clover board ---- */
/* 4 leaves at N/E/S/W (clue zones) wrap the 2x2 of card slots in the center.
   Grid is 4 columns × 4 rows; outer ring is leaves, inner 2x2 is slots. */
.clover-board {
  position: relative;
  width: min(100%, 600px);
  margin: 1.25rem auto;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: 0.65fr 1fr 1fr 0.65fr;
  grid-template-rows: 0.65fr 1fr 1fr 0.65fr;
  gap: 0.4rem;
}

/* Slots: NW NE SE SW in the inner 2x2 */
.slot {
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  padding: 0.3rem;
  min-height: 0; min-width: 0;
  position: relative;
  transition: background 0.12s, border-color 0.12s;
}
.slot-0 { grid-column: 2; grid-row: 2; }  /* NW */
.slot-1 { grid-column: 3; grid-row: 2; }  /* NE */
.slot-2 { grid-column: 3; grid-row: 3; }  /* SE */
.slot-3 { grid-column: 2; grid-row: 3; }  /* SW */
.slot.droppable { background: #faf6e8; border-style: dashed; cursor: pointer; }
.slot.droppable.selected-target { border-color: var(--green); background: var(--green-soft); }
.slot.locked { background: #eef7ee; border-color: var(--green); border-style: solid; }

/* Leaves: outer ring of clue zones */
.leaf {
  background: var(--leaf);
  border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0.4rem;
  text-align: center;
  color: var(--green-dark);
  font-weight: 600;
  border: 2px solid var(--leaf-dark);
}
.leaf-0 { grid-column: 2 / span 2; grid-row: 1; border-radius: 50% 50% 35% 35%; }
.leaf-1 { grid-column: 4;          grid-row: 2 / span 2; border-radius: 35% 50% 50% 35%; }
.leaf-2 { grid-column: 2 / span 2; grid-row: 4; border-radius: 35% 35% 50% 50%; }
.leaf-3 { grid-column: 1;          grid-row: 2 / span 2; border-radius: 50% 35% 35% 50%; }
.leaf .leaf-name { font-size: 0.7rem; color: var(--green-dark); opacity: 0.7; text-transform: uppercase; letter-spacing: 0.05em; }
.leaf .clue-text { font-size: clamp(0.8rem, 2vw, 1rem); font-weight: 800; }
.leaf input[type=text] {
  width: 90%;
  text-align: center; font-weight: 700; padding: 0.3rem;
  background: rgba(255,255,255,0.85);
}
.leaf .leaf-reason {
  width: 92%;
  margin-top: 0.3rem;
  padding: 0.25rem 0.4rem;
  font-size: 0.7rem;
  font-weight: 400;
  text-align: left;
  background: rgba(255,255,255,0.85);
  border: 1px solid var(--leaf-dark);
  border-radius: 4px;
  resize: none;
  line-height: 1.2;
  color: var(--ink);
}
.leaf .leaf-reason::placeholder { color: var(--green-dark); opacity: 0.5; font-style: italic; }
.leaf .leaf-label {
  font-size: 0.65rem; color: var(--green-dark); margin-bottom: 0.2rem;
  display: block; line-height: 1.15; font-weight: normal;
}
.leaf .leaf-label em { font-style: normal; font-weight: 700; }

/* ---- card-sq: a square card with 4 edge-words ---- */
.card-sq {
  width: 100%; height: 100%; aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-template-rows: auto 1fr auto;
  grid-template-areas:
    "top    top    top"
    "left   .      right"
    "bottom bottom bottom";
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px 4px;
  position: relative;
  font-size: 0.78rem;
  line-height: 1.1;
  text-align: center;
  cursor: default;
  transition: border-color 0.12s, transform 0.08s, box-shadow 0.12s;
}
.card-sq.tray,
.card-sq.static {
  width: 130px; height: 130px; aspect-ratio: 1 / 1;
}
.card-sq.tray { cursor: pointer; }
.card-sq.tray:hover { border-color: var(--green); }
.card-sq.tray.selected { border-color: var(--green); background: var(--green-soft); transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0,0,0,0.08); }
.card-sq.placed { cursor: pointer; } /* clickable to rotate */
.card-sq.tray.placed { opacity: 0.4; pointer-events: none; }

/* drag-and-drop */
.card-sq.tray { touch-action: none; user-select: none; -webkit-user-select: none; }
.card-sq.dragging {
  box-shadow: 0 12px 28px rgba(0,0,0,0.18), 0 4px 8px rgba(0,0,0,0.10);
  transform: scale(1.06) rotate(-2deg);
  cursor: grabbing;
  opacity: 0.96;
}
body.drag-active { cursor: grabbing; user-select: none; -webkit-user-select: none; }
.slot.drop-target {
  background: var(--green-soft) !important;
  border-color: var(--green) !important;
  border-style: solid !important;
  transform: scale(1.02);
}
.slot, .card-sq { transition: background 0.15s, border-color 0.15s, transform 0.12s ease, box-shadow 0.15s; }
.card-sq.tray:hover { transform: translateY(-2px); box-shadow: 0 4px 10px rgba(0,0,0,0.08); }

/* card text update animation when rotating */
@keyframes edge-pop {
  0%   { opacity: 0.25; transform: scale(0.85); }
  70%  { opacity: 1;    transform: scale(1.04); }
  100% { opacity: 1;    transform: scale(1); }
}
.card-sq.placed .edge { animation: edge-pop 0.22s ease both; }

/* perfect first-try celebration */
@keyframes confetti-pop {
  0%   { transform: scale(0.6) rotate(-10deg); opacity: 0; }
  60%  { transform: scale(1.12) rotate(3deg);  opacity: 1; }
  100% { transform: scale(1) rotate(0deg);     opacity: 1; }
}
.score-banner.perfect { animation: confetti-pop 0.55s ease both; }

.card-remove {
  position: absolute;
  top: 2px; right: 2px;
  width: 20px; height: 20px;
  padding: 0; line-height: 1;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: white;
  color: var(--bad);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: none;
  z-index: 2;
}
.card-sq.placed .card-remove { display: flex; align-items: center; justify-content: center; }
.card-remove:hover { background: var(--bad); color: white; border-color: var(--bad); }
.slot.locked .card-remove { display: none; } /* can't remove locked correct cards */

.slot.tried-wrong { border-color: var(--bad); border-style: solid; }
.tried-wrong-badge {
  position: absolute;
  top: -10px; left: 50%; transform: translateX(-50%);
  background: var(--bad); color: white;
  font-size: 0.65rem; padding: 0.1rem 0.45rem;
  border-radius: 999px; white-space: nowrap;
  z-index: 3;
}

.card-sq .edge {
  display: flex; align-items: center; justify-content: center;
  padding: 1px;
  color: var(--muted);
  min-width: 0; min-height: 0;
  white-space: nowrap;
  overflow: hidden;
}
.card-sq .edge.outside { color: var(--green-dark); font-weight: 700; }
.card-sq .edge-top    { grid-area: top; }
.card-sq .edge-bottom { grid-area: bottom; }
/* Side edges read along the card edge (vertical text), so long words
   like "Microscope" or "Helicopter" fit without breaking. */
.card-sq .edge-right {
  grid-area: right;
  writing-mode: vertical-rl;
  text-orientation: mixed;
  align-items: flex-end;
}
.card-sq .edge-left {
  grid-area: left;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  align-items: flex-end;
}

/* tray */
.tray {
  background: var(--paper); padding: 1rem;
  border-radius: 8px; box-shadow: var(--shadow); margin-top: 1rem;
}
.tray-label { font-weight: 600; margin-bottom: 0.5rem; }
.tray-cards { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: flex-start; }

.card-tray-row { display: flex; flex-wrap: wrap; gap: 0.6rem; }

.actions { display: flex; align-items: center; gap: 1rem; margin-top: 1.2rem; flex-wrap: wrap; }

/* misc */
.rules-mini summary { cursor: pointer; color: var(--muted); }
.rules-mini ul { color: var(--muted); font-size: 0.92rem; }
.score-banner {
  background: var(--green-soft); border-left: 6px solid var(--green);
  padding: 0.8rem 1rem; border-radius: 6px; margin: 1rem 0;
  font-size: 1.1rem;
}
.score-banner.perfect { background: linear-gradient(90deg, var(--green-soft), #fdf3d0); border-left-color: var(--gold); }
.decoy-section { margin: 1rem 0; }

.placements { width: 100%; border-collapse: collapse; margin-top: 0.5rem; font-size: 0.92rem; }
.placements th, .placements td { padding: 0.4rem 0.6rem; text-align: left; border-bottom: 1px solid var(--line); }
.placements tr.ok td { background: rgba(46,125,79,0.08); }
.placements tr.bad td { background: rgba(185,67,79,0.08); }
.placements.compact th, .placements.compact td { font-size: 0.85rem; padding: 0.3rem 0.5rem; }

/* attempt review */
.attempt-review { margin-top: 1.4rem; }
.attempt-review h3 { margin-bottom: 0.4rem; }
.slot.slot-correct { border-color: var(--green); border-style: solid; box-shadow: 0 0 0 2px rgba(46,125,79,0.15); }
.slot.slot-wrong { border-color: var(--bad); border-style: solid; box-shadow: 0 0 0 2px rgba(185,67,79,0.15); }
.slot-status {
  position: absolute; top: -10px; right: -10px;
  width: 24px; height: 24px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; line-height: 1;
  z-index: 2; color: white;
}
.slot.slot-correct .slot-status { background: var(--green); }
.slot.slot-wrong .slot-status { background: var(--bad); }

.leaf-summary { list-style: none; padding: 0; margin: 0.8rem 0 0; display: flex; flex-direction: column; gap: 0.5rem; }
.leaf-summary li { padding: 0.55rem 0.75rem; border-radius: 6px; border: 1px solid var(--line); background: var(--paper); }
.leaf-summary li.ok { border-left: 4px solid var(--green); }
.leaf-summary li.bad { border-left: 4px solid var(--bad); }
.leaf-summary .leaf-line { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.leaf-summary .leaf-line strong { font-size: 0.95rem; }
.leaf-summary .pair-line { font-size: 0.9rem; color: var(--ink); margin-top: 0.2rem; }
.leaf-summary .pair { font-weight: 700; color: var(--green-dark); }
.leaf-summary li.bad .pair { color: var(--bad); }
.leaf-summary .actual { color: var(--muted); margin-left: 0.4rem; }
.leaf-summary .reason { font-style: italic; color: var(--muted); margin-top: 0.3rem; padding: 0.35rem 0.5rem; background: var(--bg); border-radius: 4px; font-size: 0.88rem; }
.leaf-summary .status-mark { font-weight: 700; }
.leaf-summary li.ok .status-mark { color: var(--green); }
.leaf-summary li.bad .status-mark { color: var(--bad); }

.guess-card {
  background: var(--paper); padding: 1rem; border-radius: 8px;
  box-shadow: var(--shadow); margin-bottom: 1rem;
}
.guess-card header { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.5rem; }

.comments { margin-top: 1rem; padding-top: 0.8rem; border-top: 1px solid var(--line); }
.comments h4 { margin: 0 0 0.5rem; }
.comments ul { list-style: none; padding: 0; margin: 0 0 0.8rem; }
.comments li { padding: 0.4rem 0; border-bottom: 1px solid var(--line); }
.comments li p { margin: 0.2rem 0 0; }
.comment-form { display: flex; flex-direction: column; gap: 0.4rem; }
.comment-form button { align-self: flex-start; }

@media (max-width: 600px) {
  .clover-board { gap: 0.25rem; }
  .card-sq { font-size: 0.65rem; padding: 2px; }
  .card-sq.tray { width: 92px; height: 92px; }
  .leaf .clue-text { font-size: 0.85rem; }
  .leaf .leaf-label { font-size: 0.6rem; }
  main { padding: 1rem 0.75rem 3rem; }
}
