* { box-sizing: border-box; }
[hidden] { display: none !important; }
:root {
  color-scheme: light;
  --ink: #241b33;
  --paper: #f7f3ec;
  --card: #fffdf9;
  --accent: #5b3a8c;
  --rule: #c9bfd6;
  /* Group colours: kunyit, pandan, laut, bunga telang. */
  --g0: #f2cf5b; --g0-ink: #3d2c00;
  --g1: #9fd08f; --g1-ink: #123d12;
  --g2: #93c2ea; --g2-ink: #0d2f4d;
  --g3: #c5a3e6; --g3-ink: #2f1450;
  --ease-out: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
}
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 1rem/1.5 "DM Sans", Arial, sans-serif;
}
a { color: var(--accent); text-underline-offset: .18em; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:is(a, button, summary, textarea):focus-visible { outline: 3px solid #b34913; outline-offset: 3px; }
:is(#outcome, #board-title, #puzzle):focus { outline: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -60px; background: white; padding: 8px; }
.skip:focus { top: 8px; }
.wrap { width: min(100% - 32px, 640px); margin: auto; }
.wordmark { display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--ink); padding: 16px 0; }
.wordmark a { display: flex; align-items: center; min-height: 44px; font-weight: 700; color: var(--ink); text-decoration: none; }
h1, h2, h3, p { margin: 0; }
.intro { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 30px 0 22px; }
h1 { font: 400 clamp(3.3rem, 10vw, 5rem)/.98 "DM Serif Text", Georgia, serif; letter-spacing: -.05em; }
.intro p { margin-top: 10px; }
.motif { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; transform: rotate(-8deg); }
.motif i { width: clamp(22px, 5vw, 32px); aspect-ratio: 1; border-radius: 6px; border: 1px solid rgb(0 0 0 / .2); }
.motif i:nth-child(1) { background: var(--g0); animation: bob 5s var(--ease-out) infinite; }
.motif i:nth-child(2) { background: var(--g1); animation: bob 5s .4s var(--ease-out) infinite; }
.motif i:nth-child(3) { background: var(--g2); animation: bob 5s .8s var(--ease-out) infinite; }
.motif i:nth-child(4) { background: var(--g3); animation: bob 5s 1.2s var(--ease-out) infinite; }
@keyframes bob { 0%, 80%, 100% { transform: none; } 88% { transform: translateY(-5px) rotate(-6deg); } }

#puzzle {
  background: var(--card);
  border: 1px solid #b9aec9;
  border-radius: 8px;
  padding: clamp(14px, 4vw, 28px);
  box-shadow: 0 4px 0 #e0d8ea;
}
.edition { display: flex; justify-content: space-between; gap: 5px; flex-wrap: wrap; border-bottom: 1px solid var(--rule); padding-bottom: 12px; font-size: .83rem; font-weight: 700; }
.edition time { font-weight: 400; }
.instructions { margin: 18px 0 14px; font: 400 clamp(1.3rem, 4vw, 1.7rem)/1.2 "DM Serif Text", Georgia, serif; letter-spacing: -.015em; }

#solved { display: grid; gap: 8px; }
#solved:not(:empty) { margin-bottom: 8px; }
.band {
  border-radius: 6px;
  padding: 12px 10px 13px;
  text-align: center;
  min-height: 66px;
  display: grid;
  align-content: center;
  gap: 2px;
}
.band h3 { font-size: .98rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; line-height: 1.25; }
.band p { font-size: .98rem; line-height: 1.35; }
.band.arrive { animation: arrive .52s var(--spring) both; }
.band.arrive h3, .band.arrive p { animation: rise .42s .16s var(--ease-out) both; }
.band.arrive p { animation-delay: .24s; }
.band.missed { background-image: repeating-linear-gradient(135deg, rgb(255 255 255 / .35) 0 6px, transparent 6px 12px); }
#solved .band.missed.arrive:nth-child(2) { animation-delay: .14s; }
#solved .band.missed.arrive:nth-child(3) { animation-delay: .28s; }
#solved .band.missed.arrive:nth-child(4) { animation-delay: .42s; }
@keyframes arrive { from { opacity: 0; transform: scale(.94, .7); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.level-0 { background: var(--g0); color: var(--g0-ink); }
.level-1 { background: var(--g1); color: var(--g1-ink); }
.level-2 { background: var(--g2); color: var(--g2-ink); }
.level-3 { background: var(--g3); color: var(--g3-ink); }

#board { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.tile {
  min-height: 66px;
  padding: 6px 4px;
  border: 0;
  border-radius: 6px;
  background: #ebe4f2;
  color: var(--ink);
  font-weight: 700;
  font-size: var(--tile-size, 1rem);
  line-height: 1.15;
  hyphens: manual;
  box-shadow: inset 0 -3px 0 rgb(36 27 51 / .12);
  transition: background-color .16s ease, color .16s ease, transform .16s var(--spring), box-shadow .16s ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}
.tile:hover { background: #e1d7ec; }
.tile:active { transform: scale(.95); }
.tile[aria-pressed="true"] {
  background: #4a3270;
  color: white;
  transform: scale(.97);
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / .25);
}
.tile[aria-pressed="true"]:active { transform: scale(.93); }

.tries { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 16px 0 12px; font-size: .9rem; }
#tries { display: inline-flex; gap: 6px; }
#tries i { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); transition: transform .3s var(--spring), opacity .3s ease, background-color .3s ease; }
#tries i.used { transform: scale(.45); opacity: .35; background: #8c8496; }
.controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.controls button, #replay {
  min-height: 46px;
  padding: 9px 12px;
  border: 1px solid var(--ink);
  border-radius: 999px;
  background: transparent;
  font-weight: 700;
  transition: background-color .16s ease, color .16s ease, transform .12s ease, opacity .16s ease;
}
.controls button:active:not(:disabled), #replay:active { transform: scale(.96); }
.controls button:hover:not(:disabled), #replay:hover { background: #efe8f5; }
.controls button:disabled { opacity: .4; cursor: default; }
.controls .primary:disabled { background: var(--ink); color: white; }
.controls .primary:not(:disabled), .primary { background: var(--ink); color: white; border-color: var(--ink); }
.controls .primary:hover:not(:disabled) { background: #3b2d52; }
.primary { min-height: 46px; padding: 9px 18px; border-radius: 999px; font-weight: 700; border: 0; }
.assist { display: flex; justify-content: center; gap: 2px 18px; flex-wrap: wrap; margin-top: 8px; }
.assist button { border: 0; background: none; padding: 0 2px; min-height: 44px; color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
#hint-text, #confirm { background: #f0eaf6; border-radius: 6px; padding: 10px 12px; margin-top: 6px; text-align: center; animation: rise .3s var(--ease-out) both; }
#confirm p { margin-bottom: 8px; }
#confirm button { min-height: 44px; padding: 8px 14px; margin: 2px; border-radius: 999px; font-weight: 700; border: 1px solid var(--ink); background: var(--ink); color: white; }
#confirm button + button { background: white; color: var(--ink); }
#status:not(:empty) { margin-top: 12px; font-weight: 600; text-align: center; animation: rise .25s var(--ease-out) both; }

#result { margin-top: 20px; text-align: center; animation: rise .45s .25s var(--ease-out) both; }
#outcome { font: 400 clamp(2.2rem, 8vw, 3rem)/1 "DM Serif Text", Georgia, serif; letter-spacing: -.04em; }
#summary { margin: 8px auto 14px; max-width: 34ch; }
#grid { display: inline-grid; gap: 4px; margin-bottom: 4px; }
#grid div { display: flex; gap: 4px; }
#grid i { width: 22px; height: 22px; border-radius: 4px; animation: pop .34s var(--delay, 0ms) var(--spring) both; }
@keyframes pop { from { opacity: 0; transform: scale(.3); } to { opacity: 1; transform: none; } }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 10px; margin-top: 16px; }
#new-round, #first-result { margin-top: 14px; }
#first-result { display: block; margin-inline: auto; }
#share-text { width: 100%; margin-top: 10px; border: 1px solid #8d8299; border-radius: 4px; padding: 8px; }
.more { margin-top: 14px; font-size: .95rem; }

#credits { margin-top: 18px; text-align: left; border-top: 1px solid var(--rule); }
#credits summary { min-height: 48px; display: flex; align-items: center; font-weight: 700; color: var(--accent); cursor: pointer; }
#notes { list-style: none; padding: 0; margin: 0 0 6px; display: grid; gap: 8px; }
#notes li { border-radius: 6px; padding: 10px 12px; }
#notes p { margin-top: 3px; font-size: .95rem; }
#notes .sources { font-size: .85rem; }
#notes a { color: inherit; display: inline-block; padding-block: 6px; }

footer { padding: 24px 0 32px; color: #4c4357; font-size: .9rem; }
footer p, footer details { margin-bottom: 12px; }
footer > a { display: inline-flex; align-items: center; min-height: 44px; }

@media (max-width: 360px) {
  .wrap { width: calc(100% - 20px); }
  #board { gap: 5px; }
  .tile { min-height: 60px; padding-inline: 2px; }
  .motif { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
#credits summary { list-style: none; justify-content: space-between; }
#credits summary::-webkit-details-marker { display: none; }
#credits summary::after { content: ""; width: 7px; height: 7px; margin-inline-end: 4px; border: solid currentColor; border-width: 0 2px 2px 0; transform: rotate(45deg); transition: transform .2s ease; }
#credits[open] summary::after { transform: rotate(225deg); }
#credits[open] #notes li { animation: rise .35s var(--ease-out) both; }
#credits[open] #notes li:nth-child(2) { animation-delay: .05s; }
#credits[open] #notes li:nth-child(3) { animation-delay: .1s; }
#credits[open] #notes li:nth-child(4) { animation-delay: .15s; }
