@import url("https://fonts.googleapis.com/css2?family=Inter+Tight:wght@300;400;500&family=IBM+Plex+Mono:wght@300;400&display=swap");

:root {
  --paper: #fbfaf6;
  --ink: #171510;
  --faint: #8a867a;
  --hair: #e3e0d4;
  --soil: #f3f1e9;
  --accent: #c2401c;
  --accent-soft: rgba(194, 64, 28, 0.08);
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --sans: "Inter Tight", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-weight: 300;
  -webkit-font-smoothing: antialiased;
  display: flex;
  justify-content: center;
}

#app {
  width: min(560px, 100%);
  padding: 40px 20px 56px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ——— masthead ——— */
#mast {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  border-bottom: 1px solid var(--ink);
  padding-bottom: 10px;
}
#brand {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.32em;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
}
#brand-dot {
  width: 8px; height: 8px;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: pulse 4s linear infinite;
}
@keyframes pulse {
  0% { transform: rotate(0); border-radius: 50%; }
  50% { border-radius: 20%; }
  100% { transform: rotate(360deg); border-radius: 50%; }
}
#status {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--faint);
  white-space: nowrap;
}
#status .sep { margin: 0 6px; opacity: 0.5; }
#gen { color: var(--ink); }

#hint {
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.04em;
  color: var(--faint);
  margin: 12px 0 18px;
  text-align: center;
}

/* ——— grid ——— */
#grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  border-top: 1px solid var(--hair);
  border-left: 1px solid var(--hair);
  touch-action: none;
  cursor: crosshair;
  user-select: none;
  -webkit-user-select: none;
}
.cell {
  aspect-ratio: 1;
  border-right: 1px solid var(--hair);
  border-bottom: 1px solid var(--hair);
  background: var(--paper);
  position: relative;
  transition: background 0.25s ease;
}
.cell:nth-child(odd) { background: var(--soil); }
.cell.sown { cursor: ew-resize; }
.cell .ring {
  position: absolute; inset: 22%;
  border: 1px solid var(--ink);
  border-radius: 50%;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.5s ease, transform 0.8s cubic-bezier(0.2, 0.9, 0.25, 1.2);
}
.cell.sown .ring { opacity: 1; transform: scale(1); }
.cell .hand {
  position: absolute;
  left: calc(50% - 0.5px); top: 26%;
  width: 1px; height: 24%;
  background: var(--accent);
  transform-origin: 50% 100%;
  opacity: 0;
}
.cell.sown .hand { opacity: 1; }
.cell .dot {
  position: absolute;
  left: 50%; top: 50%;
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--accent);
  transform: translate(-50%, -50%) scale(0);
  transition: transform 0.6s ease;
}
.cell.sown .dot { transform: translate(-50%, -50%) scale(var(--bloom, 0.4)); }
.cell .strike {
  position: absolute; inset: 22%;
  border: 1px solid var(--accent);
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
}
.cell .strike.hit { animation: ripple 1.1s ease-out; }
@keyframes ripple {
  0% { opacity: 0.9; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.7); }
}
.cell.rewinding { background: var(--accent-soft); }
.cell .ghost {
  position: absolute; inset: 30%;
  border: 1px dashed var(--faint);
  border-radius: 50%;
  opacity: 0;
}
.cell.rewinding .ghost { opacity: 1; }

/* ——— export rail ——— */
#rail {
  margin-top: 26px;
  padding: 20px 0 22px;
  text-align: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
  position: relative;
}
#rail-line {
  display: block;
  height: 1px;
  background: var(--ink);
  transition: background 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}
#rail-label {
  display: inline-block;
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.14em;
  color: var(--faint);
  transition: color 0.2s ease;
}
#rail.armed #rail-line {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  transform: scaleY(3);
}
#rail.armed #rail-label { color: var(--accent); }
#rail.exporting #rail-line { animation: railflash 0.7s ease; }
@keyframes railflash {
  0% { background: var(--accent); box-shadow: 0 0 0 6px var(--accent-soft); }
  100% { background: var(--ink); box-shadow: none; }
}

/* ——— footer ——— */
#foot {
  margin-top: 18px;
  border-top: 1px solid var(--hair);
  padding-top: 10px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--faint);
}
#chime {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 60%;
}
#chime.struck { color: var(--accent); }

/* ——— toast ——— */
#toast {
  position: fixed;
  bottom: 26px; left: 50%;
  transform: translate(-50%, 12px);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  background: var(--ink);
  color: var(--paper);
  padding: 8px 16px;
  border-radius: 999px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s ease;
  max-width: 90vw;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 420px) {
  #app { padding: 26px 14px 44px; }
  #mast { flex-direction: column; gap: 4px; align-items: flex-start; }
  #hint { font-size: 10px; }
  #foot { flex-direction: column; gap: 4px; }
  #chime { max-width: 100%; }
}
