:root {
  --mat: #2c5a49;
  --mat-dark: #224a3c;
  --line: rgba(236, 246, 225, .09);
  --line-big: rgba(236, 246, 225, .2);
  --paper: #f7f3ea;
  --ink: #141414;
  --hot: #ff6a3d;
  --sun: #ffd84a;
  --r: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--mat); color: var(--ink); }
body { font: 16px/1.3 "Bricolage Grotesque", system-ui, sans-serif; overscroll-behavior: none; }
button, input, a { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }
.ico { width: 1.25em; height: 1.25em; display: block; flex: none; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }

/* ---------- cutting mat ---------- */
.mat {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    linear-gradient(var(--line-big) 1px, transparent 1px) 0 0 / 100px 100px,
    linear-gradient(90deg, var(--line-big) 1px, transparent 1px) 0 0 / 100px 100px,
    linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / 20px 20px,
    radial-gradient(120% 90% at 50% 40%, var(--mat) 0%, var(--mat-dark) 100%);
}
.mat::before, .mat::after { /* 45° guide lines, like a real cutting mat */
  content: ""; position: absolute; left: 50%; top: 50%; width: 220vmax; height: 1px; background: var(--line-big);
  transform: translate(-50%, -50%) rotate(45deg);
}
.mat::after { transform: translate(-50%, -50%) rotate(-45deg); }
.ruler { position: absolute; }
.ruler.top { left: 0; right: 0; top: 0; height: 12px;
  background: repeating-linear-gradient(90deg, var(--line-big) 0 1px, transparent 1px 10px), repeating-linear-gradient(90deg, rgba(236,246,225,.35) 0 1px, transparent 1px 100px);
  -webkit-mask: linear-gradient(#000 0 0) top / 100% 7px no-repeat, linear-gradient(#000 0 0) top / 100% 12px no-repeat; }
.ruler.left { top: 0; bottom: 0; left: 0; width: 12px;
  background: repeating-linear-gradient(0deg, var(--line-big) 0 1px, transparent 1px 10px); width: 7px; }

/* ---------- logo ---------- */
.logo { margin: 0; font-weight: 800; font-stretch: 80%; letter-spacing: -.035em; color: var(--paper); line-height: .9; }
.logo i { font-family: "Instrument Serif", serif; font-weight: 400; font-style: italic; letter-spacing: -.01em; color: var(--sun); }
.logo.small { font-size: 26px; }

/* ---------- buttons ---------- */
.big {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 60px; border-radius: 999px;
  background: var(--hot); color: var(--ink); font-weight: 800; font-size: 20px; letter-spacing: -.01em;
  box-shadow: 0 5px 0 #141414; transition: transform .12s, box-shadow .12s;
}
.big .ico { width: 24px; height: 24px; }
.big:active { transform: translateY(4px); box-shadow: 0 1px 0 #141414; }

/* ---------- intro ---------- */
.intro { position: fixed; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: flex-end;
  padding: 24px 24px calc(56px + var(--safe-b)); transition: opacity .5s, transform .5s; }
.intro.out { opacity: 0; transform: scale(1.04); pointer-events: none; }
.fan { position: absolute; left: 50%; top: 50%; width: 0; height: 0; }
.fan .chip { position: absolute; left: 0; top: 0; width: 118px; height: 300px; margin-left: -59px; margin-top: -276px; flex-direction: column-reverse;
  transform-origin: 50% 92%; transform: rotate(0deg); animation: fanOut 1.4s cubic-bezier(.2, .9, .2, 1.15) forwards; }
.fan .chip .sw { height: 62%; }
.fan .chip .ph, .fan .chip .stamp, .fan .chip .tape { display: none; }
.fan .chip .lbl { padding: 9px 8px 0; }
.fan .chip .h { font-size: 12px; }
.fan .chip .code { font-size: 8px; }
.fan .pin { position: absolute; left: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%; background: #d8d2c4; border: 2px solid var(--ink); z-index: 20; }
@keyframes fanOut { from { transform: rotate(0deg); } to { transform: rotate(var(--rot)); } }
.intro.out .fan .chip { transition: transform .45s ease-in; transform: rotate(0deg) !important; animation: none; }
.intro-copy { position: relative; width: 100%; max-width: 420px; text-align: center; opacity: 0; animation: rise .8s .9s cubic-bezier(.2, .8, .2, 1) forwards; }
.intro .logo { font-size: clamp(56px, 17vw, 96px); text-shadow: 0 4px 0 rgba(0, 0, 0, .25); }
.tag { margin: 12px 0 22px; color: var(--paper); font-size: 17px; opacity: .9; }
@keyframes rise { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
.legal-link { position: absolute; left: 16px; bottom: calc(14px + var(--safe-b)); font-size: 11px; color: var(--paper); opacity: .4; text-decoration: none; }
.legal-link.in { position: static; display: inline-block; margin-top: 10px; color: var(--ink); }

/* ---------- app layout: one screen, no scroll ---------- */
.app { position: relative; z-index: 1; height: 100vh; height: 100svh; max-width: 480px; margin: 0 auto; display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto; gap: 12px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px calc(58px + var(--safe-b)); }
.top { display: flex; align-items: center; justify-content: space-between; height: 40px; }
.saved-btn { display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 14px; border-radius: 999px; background: var(--paper); font-weight: 700; }
.saved-btn.bump { animation: bump .45s; }
@keyframes bump { 40% { transform: scale(1.18) rotate(-4deg); } }

/* ---------- the swatch chip ---------- */
.stage { position: relative; display: flex; align-items: center; justify-content: center; min-height: 0; touch-action: pan-y; }
.deck { position: relative; width: var(--cw, 260px); height: var(--ch, 360px); }
.chip { position: absolute; inset: 0; border-radius: 10px; background: #fff; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 1px 0 rgba(0,0,0,.08), 0 14px 30px rgba(0, 0, 0, .28); user-select: none; -webkit-user-select: none; }
.chip .sw { position: relative; height: 58%; background: var(--c); }
.chip .lbl { flex: 1; display: flex; flex-direction: column; padding: 14px 16px 0; min-width: 0; }
.chip .code { font-family: "Space Mono", monospace; font-size: 10px; letter-spacing: 0; display: flex; justify-content: space-between; gap: 6px; white-space: nowrap; }
.chip .code b { font-family: "Bricolage Grotesque", sans-serif; font-weight: 800; letter-spacing: .05em; }
.chip .code.tight b { display: none; }
.chip .h.wrap { white-space: normal; overflow-wrap: anywhere; }
.chip .h.wrap + .ph { -webkit-line-clamp: 1; }
.chip .h { margin-top: 6px; font-weight: 800; font-size: 30px; letter-spacing: -.03em; white-space: nowrap; line-height: 1.05; }
.chip .h span { opacity: .35; font-weight: 600; }
.chip .ph { margin-top: 6px; font-family: "Instrument Serif", serif; font-style: italic; font-size: 16px; line-height: 1.15; color: #555;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chip .ph em { font-style: italic; color: #999; }
.chip .tape { position: absolute; top: -8px; left: 50%; width: 92px; height: 26px; margin-left: -46px; transform: rotate(-3deg);
  background: rgba(247, 236, 205, .78); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.chip .stamp { position: absolute; right: 12px; bottom: 12px; font-family: "Space Mono", monospace; font-size: 11px; font-weight: 700;
  padding: 3px 7px; border: 1.5px solid currentColor; border-radius: 999px; color: rgba(0,0,0,.6); background: rgba(255,255,255,.35); }
.chip .stamp.dark { color: rgba(255,255,255,.85); background: rgba(0,0,0,.12); }
.chip.back1 .lbl, .chip.back2 .lbl, .chip.back1 .stamp, .chip.back2 .stamp { visibility: hidden; }
.chip.back1 { transform: translate(-14px, 8px) rotate(-6deg); filter: brightness(.88); }
.chip.back2 { transform: translate(14px, 14px) rotate(5deg); filter: brightness(.78); }
.chip.front { transition: transform .5s cubic-bezier(.2, .9, .25, 1.2); cursor: grab; }
.chip.enter { transform: translateX(120%) rotate(18deg); }
.chip.enter-l { transform: translateX(-120%) rotate(-18deg); }
.chip.leave { transition: transform .45s ease-in, opacity .45s; transform: translateX(-130%) rotate(-16deg); opacity: 0; }
.chip.leave-r { transition: transform .45s ease-in, opacity .45s; transform: translateX(130%) rotate(16deg); opacity: 0; }
.chip.back1, .chip.back2 { transition: transform .5s, filter .5s; }
.chip.pop { animation: pop .35s; }
@keyframes pop { 50% { transform: scale(1.04) rotate(-1.5deg); } }

.nav { position: absolute; top: 50%; z-index: 3; width: 40px; height: 40px; margin-top: -20px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(247, 243, 234, .14); color: var(--paper); transition: opacity .2s; }
.nav.prev { left: -4px; } .nav.next { right: -4px; }
.nav:disabled { opacity: 0; pointer-events: none; }

/* ---------- action row ---------- */
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.act { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; height: 54px; border-radius: 14px;
  background: var(--paper); font-size: 13px; font-weight: 700; text-decoration: none; transition: transform .1s; white-space: nowrap; }
.act .ico { width: 21px; height: 21px; }
.act:active { transform: scale(.95); }
.act.on { background: var(--sun); }
.act.on .ico path { fill: currentColor; }

/* ---------- controls panel ---------- */
.panel { background: var(--paper); border-radius: var(--r); padding: 10px; display: grid; gap: 8px; }
.styles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.sty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; height: 54px;
  border-radius: 12px; border: 2px solid rgba(20,20,20,.12); transition: background .15s, border-color .15s; }
.sty .ico { width: 22px; height: 22px; }
.sty small { font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.sty[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: rgba(20,20,20,.07); border-radius: 12px; padding: 3px; height: 40px; }
.seg button { border-radius: 9px; font-weight: 700; font-size: 13px; font-family: "Space Mono", monospace; }
.seg button[aria-checked="true"] { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.18); }
.word { display: flex; align-items: center; gap: 8px; height: 42px; padding: 0 6px 0 12px; border-radius: 12px; background: #fff; border: 2px solid rgba(20,20,20,.12); }
.word:focus-within { border-color: var(--ink); }
.word .ico { width: 18px; height: 18px; opacity: .55; }
.word input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; font-size: 16px; font-weight: 600; }
.word input::placeholder { color: rgba(20,20,20,.4); font-weight: 500; }
.x { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; }
.x .ico { opacity: .7; }

/* ---------- saved sheet ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; background: rgba(10, 20, 16, .55); display: flex; align-items: flex-end; justify-content: center; animation: fade .25s; }
.sheet { width: 100%; max-width: 480px; max-height: 78svh; display: flex; flex-direction: column; background: var(--paper); border-radius: 22px 22px 0 0;
  padding: 16px 16px calc(18px + var(--safe-b)); animation: up .3s cubic-bezier(.2, .9, .3, 1); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet h2 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.saved-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0; }
.saved-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid rgba(20,20,20,.08); }
.saved-list .dot { width: 26px; height: 34px; border-radius: 5px; flex: none; background: var(--c); box-shadow: inset 0 -9px 0 #fff, 0 0 0 1px rgba(0,0,0,.1); }
.saved-list .nm { flex: 1; min-width: 0; font-weight: 800; font-size: 15px; line-height: 1.2; overflow-wrap: anywhere; }
.saved-list .mini { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: #fff; text-decoration: none; }
.empty { opacity: .6; display: flex; align-items: center; gap: 6px; margin: 14px 0; }
.empty .ico { display: inline-block; width: 1.1em; height: 1.1em; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }

/* ---------- toast ---------- */
.toast { position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top, 0px)); z-index: 30; transform: translate(-50%, -20px); opacity: 0;
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 999px; font-weight: 700; font-size: 14px;
  transition: opacity .25s, transform .25s; pointer-events: none; max-width: calc(100vw - 32px); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- short phones ---------- */
@media (max-height: 700px) {
  .app { gap: 9px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
  .top { height: 34px; }
  .act { height: 48px; flex-direction: row; gap: 5px; }
  .actions { gap: 6px; }
  .act .ico { width: 18px; height: 18px; }
  .sty { height: 48px; gap: 2px; }
  .sty .ico { width: 20px; height: 20px; }
  .seg { height: 36px; }
  .word { height: 38px; }
  .big { height: 54px; font-size: 18px; }
  .panel { gap: 6px; padding: 8px; }
}
@media (max-width: 360px) {
  .act { font-size: 12px; }
}
/* desktop: give the chip room to breathe */
@media (min-width: 900px) and (min-height: 760px) {
  .app { gap: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media (min-width: 700px) and (min-height: 780px) {
  .fan { transform: scale(1.35); }
}
