:root {
  --page: #fbf7f1;
  --ink: #1b1916;
  --muted: #736b62;
  --line: #ddd3c6;
  --accent: #5e8a74;
  --nav-h: 56px;
  --serif: "EB Garamond", Garamond, Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--page);
  transition: background-color 0.5s ease;
  color: var(--ink);
  font-family: var(--serif);
  font-size: 17px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* ---------- top nav: one tab per visual direction ---------- */
.topnav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: stretch;
  gap: 36px;
  height: var(--nav-h);
  padding: 0 34px;
  background: var(--page);
  border-bottom: 1px solid var(--line);
  transition: background-color 0.5s ease;
}

.brand {
  display: flex;
  align-items: center;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.005em;
  white-space: nowrap;
}

.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }

.tab {
  position: relative;
  border: 0;
  border-radius: 0;
  padding: 0 14px;
  font-size: 17px;
  color: var(--muted);
  white-space: nowrap;
}
.tab:hover:not(:disabled) { background: none; color: var(--ink); }
.tab[aria-selected="true"] { color: var(--ink); }
.tab[aria-selected="true"]::after {
  content: "";
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: -1px;
  height: 2px;
  background: var(--ink);
}
.tab:focus-visible { outline-offset: -4px; }

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  min-height: calc(100vh - var(--nav-h));
}

/* ---------- stage ---------- */
.stage {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 56px 48px 40px;
  position: sticky;
  top: var(--nav-h);
  height: calc(100vh - var(--nav-h));
}

.specimen { margin: 0; width: min(max(320px, calc(100vh - var(--nav-h) - 150px)), 100%); }

.tile-wrap { position: relative; aspect-ratio: 1; }

/* the coloured block peeking out behind each tile in the installation */
.tile-wrap::before {
  content: "";
  position: absolute;
  left: -6%;
  top: -6%;
  width: 64%;
  height: 38%;
  background: var(--accent);
  opacity: 0.88;
  transition: background-color 0.6s ease;
}

.tile {
  position: relative;
  width: 100%;
  height: 100%;
  box-shadow: 0 1px 2px rgba(60, 40, 20, 0.12), 0 14px 30px -18px rgba(60, 40, 20, 0.45);
}

.tile svg { display: block; width: 100%; height: 100%; }

.caption {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
  font-size: 19px;
  font-variant-numeric: oldstyle-nums;
}

#fold-note { color: var(--muted); font-style: italic; }

/* ---------- panel ---------- */
.panel {
  border-left: 1px solid var(--line);
  padding: 48px 34px 36px;
  display: flex;
  flex-direction: column;
  justify-content: space-between; /* everything else on top, export at the bottom */
  gap: 30px;
}

.panel-main { display: flex; flex-direction: column; gap: 30px; }

h1 {
  margin: 0 0 8px;
  font-weight: 500;
  font-size: 34px;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.lede { margin: 0; color: var(--muted); font-size: 16px; }

h2, .control label, .export span {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h2 { margin: 0 0 12px; }

.control-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.readout { display: inline-flex; align-items: center; gap: 10px; }

#fold-icon { width: 26px; height: 26px; overflow: visible; }

output {
  font-size: 40px;
  line-height: 1;
  font-variant-numeric: lining-nums tabular-nums;
  min-width: 1.3em;
  text-align: right;
}

.hint { margin: 8px 0 0; color: var(--muted); font-size: 15px; }

kbd {
  font-family: var(--serif);
  font-size: 12px;
  border: 1px solid currentColor;
  border-radius: 3px;
  padding: 0 5px;
  margin-left: 4px;
  opacity: 0.6;
}

/* slider */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 10px 0 0;
  background: transparent;
  cursor: pointer;
}
input[type="range"]::-webkit-slider-runnable-track { height: 1px; background: var(--ink); }
input[type="range"]::-moz-range-track { height: 1px; background: var(--ink); }
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -9.5px;
  border-radius: 50%;
  background: var(--ink);
  border: 4px solid var(--page);
  box-shadow: 0 0 0 1px var(--ink);
}
input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ink);
  border: 4px solid var(--page);
  box-shadow: 0 0 0 1px var(--ink);
}
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 1px var(--ink), 0 0 0 5px rgba(27, 25, 22, 0.15); }

/* buttons */
button {
  font: inherit;
  color: var(--ink);
  background: none;
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 9px 18px;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, opacity 0.15s;
}
button:hover:not(:disabled) { background: var(--ink); color: var(--page); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.3; cursor: default; }

.grid-control { display: flex; flex-direction: column; align-items: stretch; gap: 14px; border-top: 1px solid var(--line); padding-top: 22px; }
.grid-control .text-button { align-self: flex-start; margin-top: -4px; font-size: 15px; }

.toggle-row { display: flex; align-items: center; gap: 10px; }

/* petal range for Randomize, shown while petals are unlocked; indented to line up with the toggle's label */
.range-row { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; padding-left: 48px; margin-top: -4px; color: var(--muted); font-size: 15px; }
.range-row[hidden] { display: none; }
.range-row input {
  width: 1.8em;
  font: inherit;
  font-size: 16px;
  font-variant-numeric: lining-nums tabular-nums;
  text-align: center;
  color: var(--ink);
  background: none;
  border: 0;
  border-bottom: 1px solid var(--ink);
  border-radius: 0;
  padding: 1px 0;
  -moz-appearance: textfield;
}
.range-row input::-webkit-inner-spin-button, .range-row input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.range-row input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.range-row .text-button { font-size: 15px; margin: 0 0 0 4px; align-self: center; }

/* keyboard shortcuts sit at the right end of their row */
.keys { margin-left: auto; display: inline-flex; gap: 4px; white-space: nowrap; }
.keys kbd { margin-left: 0; }
.hint-row { display: flex; align-items: flex-start; gap: 14px; margin-top: 8px; }
.hint-row .hint { margin: 0; }
.hint-row .keys { padding-top: 2px; }

/* info button with a tooltip (hover, focus, or tap) */
.info { position: relative; display: inline-flex; }
.info-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border-radius: 50%;
  font-size: 15px;
  font-style: italic;
  line-height: 1;
}
.tip {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 10px);
  width: max-content;
  max-width: 230px;
  padding: 8px 11px;
  border-radius: 6px;
  background: var(--ink);
  color: var(--page);
  font-size: 15px;
  line-height: 1.35;
  opacity: 0;
  transform: translate(-50%, 4px);
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 3;
}
.tip::after { /* little pointer toward the button */
  content: "";
  position: absolute;
  left: calc(50% - 5px);
  top: 100%;
  border: 5px solid transparent;
  border-top-color: var(--ink);
}
.info:hover .tip, .info:focus-within .tip, .info.open .tip { opacity: 1; transform: translate(-50%, 0); }
.actions { display: flex; gap: 10px; }
.primary { flex: 1; background: var(--ink); color: var(--page); font-size: 18px; padding: 12px 18px; }
.primary:hover:not(:disabled) { background: #000; }
.primary kbd { opacity: 0.55; }

/* toggle */
.toggle { display: flex; align-items: center; gap: 12px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  position: relative;
  width: 36px;
  height: 20px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  transition: background-color 0.2s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--ink);
  transition: transform 0.2s, background-color 0.2s;
}
.toggle input:checked + .switch { background: var(--ink); }
.toggle input:checked + .switch::after { transform: translateX(16px); background: var(--page); }
.toggle input:focus-visible + .switch { outline: 2px solid var(--accent); outline-offset: 2px; }

/* recipe */
.recipe { border-top: 1px solid var(--line); padding-top: 22px; }
dl { margin: 0; display: grid; grid-template-columns: 96px 1fr; gap: 8px 14px; }
dt { color: var(--muted); font-size: 14px; padding-top: 2px; }
dd { margin: 0; font-size: 16px; }
.palette { display: flex; align-items: center; gap: 10px; }
#swatches { display: inline-flex; }
#swatches i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  margin-right: -3px;
  box-shadow: 0 0 0 1.5px var(--page);
}

.export { display: flex; align-items: center; gap: 8px; }
.export span { margin-right: auto; color: var(--muted); }
.export button { padding: 5px 14px; font-size: 15px; }

/* draggable rings in the grid */
.tile .ring-hits circle { cursor: grab; touch-action: none; }
body.dragging-ring, body.dragging-ring .tile .ring-hits circle { cursor: grabbing; user-select: none; }

.text-button {
  border: 0;
  padding: 0;
  margin-left: 6px;
  font-size: inherit;
  color: var(--ink);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.text-button:hover:not(:disabled) { background: none; color: var(--ink); }

/* ---------- Translucent (butterfly): a quieter, atmospheric frame ---------- */
body[data-style="butterfly"] { --page: #f7f5f3; --line: #e3ddd8; }
body[data-style="butterfly"] .tile-wrap::before { display: none; }
body[data-style="butterfly"] .tile { box-shadow: 0 24px 60px -34px rgba(40, 30, 40, 0.35); }

/* ---------- Playful (paper): the paper tile is the whole composition ---------- */
body[data-style="paper"] .tile-wrap::before { display: none; }
body[data-style="paper"] .tile { box-shadow: 0 2px 4px rgba(40, 30, 20, 0.08), 0 20px 40px -26px rgba(40, 30, 20, 0.4); }

/* ---------- Painterly (paint): heavy filters, so fade the whole tile once ---------- */
body[data-style="paint"] .tile-wrap::before { display: none; }
body[data-style="paint"] .tile { box-shadow: 0 2px 4px rgba(20, 30, 20, 0.12), 0 24px 48px -28px rgba(20, 40, 20, 0.5); }

/* ---------- All style overview: every direction in a 2×2 grid ---------- */
body[data-view="all"] .app { display: none; }
body:not([data-view="all"]) .overview { display: none; }

.overview {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 36px 24px 48px;
  min-height: calc(100vh - var(--nav-h));
}

/* 2×2, sized so both rows and the buttons fit the window height */
.ov-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 28px;
  width: min(100%, 1100px, max(480px, calc(100vh - var(--nav-h) - 165px)));
}
@media (max-width: 640px) {
  .ov-grid { grid-template-columns: 1fr; width: 100%; }
}

.ov-card { position: relative; }
.ov-tile {
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  overflow: hidden;
  transition: transform 0.2s ease;
}
.ov-tile:hover:not(:disabled) { background: none; transform: translateY(-3px); }
.ov-tile svg { display: block; width: 100%; height: 100%; }

/* opens the card's style in its own tab */
.ov-open {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(251, 247, 241, 0.92);
  color: var(--ink);
  font-size: 16px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, background-color 0.15s, color 0.15s;
}
.ov-card:hover .ov-open, .ov-open:focus-visible { opacity: 1; }
@media (hover: none) { .ov-open { opacity: 1; } } /* touch: always visible */
.ov-open:hover:not(:disabled) { background: var(--ink); color: var(--page); }

/* the style name sits inside the card, bottom left, on a small paper label */
.ov-label {
  position: absolute;
  left: 12px;
  bottom: 12px;
  padding: 3px 10px 4px;
  border-radius: 999px;
  background: rgba(251, 247, 241, 0.92);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.3;
}
/* Randomize centred on the page, Back sitting just to its left */
.ov-actions { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; width: 100%; }
.ov-actions #ov-randomize { grid-column: 2; grid-row: 1; flex: none; min-width: 240px; }
.ov-actions #ov-back { grid-column: 1; grid-row: 1; justify-self: end; }

/* ---------- small screens ---------- */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .stage { padding: 40px 22px 16px; position: static; height: auto; }
  .specimen { width: min(560px, 100%); }
  .panel { border-left: 0; border-top: 1px solid var(--line); padding: 28px 16px 40px; }
  .topnav { gap: 0; padding: 4px 8px; height: auto; min-height: var(--nav-h); }
  .brand { display: none; }
  .tabs { flex-wrap: wrap; overflow: visible; row-gap: 0; }
  .tab { padding: 10px 8px; font-size: 16px; }
  .tab[aria-selected="true"]::after { left: 8px; right: 8px; bottom: 4px; }
}
