/* social: icon row, letter sheet, letter box, prop box, visiting (owned by the social task) */
:root{
  --hair:color-mix(in srgb,var(--ink) 42%,transparent);
  --halo:0 0 2px var(--bg),0 0 7px var(--bg),0 0 16px var(--bg);
  --spring:cubic-bezier(.2,.8,.2,1);
  --btn-on:color-mix(in srgb,var(--ink) 15%,transparent);
  /* the icon row sits under the title; the sheet and the letter box open under the row */
  --row-top:calc(max(22px,env(safe-area-inset-top)) + clamp(30px,5vw,46px) + 12px);
  --left-top:calc(var(--row-top) + 44px + 18px);
}

/* ---------- one icon family: every round button draws the same 20px, 1.6 line ---------- */
.round svg{width:20px;height:20px;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round}

/* ---------- the icon row: own tree, random, popular | letter box ---------- */
.tabbar{
  position:absolute;z-index:3;pointer-events:auto;display:flex;align-items:center;gap:8px;
  top:var(--row-top);left:max(22px,env(safe-area-inset-left));
  opacity:0;transform:translateY(-6px);transition:opacity .8s ease .3s,transform .8s var(--spring) .3s;
}
.tabbar.ready{opacity:1;transform:none}
.tabs{display:flex;gap:8px}
.tabbar .round svg{opacity:.74;transition:opacity .25s ease,transform .6s var(--spring)}
.tabbar .round:hover svg{opacity:1}
.tabs .round[aria-selected="true"],.inbox-btn[aria-expanded="true"]{
  background:var(--btn-on);box-shadow:inset 0 0 0 1.2px color-mix(in srgb,var(--ink) 52%,transparent);
}
.tabs .round[aria-selected="true"] svg,.inbox-btn[aria-expanded="true"] svg{opacity:1}
.inbox-btn{margin-left:13px}
.inbox-btn[hidden]{display:none}
/* the thin gap before the letter box */
.inbox-btn::before{content:"";position:absolute;left:-11px;top:50%;width:1px;height:16px;margin-top:-8px;background:var(--ink);opacity:.24}
.inbox-dot{
  position:absolute;right:9px;top:10px;width:7px;height:7px;border-radius:50%;background:#e0483e;
  box-shadow:0 0 0 2px var(--bg);opacity:0;transform:scale(.3);transition:opacity .3s ease,transform .45s var(--spring);
}
.inbox-btn.unread .inbox-dot{opacity:1;transform:none}

/* short tips on hover / focus */
.tip{
  position:absolute;top:calc(100% + 6px);left:50%;z-index:1;white-space:nowrap;pointer-events:none;
  font-size:12px;letter-spacing:.02em;line-height:1.2;color:var(--ink);text-shadow:var(--halo);
  opacity:0;transform:translate(-50%,-3px);transition:opacity .2s ease,transform .3s var(--spring),color .9s ease;
}
.round:focus-visible .tip{opacity:.86;transform:translate(-50%,0)}
#top-actions .round::after,.nav::after{
  content:attr(aria-label);position:absolute;white-space:nowrap;pointer-events:none;
  font-size:12px;letter-spacing:.02em;line-height:1.2;color:var(--ink);text-shadow:var(--halo);
  opacity:0;transition:opacity .2s ease,transform .3s var(--spring),color .9s ease;
}
#top-actions .round::after{right:calc(100% + 10px);top:50%;transform:translate(3px,-50%)}
.nav::after{top:calc(100% + 6px);left:50%;transform:translate(-50%,-3px)}
#top-actions .round:focus-visible::after{opacity:.86;transform:translate(0,-50%)}
.nav:focus-visible::after{opacity:.86;transform:translate(-50%,0)}
@media (hover:hover){
  .round:hover .tip{opacity:.86;transform:translate(-50%,0)}
  #top-actions .round:hover::after{opacity:.86;transform:translate(0,-50%)}
  .nav:not(:disabled):hover::after{opacity:.86;transform:translate(-50%,0)}
}
/* no tip over an open menu or the colour rows */
#top-actions .round[aria-expanded="true"]::after{opacity:0 !important}

/* ---------- the letter box: a floating list on the left, no box ---------- */
.inbox{
  position:absolute;z-index:3;pointer-events:none;box-sizing:border-box;
  left:max(14px,env(safe-area-inset-left));top:var(--left-top);
  width:min(300px,calc(100vw - 28px));max-height:min(420px,calc(100% - var(--left-top) - 130px));
  overflow-x:hidden;overflow-y:auto;overscroll-behavior:contain;scrollbar-width:thin;padding:4px 8px 18px;
  opacity:0;transform:translateY(-8px);transition:opacity .3s ease,transform .45s var(--spring);
  -webkit-mask-image:linear-gradient(180deg,#000 calc(100% - 18px),transparent);
          mask-image:linear-gradient(180deg,#000 calc(100% - 18px),transparent);
}
.inbox.open{opacity:1;transform:none;pointer-events:auto}
/* no backing patch: the rows read through their own halo */
.inbox-row{
  display:flex;align-items:center;gap:10px;width:100%;min-height:44px;margin:0 0 2px;padding:2px 0;border:0;background:none;
  cursor:pointer;color:var(--ink);font:inherit;font-size:14px;line-height:1.45;text-align:left;text-shadow:var(--halo),var(--halo);
  transition:opacity .25s ease,color .9s ease,transform .3s var(--spring);
}
.inbox-row img{flex:0 0 auto;width:30px;height:32px;pointer-events:none;filter:drop-shadow(0 3px 4px rgba(0,0,0,.18))}
.inbox-text{flex:1;min-width:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.inbox-row.read{opacity:.5}
.inbox-row:hover{opacity:1;transform:translateX(3px)}
.inbox-row:focus-visible{outline:1px solid var(--ink);outline-offset:2px;border-radius:2px}
.inbox-empty{margin:6px 0;font-size:13px;opacity:.6;text-shadow:var(--halo)}

/* ---------- the letter sheet: the one paper thing on the page ---------- */
.sheet{
  --paper-ink:#33291b;--paper-soft:rgba(51,41,27,.58);--lh:30px;
  --hand:"Gowun Batang","Nanum Myeongjo","Noto Serif KR",Batang,"AppleMyungjo","Instrument Serif",Georgia,serif;
  position:absolute;z-index:2;pointer-events:auto;box-sizing:border-box;
  left:max(22px,env(safe-area-inset-left));top:var(--left-top);
  width:304px;max-height:calc(100% - var(--left-top) - 24px);
  display:flex;flex-direction:column;color:var(--paper-ink);
  filter:drop-shadow(0 14px 18px rgba(48,32,12,.2));
  -webkit-user-select:text;user-select:text;
}
.sheet[hidden]{display:none}
:root[data-mode="night"] .sheet{filter:drop-shadow(0 16px 22px rgba(0,0,0,.42)) brightness(.95)}

/* three panels folded like a letter; they swing open on top of each other */
.sheet-fold{position:absolute;inset:0;perspective:1100px;pointer-events:none}
.fp{position:absolute;left:0;right:0;transform-style:preserve-3d;transform-origin:50% 0;backface-visibility:visible}
.fp1{top:0;height:33.34%;border-radius:3px 3px 0 0}
.fp2,.fp3{top:calc(100% - .5px);height:calc(100% + .5px);box-shadow:inset 0 1px 0 rgba(90,60,25,.07)}
.fp3{border-radius:0 0 3px 3px}
.sh{position:absolute;inset:0;pointer-events:none;opacity:0;border-radius:inherit;
  background:linear-gradient(180deg,rgba(60,40,14,.3),rgba(60,40,14,.06))}

/* a) warm cream stationery; the rules sit under each written line */
.sheet[data-paper="a"] .fp{
  background-color:#f8f1de;
  background-image:linear-gradient(170deg,rgba(255,255,255,.45),rgba(255,255,255,0) 60%);
}
.sheet[data-paper="a"] .sheet-text,.sheet[data-paper="a"] .sheet-input{
  background-image:repeating-linear-gradient(180deg,transparent 0 calc(var(--lh) - 1px),rgba(150,110,56,.22) calc(var(--lh) - 1px) var(--lh));
  background-position:0 -4px;background-attachment:local;
}

/* b) white card with a thin red-and-green edge stripe */
.sheet[data-paper="b"]{--paper-ink:#24271f;--paper-soft:rgba(36,39,31,.56)}
.sheet[data-paper="b"] .fp{
  --stripe-v:repeating-linear-gradient(180deg,#c23a37 0 7px,transparent 7px 10px,#2e7a4f 10px 17px,transparent 17px 20px);
  --stripe-h:repeating-linear-gradient(90deg,#c23a37 0 7px,transparent 7px 10px,#2e7a4f 10px 17px,transparent 17px 20px);
  background-color:#fffdf8;
  background-image:var(--stripe-v),var(--stripe-v);
  background-repeat:no-repeat;background-size:3px 100%,3px 100%;
  background-position:9px 0,calc(100% - 9px) 0;
}
.sheet[data-paper="b"] .fp1{
  background-image:var(--stripe-h),var(--stripe-v),var(--stripe-v);
  background-size:calc(100% - 18px) 3px,3px calc(100% - 9px),3px calc(100% - 9px);
  background-position:9px 9px,9px 9px,calc(100% - 9px) 9px;
}
.sheet[data-paper="b"] .fp3{
  background-image:var(--stripe-h),var(--stripe-v),var(--stripe-v);
  background-size:calc(100% - 18px) 3px,3px calc(100% - 9px),3px calc(100% - 9px);
  background-position:9px calc(100% - 9px),9px 0,calc(100% - 9px) 0;
}

/* c) kraft paper with a wax-seal dot */
.sheet[data-paper="c"]{--paper-ink:#2a1c0d;--paper-soft:rgba(42,28,13,.62)}
.sheet[data-paper="c"] .fp{
  background-color:#caa676;
  background-image:radial-gradient(circle at 30% 40%,rgba(92,60,24,.16) 0 .8px,transparent 1.4px),
                   radial-gradient(circle at 70% 60%,rgba(255,240,212,.22) 0 .8px,transparent 1.5px),
                   linear-gradient(100deg,rgba(255,255,255,.1),rgba(0,0,0,.05));
  background-size:7px 9px,11px 13px,100% 100%;
}

.sheet-in{position:relative;display:flex;flex-direction:column;min-height:0;padding:20px 24px 12px}
.sheet[data-paper="b"] .sheet-in{padding:24px 28px 16px}
.sheet-head{display:flex;align-items:center;gap:10px;height:28px;padding-right:30px;flex:0 0 auto}
.sheet-title{
  margin:0;font:inherit;font-size:12.5px;font-weight:600;letter-spacing:.06em;color:var(--paper-soft);white-space:nowrap;
}
.sheet-title::after{content:"";display:inline-block;width:22px;height:1px;margin-left:10px;vertical-align:middle;background:currentColor;opacity:.55}
/* a letter carries its ornament like a seal */
.seal{display:none;flex:0 0 auto;width:30px;height:30px;place-items:center;border-radius:50%}
.seal.thumb{display:grid}
.seal img{width:30px;height:32px;filter:drop-shadow(0 2px 3px rgba(40,24,8,.28));pointer-events:none}
.seal:not(.thumb) img{display:none}
.sheet[data-paper="c"] .seal{
  display:grid;width:30px;height:30px;
  background:radial-gradient(circle at 36% 32%,#d35e55 0,#a5292c 46%,#7c171b 100%);
  box-shadow:inset 0 0 0 3px rgba(120,20,24,.55),inset 0 0 0 4px rgba(255,170,150,.18),0 2px 3px rgba(60,20,10,.3);
}
.sheet[data-paper="c"] .seal img{width:22px;height:24px}

.sheet-body{overflow-y:auto;min-height:0;flex:0 1 auto;scrollbar-width:thin}
.sheet-text{
  margin:10px 0 0;font-family:var(--hand);font-size:17.5px;line-height:var(--lh);letter-spacing:.005em;
  word-break:keep-all;overflow-wrap:anywhere;white-space:pre-wrap;
}
.sheet[data-paper] .sheet-text.quiet{color:var(--paper-soft);font-size:15px;background-image:none}
.sheet-input{
  display:block;width:100%;box-sizing:border-box;margin:10px 0 0;padding:0;border:0;border-radius:0;outline:0;resize:none;
  background:transparent;color:var(--paper-ink);caret-color:var(--paper-ink);
  font-family:var(--hand);font-size:17.5px;line-height:var(--lh);-webkit-user-select:text;user-select:text;
}
.sheet-input.story-input{height:calc(3 * var(--lh))}
.sheet-input.letter-input{height:calc(2 * var(--lh))}
.sheet:not([data-paper="a"]) .sheet-input{border-bottom:1px solid rgba(60,44,24,.28);background-image:none}
.sheet-input::placeholder{color:var(--paper-ink);opacity:.42}
.sheet-note{margin:6px 0 0;font-size:12px;line-height:1.4;color:var(--paper-soft);word-break:keep-all}
.sheet-act{display:flex;gap:26px;margin-top:6px;flex:0 0 auto}
.sheet-act[hidden]{display:none}
.sheet .tbtn{color:var(--paper-ink);text-shadow:none;font-size:13.5px}
.sheet .tbtn:focus-visible{outline-color:var(--paper-ink)}
.sheet-x{
  position:absolute;top:8px;right:8px;width:44px;height:44px;border:0;border-radius:50%;padding:0;margin:0;
  display:grid;place-items:center;background:none;cursor:pointer;color:var(--paper-soft);
  transition:color .2s ease,background-color .2s ease;
}
.sheet[data-paper="b"] .sheet-x{top:12px;right:12px}
.sheet-x[hidden]{display:none}
.sheet-x svg{width:16px;height:16px;stroke-width:1.6}
.sheet-x:hover{color:var(--paper-ink);background:rgba(60,44,24,.07)}
.sheet-x:focus-visible{outline:1.5px solid var(--paper-ink);outline-offset:-4px}

/* narrow: the sheet unfolds from the top under the icon row, across the width, clear of the bottom tray */
@media (max-width:899px){
  /* it starts under the star (social.js keeps --star-clear on the star's lower edge), so the star stays in
     sight and a press on it folds the sheet */
  .sheet{
    --sheet-top:max(var(--left-top),var(--star-clear,0px));
    left:max(16px,env(safe-area-inset-left));right:calc(max(16px,env(safe-area-inset-right)) + 56px);width:auto;
    top:var(--sheet-top);max-height:calc(100% - var(--sheet-top) - 118px);
  }
  /* visiting, the right-hand column ends above the sheet: it may take the whole width */
  :root[data-view="visit"] .sheet{right:max(16px,env(safe-area-inset-right))}
  .sheet-in{padding:18px 20px 10px}
  .sheet{--lh:28px}
  .sheet-text,.sheet-input{font-size:16.5px}
  /* 16px fields: phones do not zoom the page when they take focus */
  .sheet-input{font-size:16.5px}
  .inbox-open .star-hit,:root:has(.panel.open) .star-hit{pointer-events:none}
}

.tbtn{
  /* at least 40x40 to tap; negative margins keep the words where they were */
  border:0;background:none;margin:0 -10px;padding:4px 10px;min-height:44px;min-width:44px;cursor:pointer;
  font:inherit;font-size:13px;letter-spacing:.02em;color:var(--ink);opacity:.92;text-shadow:var(--halo);
  text-decoration:underline;text-decoration-color:transparent;text-underline-offset:4px;
  transition:opacity .2s ease,text-decoration-color .2s ease;
}
.tbtn:hover{opacity:1;text-decoration-color:currentColor}
.tbtn:focus-visible{outline:1px solid var(--ink);outline-offset:3px;border-radius:2px}

/* ---------- the star is a button ---------- */
.star-hit{
  position:absolute;z-index:1;left:0;top:0;width:52px;height:52px;border:0;border-radius:50%;padding:0;margin:0;
  background:none;cursor:pointer;pointer-events:auto;-webkit-tap-highlight-color:transparent;
}
.star-hit::after{
  content:"";position:absolute;inset:-6px;border-radius:50%;
  background:radial-gradient(closest-side,rgba(255,226,150,.38),rgba(255,226,150,0));
  opacity:0;transform:scale(.7);transition:opacity .35s ease,transform .5s var(--spring);
}
.star-hit:hover::after,.star-hit:focus-visible::after{opacity:1;transform:none}
.star-hit:focus-visible{outline:1px solid var(--ink);outline-offset:2px}

/* ---------- visiting: heart, arrows ---------- */
.heart svg path{transition:fill .25s ease}
.heart[aria-pressed="true"] svg path{fill:currentColor}
.heart .burst{position:absolute;left:50%;top:50%;width:0;height:0;pointer-events:none}
.heart .burst::before{
  content:"";position:absolute;left:-2px;top:-2px;width:4px;height:4px;border-radius:50%;opacity:0;
  box-shadow:0 -22px 0 currentColor,15.6px -15.6px 0 currentColor,22px 0 0 currentColor,15.6px 15.6px 0 currentColor,
             0 22px 0 currentColor,-15.6px 15.6px 0 currentColor,-22px 0 0 currentColor,-15.6px -15.6px 0 currentColor;
}
.heart.pop svg{animation:heart-pop .5s var(--spring)}
.heart.pop .burst::before{animation:heart-burst .6s ease-out}
@keyframes heart-pop{0%{transform:scale(1)}35%{transform:scale(1.32)}100%{transform:scale(1)}}
@keyframes heart-burst{0%{opacity:.9;transform:scale(.35)}100%{opacity:0;transform:scale(1.35)}}

/* the arrows sit beside the tree (css/visit.css, placed by js/visit.js) */
.nav:disabled{opacity:.28;cursor:default}
.nav:disabled:active{transform:none}
.nav svg{transition:transform .35s var(--spring)}
.nav.next:not(:disabled):hover svg{transform:translateX(2px)}
.nav.prev:not(:disabled):hover svg{transform:translateX(-2px)}

/* ---------- prop box ---------- */
.tray button{position:relative}
.tray .lock{position:absolute;right:7px;top:7px;width:12px;height:12px;color:var(--ink);opacity:.7;pointer-events:none}
.tray button[data-premium]{cursor:default}
.tray button[data-premium] img{opacity:.62;filter:saturate(.6) drop-shadow(0 7px 8px rgba(0,0,0,.14))}
.tray button[data-premium]:hover img{transform:none}
.tray.done button img{opacity:.26;filter:saturate(.4)}
.tray.done button{cursor:default}
.tray.done button:hover img{transform:none}
.tray-note{
  position:fixed;z-index:2;margin:0;pointer-events:none;color:var(--ink);font-size:13px;letter-spacing:.01em;
  left:0;right:0;bottom:calc(max(12px,env(safe-area-inset-bottom)) + 82px);text-align:center;
  opacity:0;transform:translateY(4px);text-shadow:var(--halo);transition:opacity .5s ease,transform .5s var(--spring),color .9s ease;
}
.tray-note.show{opacity:.7;transform:none}
/* phone: the legal line takes the very bottom, so the note steps up with the tray */
@media (max-width:899px){.tray-note{bottom:calc(max(12px,env(safe-area-inset-bottom)) + 94px)}}
/* a hint line uses the same place: the note steps aside while it shows */
:root:has(.hint.show) .tray-note.show{opacity:0}

/* narrow: the bottom row, premium items at the end after a hairline */
.tray .grp{display:contents}
.tray .lab{display:none}
.tray .sep{flex:0 0 1px;align-self:center;height:30px;margin:0 10px;background:var(--ink);opacity:.22}

/* the colour rows open under the whole button column */
.panel{top:calc(var(--box-top,134px) - 10px)}

/* wide: a column on the right under the round buttons */
@media (min-width:900px){
  .tray{
    left:auto;right:max(16px,env(safe-area-inset-right));top:var(--box-top,160px);
    /* --tray-cut (tray.js): at rest the rows above the edge are whole and the next row shows its top (--tray-peek),
       which melts into the fade: the sign that more is below */
    --tray-peek:38px;
    bottom:calc(max(14px,env(safe-area-inset-bottom)) + var(--tray-cut,0px));
    width:128px;display:block;overflow-x:hidden;overflow-y:auto;padding:2px 0 44px;touch-action:pan-y;
    scroll-snap-type:y proximity;scroll-padding-top:2px;
    -webkit-mask-image:linear-gradient(180deg,#000 calc(100% - var(--tray-peek)),rgba(0,0,0,.85) calc(100% - var(--tray-peek)*.5),transparent);
            mask-image:linear-gradient(180deg,#000 calc(100% - var(--tray-peek)),rgba(0,0,0,.85) calc(100% - var(--tray-peek)*.5),transparent);
    transform:translateX(16px);transition:opacity .8s ease .4s,transform .8s var(--spring) .4s,top .5s var(--spring);
  }
  .tray.ready{transform:none}
  .tray::before,.tray::after{display:none}
  .tray .grp{display:grid;grid-template-columns:repeat(2,56px);gap:2px 12px;justify-content:end;margin-bottom:20px}
  .tray .lab{grid-column:1/-1;display:flex;align-items:center;gap:8px;margin:0 2px 4px;font-size:11px;letter-spacing:.04em;opacity:.78;color:var(--ink);text-shadow:var(--halo),var(--halo)}
  .tray .lab::before{content:"";flex:1;height:1px;background:currentColor;opacity:.5}
  .tray .sep{display:none}
  .tray button{width:56px;height:60px;touch-action:pan-y}
  /* a scroll comes to rest on a whole row (or a group's label) at the top */
  .tray .lab,.tray button{scroll-snap-align:start}
  .tray.done{top:calc(var(--box-top,160px) + 44px)}
  .tray-note{left:auto;bottom:auto;right:max(16px,env(safe-area-inset-right));top:var(--box-top,160px);width:auto;white-space:nowrap;text-align:right;line-height:1.45}
  /* a column that does not scroll: a touch drag in any direction carries the item */
  .tray.noscroll,.tray.noscroll button{touch-action:none}
  .tray.noscroll{padding-bottom:0;-webkit-mask-image:none;mask-image:none}
  /* colour rows open to the LEFT of the round buttons, clear of the prop box */
  .panel{top:calc(max(18px,env(safe-area-inset-top)) + 2px);right:calc(max(16px,env(safe-area-inset-right)) + 60px)}
  /* the account (and sound) buttons sit in the top row just left of the column: the rows start under them */
  :root:has(#account-actions > .round:not([hidden])) .panel{top:calc(max(18px,env(safe-area-inset-top)) + 58px)}
}

@media (prefers-reduced-motion:reduce){
  .inbox,.inbox-row,.inbox-dot,.tip,#top-actions .round::after,.nav::after,
  .tabbar,.tabbar .round svg,.star-hit::after,.tray-note,.nav svg,.tray,.tray img,.sheet-x{transition:none}
  .tray,.tray.ready,.tabbar{transform:none}
  .heart.pop svg,.heart.pop .burst::before{animation:none}
}
