/* ==========================================================================
   Tessra homepage — core stylesheet
   --------------------------------------------------------------------------
   This site has no layout chrome of its own. Every piece of content lives
   inside a .widget — the exact same card the extension renders on your new
   tab. The tokens below are lifted straight from the extension's newtab.css
   so the two surfaces look identical.

   Files:
     tessra.css   ← you are here (tokens, page/board layout, widget frame)
     widgets.css  ← the insides of every individual widget
     tessra.js    ← live data, dragging, responsive relayout, theme
     editor.js    ← LAYOUT EDIT MODE. Delete the file + its <script> tag
                    in index.html to ship production.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Design tokens  (mirrors Tessra's newtab.css :root block)
   -------------------------------------------------------------------------- */
:root {
  --grid-size: 20px;

  --bg: #fafafa;
  --dot: #d8d8d8;
  --fg: #1a1a1a;
  --muted: #7a7a7a;
  --faint: #a1a1aa;

  --panel-bg: #ffffff;
  --panel-border: #ececec;

  /* Monochrome accent — the preset this project ships its own site with. */
  --accent: #1a1a1a;
  --accent-ink: #ffffff;
  --accent-soft: rgba(26, 26, 26, 0.07);

  --widget-bg: #ffffff;
  --widget-border: #e5e5e5;
  --widget-border-width: 1px;
  --widget-radius: 10px;
  --widget-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.04);
  --widget-shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.06), 0 6px 16px rgba(0, 0, 0, 0.06);

  /* Surface tints. Flip to white-alpha in dark mode so they still register. */
  --tint: rgba(0, 0, 0, 0.03);
  --tint-2: rgba(0, 0, 0, 0.06);
  --tint-3: rgba(0, 0, 0, 0.10);
  --hair: rgba(0, 0, 0, 0.07);

  --pos: #16a34a;
  --neg: #dc2626;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto,
          Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
          "Liberation Mono", monospace;
  --hand: "Bradley Hand", "Segoe Print", "Comic Sans MS", cursive;

  /* Authored canvas width. Every left/top in index.html is relative to this. */
  --canvas: 1200px;
}

/* Dark tokens — applied by the explicit toggle and by the OS in auto mode. */
:root[data-theme="dark"] {
  --bg: #18181b;
  --dot: #3f3f46;
  --fg: #f4f4f5;
  --muted: #a1a1aa;
  --faint: #71717a;

  --panel-bg: #27272a;
  --panel-border: #3f3f46;

  --accent: #f4f4f5;
  --accent-ink: #18181b;
  --accent-soft: rgba(255, 255, 255, 0.10);

  --widget-bg: #27272a;
  --widget-border: #3f3f46;
  --widget-shadow: 0 1px 2px rgba(0, 0, 0, 0.20), 0 2px 8px rgba(0, 0, 0, 0.24);
  --widget-shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.28), 0 6px 16px rgba(0, 0, 0, 0.32);

  --tint: rgba(255, 255, 255, 0.05);
  --tint-2: rgba(255, 255, 255, 0.08);
  --tint-3: rgba(255, 255, 255, 0.14);
  --hair: rgba(255, 255, 255, 0.09);

  --pos: #4ade80;
  --neg: #f87171;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --bg: #18181b;
    --dot: #3f3f46;
    --fg: #f4f4f5;
    --muted: #a1a1aa;
    --faint: #71717a;
    --panel-bg: #27272a;
    --panel-border: #3f3f46;
    --accent: #f4f4f5;
    --accent-ink: #18181b;
    --accent-soft: rgba(255, 255, 255, 0.10);
    --widget-bg: #27272a;
    --widget-border: #3f3f46;
    --widget-shadow: 0 1px 2px rgba(0, 0, 0, 0.20), 0 2px 8px rgba(0, 0, 0, 0.24);
    --widget-shadow-hover: 0 2px 4px rgba(0, 0, 0, 0.28), 0 6px 16px rgba(0, 0, 0, 0.32);
    --tint: rgba(255, 255, 255, 0.05);
    --tint-2: rgba(255, 255, 255, 0.08);
    --tint-3: rgba(255, 255, 255, 0.14);
    --hair: rgba(255, 255, 255, 0.09);
    --pos: #4ade80;
    --neg: #f87171;
  }
}

/* --------------------------------------------------------------------------
   2. Page shell — the dotted grid, exactly as the extension draws it
   -------------------------------------------------------------------------- */
* { box-sizing: border-box; }

html {
  scroll-behavior: smooth;
  /* Anchor targets sit under the sticky nav widget. */
  scroll-padding-top: 92px;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg);
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: var(--grid-size) var(--grid-size);
  background-position: 0 0;
  background-repeat: repeat;
  /* Canvas mode positions widgets absolutely inside 1200px-wide boards; on
     small screens tessra.js swaps to data-mode="flow" and they stack. */
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

/* Screen-reader-only text — used for the real <h1>/<h2> landmarks so the
   page stays navigable even though visually the headings live in widgets. */
.sr {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* --------------------------------------------------------------------------
   3. Boards — one per page section. A board is a fixed-size canvas that
      widgets are absolutely placed on, centred in the viewport.
   -------------------------------------------------------------------------- */
.board-wrap {
  position: relative;
  width: 100%;
  /* JS sets this to (board height × scale) so the page scrolls correctly
     once a board has been scaled down for a mid-size viewport. */
}

.board {
  position: relative;
  width: var(--canvas);
  margin: 0 auto;
  transform-origin: top center;
}

/* --- Flow mode: narrow viewports. Boards become a simple stacked column and
       every purely decorative widget drops out. ------------------------- */
body[data-mode="flow"] .board-wrap { height: auto !important; }

body[data-mode="flow"] .board {
  width: 100%;
  max-width: 620px;
  height: auto !important;
  padding: 0 16px;
  transform: none !important;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

body[data-mode="flow"] .widget {
  position: relative !important;
  left: auto !important;
  top: auto !important;
  width: 100% !important;
  height: auto !important;
  min-height: 0 !important;
  transform: none !important;
  z-index: auto !important;
}

body[data-mode="flow"] .widget[data-deco="1"] { display: none !important; }

/* Stickies keep their tilt even when stacked — they're the one element whose
   whole charm is the rotation. */
body[data-mode="flow"] .widget[data-type="stickies"] { align-self: center; width: 210px !important; }

/* Section rhythm */
.section {
  padding: 0 0 26px;
}
.section:first-of-type { padding-top: 8px; }

body[data-mode="flow"] .section { padding: 0 0 22px; }

/* --------------------------------------------------------------------------
   4. The widget frame — 1:1 with .widget in the extension's newtab.css
   -------------------------------------------------------------------------- */
.widget {
  position: absolute;
  background: var(--widget-bg);
  border: var(--widget-border-width) solid var(--widget-border);
  border-radius: var(--widget-radius);
  box-shadow: var(--widget-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: box-shadow 0.15s ease;
}

/* Reveal-on-scroll: widgets fade up as their board arrives. Gated behind
   body.js-reveal, which tessra.js adds the moment it runs — so if the script
   is missing or blocked the page still renders every widget instead of a
   blank canvas. JS adds .in once the board enters the viewport. */
body.js-reveal .board-wrap:not(.in) .widget { opacity: 0; }
body.js-reveal .board-wrap.in .widget {
  animation: widget-rise 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}
@keyframes widget-rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
/* Never animate the sticky nav or a widget the visitor is dragging. */
.widget.no-anim, .widget.dragging, .widget.moved { animation: none !important; opacity: 1 !important; }

.widget:hover { box-shadow: var(--widget-shadow-hover); }

.widget.dragging {
  opacity: 0.9;
  box-shadow: var(--widget-shadow-hover);
  cursor: grabbing;
  transform: none;
}

@media (prefers-reduced-motion: reduce) {
  body.js-reveal .board-wrap .widget,
  body.js-reveal .board-wrap:not(.in) .widget { animation: none !important; opacity: 1 !important; }
  html { scroll-behavior: auto; }
}

/* --- Header: × on the right, editable-looking title on the left --------- */
.widget-header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--widget-border);
  background: var(--tint);
  user-select: none;
  flex: 0 0 auto;
  cursor: grab;
}
.widget-header:active { cursor: grabbing; }

.widget-title-wrap {
  flex: 1;
  order: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  overflow: hidden;
}

.widget-title {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 1px 5px;
  border-radius: 3px;
  letter-spacing: 0.1px;
}
.widget-title:hover { background: var(--tint-2); }

.widget-remove {
  order: 3;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.widget-remove:hover { color: #dc2626; background: var(--tint-2); }

/* --- Body -------------------------------------------------------------- */
.widget-body {
  flex: 1 1 auto;
  padding: 16px;
  overflow: auto;
  min-height: 0;
}

/* Scrollbars inside widgets stay discreet, like the extension's. */
.widget-body::-webkit-scrollbar { width: 8px; height: 8px; }
.widget-body::-webkit-scrollbar-thumb {
  background: var(--tint-3);
  border-radius: 8px;
}
.widget-body::-webkit-scrollbar-track { background: transparent; }

/* Padding variants a few widgets ask for */
.widget-body.pad-sm { padding: 10px 12px; }
.widget-body.pad-0  { padding: 0; }

/* Vertically centred body — clocks, moon, dice, gauges.
   These are fixed-size display widgets whose content is comfortably shorter
   than the card, so they must never scroll. Without `hidden`, flex centring
   leaves the content on a fractional offset and scrollHeight rounds up by 1px,
   which is enough for the browser to draw a phantom scrollbar. */
.widget-body.center {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   5. Generic in-widget primitives, shared by many widgets
   -------------------------------------------------------------------------- */
.w-mut   { color: var(--muted); font-size: 11px; }
.w-mut-2 { color: var(--faint); font-size: 10px; }
.w-lbl   {
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.7px;
  text-transform: uppercase;
}
.w-big   { font-size: 34px; font-weight: 300; letter-spacing: -1px; line-height: 1.05; }
.w-mono  { font-family: var(--mono); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* Row with label left, value right */
.w-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  font-size: 13px;
}
.w-row + .w-row { border-top: 1px solid var(--hair); }
.w-row b { font-weight: 600; }

/* Thin progress bar */
.w-bar {
  height: 6px;
  border-radius: 99px;
  background: var(--tint-2);
  overflow: hidden;
}
.w-bar > i {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.4s ease;
}

/* Footer strip inside a widget body */
.w-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--hair);
  color: var(--muted);
  font-size: 10px;
}
.w-foot .add { cursor: pointer; }
.w-foot .add:hover { color: var(--fg); }

/* Small in-widget button, matching the extension's .btn-subtle */
.w-btn {
  font: inherit;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--widget-border);
  background: var(--tint);
  color: var(--fg);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.w-btn:hover { background: var(--tint-2); border-color: var(--tint-3); }
.w-btn:active { transform: translateY(1px); }
.w-btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.w-btn.primary:hover { filter: brightness(1.12); }

.w-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* Pill / chip */
.w-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 99px;
  border: 1px solid var(--widget-border);
  background: var(--tint);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.w-chip .live {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pos);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--pos) 22%, transparent);
}

/* Icon sizing default for inline SVGs */
.widget-body svg { display: block; }

/* --------------------------------------------------------------------------
   6. Prose widgets — the "content" half of the page. These are Notes /
      Markdown widgets, so their typography mimics the extension's markdown
      renderer rather than a marketing page.
   -------------------------------------------------------------------------- */
.prose { font-size: 14px; line-height: 1.62; color: var(--fg); }

.prose > :first-child { margin-top: 0; }
.prose > :last-child  { margin-bottom: 0; }

.prose h1 {
  margin: 0 0 6px;
  font-size: 46px;
  font-weight: 650;
  letter-spacing: -1.6px;
  line-height: 1.02;
}
.prose h2 {
  margin: 0 0 8px;
  font-size: 27px;
  font-weight: 640;
  letter-spacing: -0.7px;
  line-height: 1.14;
}
.prose h3 {
  margin: 16px 0 5px;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.2px;
}
.prose h4 {
  margin: 14px 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
}
.prose p { margin: 0 0 10px; color: var(--muted); }
.prose p.lead { font-size: 15.5px; line-height: 1.6; }
.prose strong, .prose b { color: var(--fg); font-weight: 640; }
.prose a { color: var(--fg); text-decoration: underline; text-decoration-color: var(--tint-3); text-underline-offset: 2px; }
.prose a:hover { text-decoration-color: currentColor; }
.prose code {
  font-family: var(--mono);
  font-size: 0.88em;
  padding: 1.5px 5px;
  border-radius: 4px;
  background: var(--tint-2);
}
.prose ul { margin: 0 0 10px; padding-left: 18px; color: var(--muted); }
.prose li { margin: 3px 0; }
.prose hr { border: 0; border-top: 1px solid var(--hair); margin: 14px 0; }

/* The markdown widget shows its source-ish heading marks, like the real one */
.md-mark { color: var(--faint); font-weight: 400; }

/* The hero wordmark, with the Tessra mark set beside it at cap height. */
.hero-title {
  display: flex;
  align-items: center;
  gap: 15px;
}
.hero-logo {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 13px;
  background: var(--accent);
  color: var(--accent-ink);
}
.hero-logo svg { width: 30px; height: 30px; }

/* Tagline under the big Tessra wordmark */
.tagline {
  margin: 0 0 12px;
  font-size: 19px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: -0.3px;
}

/* --------------------------------------------------------------------------
   7. Brand mark
   -------------------------------------------------------------------------- */
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  font-size: 15px;
  letter-spacing: -0.3px;
  text-decoration: none;
  color: var(--fg);
}
.brand .logo {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  flex: 0 0 auto;
}

/* --------------------------------------------------------------------------
   8. Nav — itself a Shortcuts widget, pinned to the top of the viewport
   -------------------------------------------------------------------------- */
.nav-wrap {
  position: sticky;
  top: 14px;
  z-index: 60;
  width: 100%;
  padding: 14px 16px 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.widget.nav-widget {
  position: relative;
  width: 100%;
  max-width: var(--canvas);
  pointer-events: auto;
  background: color-mix(in srgb, var(--widget-bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(180%);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
}

.nav-body {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 9px 14px;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-wrap: wrap;
}

.navlink {
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}
.navlink:hover { background: var(--tint-2); color: var(--fg); }

.nav-cta {
  margin-left: 4px;
  padding: 7px 13px;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.nav-cta:hover { filter: brightness(1.14); }

.theme-toggle {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 8px;
  border: 1px solid var(--widget-border);
  background: var(--tint);
  color: var(--muted);
  cursor: pointer;
  flex: 0 0 auto;
}
.theme-toggle:hover { color: var(--fg); background: var(--tint-2); }
.theme-toggle svg { width: 15px; height: 15px; }
.theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: block; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .theme-toggle .icon-sun { display: none; }
  :root[data-theme="auto"] .theme-toggle .icon-moon { display: block; }
}

@media (max-width: 860px) {
  .nav-wrap { padding: 10px 10px 0; top: 8px; }
  .nav-body { gap: 10px; padding: 8px 10px; }
  .nav-links .navlink { display: none; }
  .nav-links { gap: 6px; }
}

/* --------------------------------------------------------------------------
   9. Buttons used inside CTA widgets (bigger than .w-btn)
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 17px;
  border-radius: 9px;
  border: 1px solid var(--widget-border);
  background: var(--widget-bg);
  color: var(--fg);
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.13s, border-color 0.13s, transform 0.13s;
}
.btn:hover { background: var(--tint); border-color: var(--tint-3); }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; flex: 0 0 auto; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.btn-primary:hover { background: var(--accent); filter: brightness(1.14); }

/* --------------------------------------------------------------------------
   10. Hints & captions that float on the grid (not widgets, but tiny
       one-line affordances the extension shows too)
   -------------------------------------------------------------------------- */
.grid-hint {
  position: absolute;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 99px;
  background: color-mix(in srgb, var(--widget-bg) 78%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--widget-border);
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 40;
  transition: opacity 0.4s ease;
}
body.touched .grid-hint { opacity: 0; }
body[data-mode="flow"] .grid-hint { display: none; }

/* --------------------------------------------------------------------------
   11. Edit-mode hooks. Harmless when editor.js is deleted — nothing ever
       adds these classes and the rules simply never match.
   -------------------------------------------------------------------------- */
.widget-resize {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  display: none;
  z-index: 5;
  opacity: 0.45;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'><path d='M3 14 L14 3 M7 14 L14 7 M11 14 L14 11' stroke='%237a7a7a' stroke-width='1.5' stroke-linecap='round' fill='none'/></svg>");
  background-repeat: no-repeat;
  background-position: center;
}
body.edit-mode .widget-resize { display: block; }
body.edit-mode .widget-resize:hover { opacity: 1; }

body.edit-mode .widget { outline: 1px dashed var(--tint-3); outline-offset: 2px; }
body.edit-mode .widget.sel { outline: 2px solid var(--accent); outline-offset: 2px; }
body.edit-mode .board { background: color-mix(in srgb, var(--accent) 3%, transparent); }
.widget.resizing { opacity: 0.95; user-select: none; }
