/* fridgle. — a daily fridge of word magnets */

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  /* the surface of a fridge: off-white powder coat with a fine speckle
     (the noise is a tiny inline svg, no image files) and a soft sheen */
  background-color: #f4f3ee;
  background-image:
    linear-gradient(100deg,
      rgba(255, 255, 255, 0.5) 0%,
      rgba(255, 255, 255, 0) 45%,
      rgba(210, 206, 195, 0.18) 100%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3CfeComponentTransfer%3E%3CfeFuncA type='linear' slope='0.055'/%3E%3C/feComponentTransfer%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  color: #33302a;
  font-family: Georgia, "Iowan Old Style", "Times New Roman", serif;
}

main {
  max-width: 42.5rem;
  margin: 0 auto;
  padding: 26px 18px 70px;
}

/* ---------- header ---------- */

header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}

h1 {
  font-size: 1.4rem;
  font-weight: normal;
  margin: 0;
  letter-spacing: 0.02em;
}

.corner { display: flex; align-items: baseline; gap: 0.9em; }

/* quiet text buttons: clear, copy, edit, hard mode */
.quiet {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 0.85rem;
  color: #8f8a7d;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
}
.quiet:hover { color: #33302a; }

/* "off" and "on" are different widths — pin the button so the header
   doesn't shift when hard mode toggles */
#hard-toggle { min-width: 13ch; text-align: left; }

/* ---------- the sentence line ---------- */

#line {
  /* a single writing line: magnets sit on it, and the area grows
     upward-wrapping as the sentence gets long */
  border-bottom: 1px solid #cfccc0;
  min-height: 3.1em;
  padding: 0.3em 0.2em 0.6em;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-end;
  align-items: center;
  row-gap: 0.7em;
  position: relative;
}

#line.empty::after {
  content: "drag tiles here";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #c9c5b8;
  font-style: italic;
  pointer-events: none;
}

/* ---------- magnets ---------- */

.tile {
  display: inline-block;
  background: #fffffe;
  border: 1px solid #c8c5b8;
  padding: 0.24em 0.53em 0.3em;
  font-size: 1.06rem;
  line-height: 1.3;
  white-space: pre;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
  /* every magnet sits a little crooked, like a real fridge */
  transform: rotate(var(--rot, 0deg)) translateY(var(--dy, 0px));
  box-shadow:
    0 1px 2px rgba(72, 60, 38, 0.18),
    0 2px 6px rgba(72, 60, 38, 0.08);
}

.tile.punct, .tile.affix {
  color: #6d675a;
  min-width: 1.9em;
  text-align: center;
}

/* the wear overlay: wiped-off patches that sit over the print */
.tile .wear {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* words with other forms are a little stack: the right edges of the
   magnets underneath stick out from beneath the top one, full height,
   flush with the tile. tapping that strip opens the menu. */
.tile { position: relative; }

/* words with other forms are a pile: whole darker tiles sit underneath
   the top one, offset a little right, so their edges show. they're drawn
   as sharp box-shadows (a fill + a 1px ring as the border each), which
   naturally paint behind the tile. two forms underneath at most. */
.tile.stacked {
  box-shadow:
    0 1px 2px rgba(72, 60, 38, 0.18),
    0 2px 6px rgba(72, 60, 38, 0.08),
    5px 1px 0 0 #e9e6d9,
    5px 1px 0 1px #b9b6a7,
    10px 2px 0 0 #e2dfd1,
    10px 2px 0 1px #aeab9c;
}
.tile.stacked.one {
  box-shadow:
    0 1px 2px rgba(72, 60, 38, 0.18),
    0 2px 6px rgba(72, 60, 38, 0.08),
    5px 1px 0 0 #e9e6d9,
    5px 1px 0 1px #b9b6a7;
}

/* invisible strip over the protruding pile: the tap target for the menu */
.tile .stack {
  position: absolute;
  top: -1px;
  bottom: -1px;
  right: -1.6em;
  width: 1.66em; /* wider than the visible edges — easier to tap on a phone */
  cursor: pointer;
  touch-action: none;
}

/* the pool and the line both leave room for the protruding pile */
#pool .tile.stacked, #line .tile.stacked { margin-right: 0.7em; }
#pool .tile.stacked.one, #line .tile.stacked.one { margin-right: 0.45em; }

/* spacing between magnets on the line: normal word gap by default,
   snug when something glues (punctuation, suffixes, dashes) */
#line .tile { margin-left: 0.55em; }
#line .tile.first { margin-left: 0; }
#line .tile.tight { margin-left: 2px; }

/* the one being dragged: the original stays as a faint ghost */
.tile.ghost { opacity: 0.25; cursor: grabbing; }

/* the copy that follows your finger */
.tile.clone {
  position: fixed;
  z-index: 40;
  margin: 0;
  pointer-events: none;
  transform: rotate(var(--rot, 0deg)) scale(1.07);
  box-shadow:
    0 5px 12px rgba(72, 60, 38, 0.28),
    0 12px 28px rgba(72, 60, 38, 0.14);
}

/* thin marker showing where the magnet will land */
.caret {
  width: 2px;
  height: 1.7em;
  border-radius: 1px;
  background: #b5ae9d;
  margin-left: 3px;
  align-self: center;
}

/* the morning deal: magnets drop onto the fridge one after another */
.tile.arrive {
  animation: arrive 0.26s cubic-bezier(0.2, 0.8, 0.3, 1) backwards;
}
@keyframes arrive {
  0% { opacity: 0; translate: 0 -16px; scale: 1.1; }
  70% { opacity: 1; translate: 0 1px; }
  100% { opacity: 1; translate: 0 0; scale: 1; }
}

/* small "no" shake, e.g. tapping a magnet that has no other forms */
.tile.wiggle { animation: wiggle 0.22s ease-in-out; }
@keyframes wiggle {
  25% { transform: rotate(calc(var(--rot, 0deg) - 2.5deg)) translateY(var(--dy, 0px)); }
  75% { transform: rotate(calc(var(--rot, 0deg) + 2.5deg)) translateY(var(--dy, 0px)); }
}

/* ---------- under the line: hard mode info + buttons ---------- */

#meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  min-height: 2em;
}

#hard-info { color: #8f8a7d; font-size: 0.85rem; }
#hard-info.over { color: #a8574a; }
/* hard mode counter: reddish until the word count is exactly right */
#hard-info.bad { color: #a8574a; }
#hard-info.good { color: #6f8a55; }

#actions { margin-left: auto; display: flex; align-items: center; gap: 1.2em; }

/* finalize looks like a magnet itself */
#finalize-btn {
  font: inherit;
  font-size: 0.92rem;
  background: #fffffe;
  color: #33302a;
  border: 1px solid #dcdad1;
  padding: 0.3em 0.9em 0.35em;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(72, 60, 38, 0.16);
}
#finalize-btn:hover:not(:disabled) { border-color: #b5ae9d; }
#finalize-btn:disabled { opacity: 0.4; cursor: default; }

/* ---------- the poem card (after finalize) ---------- */

#poem {
  position: fixed;
  z-index: 70;
  left: 50%;
  top: 10%;
  transform: translateX(-50%);
  width: min(38rem, 92vw);
  background: #fefdf9;
  border: 1px solid #c8c5b8;
  padding: 2.2em 2.2em 1.9em;
  text-align: center;
  box-shadow:
    0 8px 20px rgba(72, 60, 38, 0.18),
    0 24px 60px rgba(72, 60, 38, 0.14);
  animation: poem-in 0.35s ease-out;
}

@keyframes poem-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }
}

@media (prefers-reduced-motion: reduce) {
  #poem { animation: none; }
}

#poem-label { color: #8f8a7d; font-size: 1rem; margin-bottom: 1.1em; }

#poem-text {
  font-size: 1.9rem;
  line-height: 1.5;
  font-style: italic;
  color: #33302a;
  overflow-wrap: break-word;
}

.poem-row {
  margin-top: 1.4em;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 1.2em;
}

/* the share button is a magnet, like finalize */
#share-btn {
  font: inherit;
  font-size: 1.05rem;
  background: #fffffe;
  color: #33302a;
  border: 1px solid #c8c5b8;
  padding: 0.35em 1em 0.4em;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(72, 60, 38, 0.16);
}
#share-btn:hover { border-color: #b5ae9d; }

#copy-note { color: #8f8a7d; font-size: 0.85rem; font-style: italic; }

/* ---------- the pool of unused magnets ---------- */

#pool {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7em 0.5em;
  margin-top: 28px;
  padding: 2px;
}

/* once finalized, the fridge is done for today */
body.done .tile { cursor: default; }
body.done #pool .tile { opacity: 0.45; }

/* ---------- history panel: your finalized prose ---------- */

#history {
  position: fixed;
  z-index: 60;
  left: 50%;
  top: 12%;
  transform: translateX(-50%);
  width: min(28rem, 88vw);
  max-height: 62vh;
  overflow-y: auto;
  background: #fefdf9;
  border: 1px solid #dcdad1;
  border-radius: 8px;
  padding: 16px 20px 18px;
  box-shadow:
    0 6px 16px rgba(72, 60, 38, 0.16),
    0 18px 40px rgba(72, 60, 38, 0.12);
}

#history h2 {
  margin: 0 0 4px;
  font-size: 1rem;
  font-weight: normal;
  font-style: italic;
  color: #6d675a;
}

.history-entry { margin-top: 14px; }
.history-share { margin-left: 0.9em; }
.history-day { color: #8f8a7d; font-size: 0.8rem; }
.history-sentence { margin-top: 2px; color: #3a362e; }
.history-empty { color: #8f8a7d; font-style: italic; margin: 12px 0 4px; }

/* ---------- tap-a-word menu of other forms ---------- */

#menu {
  position: fixed;
  z-index: 50;
  background: #fffffe;
  border: 1px solid #dcdad1;
  border-radius: 8px;
  box-shadow:
    0 4px 10px rgba(72, 60, 38, 0.16),
    0 12px 30px rgba(72, 60, 38, 0.12);
  padding: 5px 0;
  min-width: 7.5em;
  max-height: 42vh;
  overflow-y: auto;
}

.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  font: inherit;
  font-size: 1rem;
  color: #33302a;
  padding: 0.45em 0.9em;
  cursor: pointer;
}
.menu-item:hover { background: #f5f4ee; }

.menu-item.now { font-weight: bold; }
.menu-item.now::after { content: " •"; color: #b5ae9d; }

@media (max-width: 480px) {
  main { padding-top: 18px; }
  .tile { font-size: 1rem; }
}
