:root{
  --paper:#f8f5ee;--ink:#433b49;--muted:#64586b;--lilac:#e8dded;--lilac-deep:#746080;
  --line:#dcd4dc;--card:#fffdf8;--butter:#f2e9d6;--focus:#654878;
  --wallpaper-1:#e8dded;--wallpaper-2:#f2e9d6;
  color-scheme:light;font-family:'Noto Sans Thai',sans-serif;
}
*{box-sizing:border-box}
html{overflow-x:hidden}
body{
  margin:0;color:var(--ink);min-height:100svh;overflow-x:hidden;
  background:
    radial-gradient(1100px 560px at 12% -12%, var(--wallpaper-1), transparent 60%),
    radial-gradient(900px 520px at 105% -6%, var(--wallpaper-2), transparent 55%),
    var(--paper);
  background-attachment:fixed;
}
a{color:inherit;text-decoration:none}
.script{font-family:'Mali',cursive}
a:focus-visible{outline:3px solid var(--focus);outline-offset:4px}

.desktop{
  min-height:100svh;
  display:flex;flex-direction:column;
  padding:16px clamp(16px,4vw,48px) 32px;
}
.bar{
  /* A frosted panel rather than plain text on the wallpaper: the
     wallpaper (and later, maybe a custom photo) can be any color, so
     text sitting directly on it can't guarantee contrast. The blurred
     translucent backing guarantees it regardless of what's behind. */
  display:flex;flex-wrap:wrap;justify-content:space-between;align-items:center;
  gap:6px 16px;
  padding:11px 16px;margin-bottom:16px;
  background:#ffffffb3;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);
  border:1px solid #ffffff80;border-radius:14px;
  box-shadow:0 8px 24px -16px #433b4940;
}
.brand{font-size:15px;letter-spacing:.02em}
.brand span{color:var(--lilac-deep)}
.clock{font-size:13px;color:var(--muted);font-variant-numeric:tabular-nums;white-space:nowrap}

/* --- swipeable pages, iOS-style --- */
.pager{
  flex:1;display:flex;overflow-x:auto;scroll-snap-type:x mandatory;
  scroll-behavior:smooth;
  margin:0 clamp(-16px,-4vw,-48px);
  scrollbar-width:none;-ms-overflow-style:none;
}
.pager::-webkit-scrollbar{display:none}
.page{
  flex:0 0 100%;scroll-snap-align:start;
  padding:20px clamp(16px,4vw,48px) 4px;
  min-width:0;
}

.jiggle-done{
  display:block;width:fit-content;margin:0 0 14px auto;
  padding:7px 18px;border:none;border-radius:100px;
  background:var(--ink);color:var(--paper);font:inherit;font-size:13px;font-weight:600;
  cursor:pointer;
}
.jiggle-done[hidden]{display:none}

.widgets{
  display:flex;flex-direction:column;gap:12px;max-width:420px;
}
.widget{
  background:#ffffffb3;backdrop-filter:blur(10px);-webkit-backdrop-filter:blur(10px);
  border:1px solid #ffffff80;border-radius:18px;
  padding:16px 18px;
  box-shadow:0 8px 24px -14px #433b4940;
}
.widget-label{
  font-size:11px;letter-spacing:.1em;text-transform:uppercase;color:var(--muted);
  margin:0 0 10px;
}
.widget-stats{display:flex;gap:22px}
.widget-stat .num{
  display:block;font-family:Georgia,serif;font-size:28px;color:var(--lilac-deep);
  font-variant-numeric:tabular-nums;
}
.widget-stat .label{display:block;font-size:11.5px;color:var(--muted);margin-top:2px}
.widget-note-title{font-size:14px;font-weight:600;margin:0 0 4px}
.widget-note-body{
  font-size:13px;color:var(--muted);margin:0;
  display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;
}
.widget-empty{font-size:13px;color:var(--muted);margin:0}
.widget-globe-stage{position:relative;width:150px;height:150px;margin:6px auto 4px}
.widget-globe-stage canvas{position:absolute;inset:0;width:100%;height:100%}
.widget-globe-preview{
  position:absolute;right:-6px;bottom:-6px;width:44px;height:44px;
  border-radius:10px;object-fit:cover;border:2px solid var(--card);
  box-shadow:0 2px 8px #00000030;
}
.widget-globe-caption{font-size:11px;color:var(--muted);margin:0;text-align:center}
.widget-track{display:flex;align-items:center;gap:12px}
.widget-track img{width:44px;height:44px;border-radius:8px;object-fit:cover;flex-shrink:0}
.widget-track-info{min-width:0}
.widget-track-title{font-size:14px;font-weight:600;margin:0 0 2px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.widget-track-artist{font-size:12.5px;color:var(--muted);margin:0;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.widget-controls{display:flex;justify-content:center;gap:10px;margin-top:12px}
.widget-controls button{
  border:none;background:var(--paper);color:var(--ink);width:36px;height:36px;
  border-radius:100px;font-size:14px;cursor:pointer;display:grid;place-items:center;
}
.widget-controls button:hover{background:var(--lilac)}
.widget-controls button[data-action="play"],.widget-controls button[data-action="pause"]{
  background:var(--lilac-deep);color:#fff;width:40px;height:40px;
}

.grid{
  display:grid;
  grid-template-columns:repeat(auto-fill,minmax(72px,1fr));
  gap:18px 12px;
  max-width:640px;
}

@media(max-width:360px){
  .grid{grid-template-columns:repeat(auto-fill,minmax(64px,1fr));gap:16px 10px}
  .tile{width:50px;height:50px}
  .tile svg{width:22px;height:22px}
  .icon span.label{font-size:11px}
}
.icon{
  display:flex;flex-direction:column;align-items:center;gap:8px;
  text-align:center;padding:6px;border-radius:12px;
  transition:transform .15s;
  /* Without these, a long-press on the link fires the browser's own
     "open in new tab / share" callout before our reorder gesture gets
     a chance — this is what actually owns long-press-to-rearrange.
     touch-action must be none from the start (not just once .jiggle
     is added): Android Chrome's long-press link menu and its scroll
     gesture recognizer are both gated by this, so setting it only
     after the 500ms timer fires is too late — a real finger drifts
     enough in that time for the browser to already have hijacked the
     touch as a scroll (or armed its own link menu) before our JS ever
     gets to react. */
  touch-action:none;
  -webkit-touch-callout:none;-webkit-user-select:none;user-select:none;
}
.icon:hover{transform:translateY(-3px)}
.icon:active{transform:translateY(0)}
.tile{
  width:56px;height:56px;border-radius:16px;
  display:grid;place-items:center;
  /* Fixed, not var(--card): tile backgrounds are deliberately colorful
     in both themes, so the icon glyph needs to stay light regardless
     of whether --card itself is currently light or dark. */
  color:#fdfaf6;
  box-shadow:0 6px 16px -6px #00000040;
}
.tile svg{width:26px;height:26px}
.icon span.label{
  font-size:12px;color:var(--ink);line-height:1.3;
  /* Soft halo in the page's own tone (not the wallpaper's), so the
     label stays readable wherever the wallpaper gradient happens to
     be lighter/darker/more saturated underneath it. */
  text-shadow:0 1px 2px var(--paper),0 0 10px var(--paper);
}

/* --- long-press rearrange, iOS-style --- */
.grid.jiggle .icon{
  animation:jiggle .25s infinite ease-in-out;
}
.grid.jiggle .icon:nth-child(even){animation-name:jiggle-reverse}
.grid.jiggle .icon.dragging{
  /* transition:none is the important part — the base .icon transition
     would otherwise ease every transform update shell.js sets while
     dragging, making the icon visibly lag behind the pointer instead
     of tracking it directly. */
  animation:none;transition:none;transform:scale(1.08);z-index:5;
  box-shadow:0 10px 24px -8px #00000059;border-radius:16px;
}
@keyframes jiggle{
  0%,100%{transform:rotate(-1.5deg)}
  50%{transform:rotate(1.5deg)}
}
@keyframes jiggle-reverse{
  0%,100%{transform:rotate(1.5deg)}
  50%{transform:rotate(-1.5deg)}
}
@media(prefers-reduced-motion:reduce){
  .grid.jiggle .icon{animation:none;outline:2px dashed var(--lilac-deep);outline-offset:2px}
}

.dots{display:flex;justify-content:center;padding-top:6px}
.dot{
  /* Real tap target is 40x40; the visible dot is drawn via ::after so
     the hit area can be much bigger than the mark without looking it. */
  width:40px;height:40px;border:none;padding:0;background:none;
  display:grid;place-items:center;
}
.dot::after{
  content:'';width:7px;height:7px;border-radius:50%;
  background:var(--lilac-deep);opacity:.35;
  transition:width .15s,opacity .15s,border-radius .15s;
}
.dot.active::after{opacity:1;width:18px;border-radius:4px}

@media(prefers-color-scheme:dark){
  :root:not([data-theme="light"]){
    --paper:#29252e;--ink:#f0e9ee;--muted:#c0b5c4;--lilac:#42364b;
    --lilac-deep:#c6abd7;--line:#514657;--card:#38313b;--butter:#473f35;--focus:#d7b6ee;
    --wallpaper-1:#3a2f45;--wallpaper-2:#3a3327;
    color-scheme:dark;
  }
  :root:not([data-theme="light"]) .widget,
  :root:not([data-theme="light"]) .bar{background:#38313bb3;border-color:#4a3f55}
}
:root[data-theme="dark"]{
  --paper:#29252e;--ink:#f0e9ee;--muted:#c0b5c4;--lilac:#42364b;
  --lilac-deep:#c6abd7;--line:#514657;--card:#38313b;--butter:#473f35;--focus:#d7b6ee;
  --wallpaper-1:#3a2f45;--wallpaper-2:#3a3327;
  color-scheme:dark;
}
:root[data-theme="dark"] .widget,
:root[data-theme="dark"] .bar{background:#38313bb3;border-color:#4a3f55}
