:root {
  --ink: #111;
  --fridge: #e8e8e4;
  --accent: #111;
  --tile-font: 600 17px/24px ui-rounded, -apple-system, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  color: var(--ink);
  font: 16px/1.5 -apple-system, "Segoe UI", system-ui, sans-serif;
  background: var(--fridge);
}

/* ---------- shared bits ---------- */

.btn {
  display: inline-block;
  padding: 10px 18px;
  font: 600 15px/1.2 inherit;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid #bbb;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  touch-action: manipulation;
}
.btn:active { transform: translate(1px, 1px); border-right-width: 2px; border-bottom-width: 2px; }
.btn-dark { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-big { padding: 14px 26px; font-size: 17px; }

/* ---------- editor ---------- */

.editor-body {
  overflow: hidden;
  height: 100dvh;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  pointer-events: none;
}
.topbar > * { pointer-events: auto; }

.brand {
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.5px;
  color: var(--ink);
  text-decoration: none;
  background: #fff;
  padding: 6px 12px;
  border: 1px solid #bbb;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  border-radius: 4px;
}

#board {
  position: fixed;
  inset: 0;
  touch-action: none;
  cursor: grab;
  background:
    radial-gradient(120% 90% at 30% 0%, rgba(255, 255, 255, 0.75), rgba(255, 255, 255, 0) 60%),
    var(--fridge);
}
#board.panning { cursor: grabbing; }

#canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

.tile {
  position: absolute;
  background: #fff;
  color: var(--ink);
  font: var(--tile-font);
  white-space: nowrap;
  padding: 8px 12px;
  border: 1px solid #c9c9c4;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  border-radius: 2px;
  cursor: grab;
  touch-action: none;
}
.tile.dragging {
  cursor: grabbing;
  box-shadow: 4px 6px 10px rgba(0, 0, 0, 0.25);
}
.tile.menu-open { outline: 2px dashed var(--ink); outline-offset: 2px; }

/* floating controls */

.fab-stack {
  position: fixed;
  right: calc(env(safe-area-inset-right) + 14px);
  bottom: calc(env(safe-area-inset-bottom) + 96px);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fab {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  color: var(--ink);
  border: 1px solid #bbb;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}
.fab:active { transform: translate(1px, 1px); }
.fab-small {
  width: 44px;
  height: 44px;
  font-size: 22px;
  font-weight: 700;
}
.fab-add {
  position: fixed;
  right: calc(env(safe-area-inset-right) + 14px);
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  z-index: 20;
  width: 60px;
  height: 60px;
  font-size: 34px;
  font-weight: 700;
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
  border-radius: 12px;
}

/* long-press menu */

.tile-menu {
  position: fixed;
  z-index: 30;
  display: flex;
  flex-direction: column;
  min-width: 150px;
  background: #fff;
  border: 1px solid #bbb;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
}
.tile-menu button {
  padding: 13px 16px;
  font: 600 16px/1 inherit;
  font-family: inherit;
  text-align: left;
  background: none;
  border: none;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}
.tile-menu button:last-child { border-bottom: none; }
.tile-menu button:active { background: #f0f0ec; }
.tile-menu .danger { color: #b00020; }

/* modals */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border: 1px solid #bbb;
  border-right: 4px solid var(--ink);
  border-bottom: 4px solid var(--ink);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: calc(env(safe-area-inset-bottom) + 8px);
}
.modal-card h2 { margin: 0 0 12px; font-size: 18px; }
.modal-card textarea {
  width: 100%;
  font: var(--tile-font);
  padding: 10px;
  border: 1px solid #bbb;
  border-radius: 6px;
  resize: none;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}
.share-hint { margin: 0 0 12px; font-size: 14px; color: #555; }
.share-row { display: flex; gap: 8px; }
.share-row input {
  flex: 1;
  min-width: 0;
  font: 14px/1.4 ui-monospace, monospace;
  padding: 10px;
  border: 1px solid #bbb;
  border-radius: 6px;
}

@media (min-width: 600px) {
  .modal { align-items: center; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 24px);
  transform: translateX(-50%);
  z-index: 50;
  background: var(--ink);
  color: #fff;
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 8px;
  pointer-events: none;
}

/* ---------- home ---------- */

.home-body main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px calc(env(safe-area-inset-bottom) + 48px);
}

.home-hero {
  max-width: 1080px;
  margin: 0 auto;
  padding: 48px 16px 12px;
  text-align: center;
}
.home-hero h1 { margin: 0 0 14px; font-size: 44px; }
.magnet-word {
  display: inline-block;
  background: #fff;
  padding: 6px 18px;
  border: 1px solid #c9c9c4;
  border-right: 5px solid var(--ink);
  border-bottom: 5px solid var(--ink);
  border-radius: 3px;
  transform: rotate(-1.5deg);
}
.home-hero p {
  max-width: 520px;
  margin: 0 auto 22px;
  color: #444;
}
.hero-actions { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }

.feed-title { margin: 40px 0 16px; font-size: 20px; }

.story-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}

.story-card {
  display: block;
  background: #fff;
  border: 1px solid #c9c9c4;
  border-right: 3px solid var(--ink);
  border-bottom: 3px solid var(--ink);
  border-radius: 6px;
  overflow: hidden;
  text-decoration: none;
  color: var(--ink);
}
.story-card:active { transform: translate(1px, 1px); }
.story-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1200 / 630;
  object-fit: cover;
  border-bottom: 1px solid #eee;
  background: var(--fridge);
}
.story-card .card-text {
  padding: 10px 12px 12px;
}
.story-card .card-snippet {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-weight: 600;
  font-size: 15px;
  line-height: 1.35;
  min-height: 2.7em;
}
.story-card .card-date {
  margin-top: 6px;
  font-size: 12.5px;
  color: #777;
}

.empty-state {
  text-align: center;
  padding: 48px 0;
  color: #555;
}
.empty-state .btn { margin-top: 10px; }

#sentinel { height: 1px; }
.feed-status { text-align: center; color: #777; padding: 18px 0; }
