/* Play view: HUD + board + tiles. */

.view--play {
  display: grid;
  grid-template-columns: 208px minmax(0, 1fr);
  gap: 16px;
  padding: 14px;
}

/* ---------- HUD ---------- */
.hud {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
.hud-label {
  font: 600 10.5px/1 var(--font-mono);
  color: var(--muted);
  text-transform: uppercase;
}
.hud-num { font: 800 22px/1.15 var(--font-mono); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.hud-num--big { font-size: 34px; color: var(--text); }
.hud-stat { display: flex; flex-direction: column; gap: 5px; }
.hud-stat--small .hud-num { font-size: 16px; }
.hud-stat.is-low .hud-num, .hud-stat.is-low .hud-label { color: var(--warn); }

.hud-progress { display: flex; flex-direction: column; gap: 6px; }
.bar {
  height: 14px;
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  background: var(--bg-2);
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: repeating-linear-gradient(-45deg, var(--acid) 0 8px, var(--acid-2) 8px 16px);
  transform-origin: left;
  transform: scaleX(0);
  transition: transform 300ms cubic-bezier(.2,.8,.3,1);
}
.hud-sub { font: 500 11px/1 var(--font-mono); color: var(--muted); }

.hud-actions { display: flex; flex-direction: column; gap: 8px; margin-top: auto; }

/* ---------- board ---------- */
.board-wrap {
  position: relative;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
}
.board {
  --rows: 8;
  --cols: 8;
  position: relative;
  width: min(100cqw, 100cqh);
  aspect-ratio: 1;
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  /* Checkerboard marks the cells; one cell = 1/cols of the board. */
  background:
    conic-gradient(var(--cell-a) 25%, var(--cell-b) 0 50%, var(--cell-a) 0 75%, var(--cell-b) 0)
    0 0 / calc(200% / var(--cols)) calc(200% / var(--rows));
  box-shadow: inset 0 0 0 1px var(--line), var(--shadow-win);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.board:focus { outline: none; }
.board:focus-visible { outline: 3px solid var(--acid); outline-offset: 3px; }

.tile {
  position: absolute;
  left: 0;
  top: 0;
  width: calc(100% / var(--cols));
  height: calc(100% / var(--rows));
  will-change: transform;
  pointer-events: none;
}
.tile-in { position: absolute; inset: 0; }
.tile-face {
  position: absolute;
  inset: 7%;
  display: block;
  transition: transform 140ms cubic-bezier(.3,1.6,.6,1);
}
.tile-face > svg, .tile-face > img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  -webkit-user-drag: none;
}

.tile.is-selected::before {
  content: "";
  position: absolute;
  inset: 2px;
  border: 3px solid var(--acid);
  border-radius: var(--r-md);
  background: var(--acid-soft);
}
.tile.is-selected .tile-face { transform: scale(1.1) rotate(-5deg); }

.tile.is-cursor::after {
  content: "";
  position: absolute;
  inset: 1px;
  border: 2px dashed var(--text);
  border-radius: var(--r-md);
}

/* Hint: gentle bob on the two tiles, stops on the next input. */
.tile.is-hint .tile-face { animation: hint-bob 1.1s ease-in-out infinite; }
@keyframes hint-bob {
  0%, 100% { transform: none; }
  50% { transform: translateY(-7%) scale(1.08); }
}

.tile.is-nope .tile-face { filter: saturate(0.3) brightness(0.8); }

/* ---------- pause ---------- */
.pause-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(5, 7, 13, 0.8);
}
.pause-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(340px, 100%);
  padding: 20px;
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-win);
}
.pause-title { font: 30px/1 var(--font-stamp); color: var(--warn); }
.pause-sub { color: var(--muted); }

/* ---------- narrow screens ---------- */
@media (max-width: 719px), (max-height: 520px) and (max-width: 1023px) {
  .view--play {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 8px;
    padding: 8px;
  }
  .hud {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px 10px;
    overflow: visible;
  }
  .hud-progress { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 8px; }
  .hud-progress .hud-label { flex: none; }
  .hud-progress .bar { flex: 1; height: 10px; }
  .hud-progress .hud-sub { flex: none; }
  .hud-stat { gap: 2px; }
  .hud-num, .hud-num--big, .hud-stat--small .hud-num { font-size: 18px; }
  .hud-stat--chain, .hud-stat--best { display: none; }
  .hud-actions { grid-column: 1 / -1; flex-direction: row; margin-top: 0; }
  .hud-actions .btn { flex: 1; min-height: 44px; padding: 0 8px; }
}

/* ======================= Phase 2 ======================= */

/* Board column: optional boss bar above the board. */
.play-main {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  min-width: 0;
  min-height: 0;
}
.play-main > .board-wrap { grid-row: 2; }

/* ---------- objectives ---------- */
.hud-objs { display: flex; flex-direction: column; gap: 6px; }
.obj {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 5px 8px 5px 5px;
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  background: var(--bg-2);
}
.obj-ico { width: 28px; height: 28px; display: grid; place-items: center; }
.obj-ico svg, .obj-ico img { width: 100%; height: 100%; object-fit: contain; display: block; }
.obj-pts { font: 800 9px/1 var(--font-mono); color: var(--acid-ink); background: var(--acid); padding: 5px 3px; border-radius: 2px; }
.obj-txt { font-size: 12px; line-height: 1.2; color: var(--muted); overflow-wrap: anywhere; }
.obj-n { font: 800 13px/1 var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.obj.is-done { background: var(--acid-soft); border-color: var(--acid); }
.obj.is-done .obj-n { color: var(--acid); }
.obj.is-done .obj-txt { text-decoration: line-through; }
.obj.is-bump { animation: obj-bump 260ms ease-out; }
@keyframes obj-bump { 40% { transform: scale(1.05); } }

/* ---------- limit flash (+moves / -moves) ---------- */
.hud-stat.is-plus .hud-num { animation: num-plus 600ms ease-out; }
.hud-stat.is-minus .hud-num { animation: num-minus 600ms ease-out; }
@keyframes num-plus { 30% { transform: translateY(-4px) scale(1.15); color: var(--acid); } }
@keyframes num-minus { 30% { transform: translateX(-3px); color: var(--hot); } 60% { transform: translateX(3px); } }

/* ---------- Rot Meter ---------- */
.hud-rot { display: flex; flex-direction: column; gap: 6px; }
.hud-rot-head { display: flex; justify-content: space-between; align-items: baseline; }
.hud-rot-head b { font: 800 13px/1 var(--font-mono); color: var(--hot); font-variant-numeric: tabular-nums; }
.bar--rot { height: 12px; }
.bar--rot .bar-fill {
  background: repeating-linear-gradient(-45deg, var(--hot) 0 6px, var(--hot-2) 6px 12px);
  transition: transform 160ms linear;
}
.hud-rot.is-brainrot .bar--rot .bar-fill { background: repeating-linear-gradient(-45deg, var(--acid) 0 6px, var(--hot) 6px 12px); }
.hud-rot.is-brainrot .hud-rot-head b { color: var(--acid); }

/* ---------- boss bar ---------- */
.boss-bar {
  --boss: var(--hot);
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 8px 12px 8px 8px;
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: 4px 4px 0 var(--ink);
}
.boss-pic { position: relative; width: 64px; height: 64px; }
.boss-portrait, .boss-shards, .boss-shard { position: absolute; inset: 0; }
.boss-portrait {
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  background: var(--bg-2);
  overflow: hidden;
}
.boss-portrait svg, .boss-portrait img, .boss-shard svg, .boss-shard img { display: block; width: 100%; height: 100%; object-fit: contain; }
.boss-portrait.is-broken { opacity: 0; }
.boss-shards { pointer-events: none; z-index: 2; }
.boss-shard { border: 2px solid var(--ink); border-radius: var(--r-sm); background: var(--bg-2); overflow: hidden; }
.boss-info { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.boss-head { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.boss-name { font: 800 17px/1.1 var(--font-ui); color: var(--boss); white-space: nowrap; }
.boss-title { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar--boss { height: 16px; }
.bar--boss .bar-fill {
  transform: scaleX(1);
  background: repeating-linear-gradient(-45deg, var(--boss) 0 8px, color-mix(in srgb, var(--boss) 70%, #000) 8px 16px);
  transition: transform 260ms cubic-bezier(.2,.8,.3,1);
}
.boss-meta { display: flex; justify-content: space-between; gap: 10px; font: 600 11px/1.2 var(--font-mono); color: var(--muted); }
.boss-intent { text-align: right; }
.boss-bar.is-telegraph { border-color: var(--warn); }
.boss-bar.is-telegraph .boss-intent { color: var(--warn); font-weight: 800; animation: intent-blink 1s steps(2, start) infinite; }
@keyframes intent-blink { to { opacity: 0.35; } }
.boss-bar.is-hit .boss-portrait { animation: boss-hit 240ms ease-out; }
@keyframes boss-hit { 30% { transform: translateX(-4px) rotate(-4deg); } 60% { transform: translateX(3px) rotate(3deg); } }
.boss-bar.is-attack .boss-pic { animation: boss-lunge 380ms cubic-bezier(.3,1.5,.5,1); }
@keyframes boss-lunge { 40% { transform: scale(1.18) translateY(4px); } }
.boss-bar.is-dead .boss-name { text-decoration: line-through; }

/* Board edge while a boss attack is announced. */
.board-wrap.is-telegraph .board { border-color: var(--warn); box-shadow: inset 0 0 0 2px var(--warn), var(--shadow-win); }

/* ---------- specials ---------- */
.tile-sp { position: absolute; inset: 16%; pointer-events: none; opacity: 0.94; }
.tile-sp svg { display: block; width: 100%; height: 100%; }
.tile.is-special .tile-in::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 3px dashed var(--acid);
  border-radius: 50%;
  animation: sp-spin 4s linear infinite;
}
.tile[data-slot="0"] .tile-in::before { border-color: var(--hot); inset: 0; }
@keyframes sp-spin { to { transform: rotate(360deg); } }

/* ---------- tab blockers ---------- */
.tile-block { position: absolute; inset: 0; pointer-events: none; }
.tile-block[data-hp="0"] { display: none; }
.tile.is-unlocking .tile-block { display: block; }
.tile.is-frozen .tile-face { opacity: 0.75; }
.tile.is-frozen .tile-sp { opacity: 0.5; }
.tb-card {
  position: absolute;
  inset: 9% 7% 7%;
  border: 2px solid var(--ink);
  border-radius: 7px 7px 3px 3px;
  background: rgba(233, 228, 212, 0.38);
  box-shadow: 2px 2px 0 var(--ink);
  overflow: hidden;
}
/* Title strip of the "tab". */
.tb-card::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 26%;
  background: var(--ink);
}
.tb-x {
  position: absolute;
  top: 0;
  right: 6%;
  height: 26%;
  display: grid;
  place-items: center;
  font: 800 clamp(8px, 1.4cqmin, 13px)/1 var(--font-mono);
  color: var(--hot);
}
.tb-pips { position: absolute; left: 0; right: 0; bottom: 8%; display: flex; justify-content: center; gap: 10%; }
.tb-pips i { width: 17%; aspect-ratio: 1; border: 2px solid var(--ink); border-radius: 50%; background: #e9e4d4; }
.tile-block[data-hp="1"] .tb-pips i + i { display: none; }
.tile-block[data-hp="2"] .tb-card { background: rgba(255, 176, 32, 0.42); }
.tile-block[data-hp="2"] .tb-card::before { background: #6b4700; }
.tile-block[data-hp="2"] .tb-pips i { background: var(--warn); }

/* Layer for beams and rings, clipped by the board. */
.board-fx { position: absolute; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }

/* ---------- Brainrot Mode ---------- */
.brainrot-banner {
  position: absolute;
  bottom: 8px;
  left: 50%;
  z-index: 9;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 4px;
  border: 2px solid var(--ink);
  background: var(--hot);
  color: #fff;
  box-shadow: 3px 3px 0 var(--ink);
  transform: translateX(-50%) rotate(-2deg);
  white-space: nowrap;
  pointer-events: none;
}
.brainrot-banner b { font: 16px/1 var(--font-stamp); }
.brainrot-banner span { font: 700 12px/1 var(--font-mono); }
.brainrot-banner span:last-child { color: var(--acid); min-width: 3ch; }

body.is-brainrot .board { border-color: var(--hot); box-shadow: 0 0 0 3px var(--acid), 0 0 0 6px var(--hot), var(--shadow-win); }
body.is-brainrot .tile-face > * { animation: rot-wobble 0.9s ease-in-out infinite alternate; }
body.is-brainrot .tile:nth-child(3n) .tile-face > * { animation-duration: 0.7s; animation-direction: alternate-reverse; }
@keyframes rot-wobble { from { transform: rotate(-6deg) scale(1.02); } to { transform: rotate(6deg) scale(0.97); } }
/* Scanlines roll slowly over the board (no flashing). */
body.is-brainrot .board-fx::after {
  content: "";
  position: absolute;
  inset: -20% 0;
  background: repeating-linear-gradient(0deg, rgba(255, 46, 136, 0.09) 0 2px, transparent 2px 6px);
  animation: scan-roll 2.4s linear infinite;
}
@keyframes scan-roll { to { transform: translateY(18%); } }
body.is-brainrot .sticker { animation: sticker-wobble 1.6s ease-in-out infinite alternate; }
@keyframes sticker-wobble { to { transform: rotate(6deg) scale(1.08); } }
body.is-brainrot .win--main > .win-bar { background: var(--hot); color: #fff; }

/* FATALITY: freeze beat before the board explodes. */
.board-wrap.is-slowmo .board { transform: scale(1.025); transition: transform 900ms cubic-bezier(.2,.8,.3,1); }
.board-wrap.is-slowmo .tile-face { opacity: 0.75; }

/* ---------- event popup ("pesan baru") ---------- */
.os-popup {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 12;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(290px, calc(100% - 20px));
  padding: 10px 12px 12px;
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  background: var(--surface-2);
  box-shadow: 5px 5px 0 var(--ink);
  animation: toast-in 220ms cubic-bezier(.2,.9,.3,1.2);
}
.os-popup-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.os-popup-head .win-ico { color: var(--acid); }
.os-popup-app { margin-left: auto; font: 600 10.5px/1 var(--font-mono); color: var(--muted); }
.os-popup-text { font-size: 16px; font-weight: 700; }
.os-popup-timer { height: 4px; background: var(--bg-2); border-radius: 2px; overflow: hidden; }
.os-popup-timer i { display: block; height: 100%; background: var(--warn); transform-origin: left; }
.os-popup-timer i.is-running { animation: pop-timer linear forwards; }
@keyframes pop-timer { from { transform: scaleX(1); } to { transform: scaleX(0); } }
.os-popup-actions { display: flex; gap: 8px; }
.os-popup-actions .btn { flex: 1; min-height: 40px; }

/* ---------- Wifi lock ---------- */
.lock-overlay {
  position: absolute;
  inset: 0;
  z-index: 11;
  display: grid;
  place-items: center;
  padding: 12px;
  background: rgba(5, 7, 13, 0.78);
}
.lock-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 20px;
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-win);
  text-align: center;
}
.lock-card svg { width: 44px; height: 36px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; }
.lock-card .lock-x { stroke: var(--hot); stroke-width: 2.4; }
.lock-card b { font: 18px/1 var(--font-stamp); color: var(--warn); }
.lock-card p { font: 500 12px/1.4 var(--font-mono); color: var(--muted); }

@media (max-width: 719px), (max-height: 520px) and (max-width: 1023px) {
  .play-main { gap: 6px; }
  .hud-objs { grid-column: 1 / -1; flex-direction: row; overflow-x: auto; gap: 6px; scrollbar-width: none; }
  .hud-objs::-webkit-scrollbar { display: none; }
  .obj { flex: 1 0 auto; min-height: 34px; grid-template-columns: 22px auto auto; }
  .obj-ico { width: 22px; height: 22px; }
  .obj-txt { display: none; }
  .hud-rot { justify-content: flex-end; gap: 4px; }
  .boss-bar { grid-template-columns: 42px minmax(0, 1fr); gap: 8px; padding: 5px 8px 5px 5px; box-shadow: 3px 3px 0 var(--ink); }
  .boss-pic { width: 42px; height: 42px; }
  .boss-title { display: none; }
  .boss-name { font-size: 14px; }
  .bar--boss { height: 12px; }
  .brainrot-banner b { font-size: 13px; }
}

/* ======================= Phase 3 ======================= */

/* ---------- boosters ---------- */
.hud-boost { display: flex; flex-direction: column; gap: 6px; }
.hud-boost-head { display: flex; justify-content: space-between; align-items: baseline; }
.hud-aura { font: 600 11px/1 var(--font-mono); color: var(--muted); }
.hud-aura b { color: var(--warn); font-size: 13px; }
.boost-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 7px; padding: 7px 7px 3px 0; }
.boost {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 44px;
  padding: 4px 2px 10px;
  border: 2px solid var(--ink);
  border-radius: var(--r-sm);
  background: var(--surface-3);
  box-shadow: 0 3px 0 var(--ink);
  transition: transform 80ms, box-shadow 80ms;
}
.boost:active { transform: translateY(3px); box-shadow: none; }
.boost-g { font: 15px/1 var(--font-stamp); color: var(--text); }
.boost-n {
  position: absolute;
  top: -7px;
  right: -6px;
  min-width: 18px;
  padding: 2px 4px;
  border: 2px solid var(--ink);
  border-radius: 9px;
  background: var(--warn);
  color: var(--ink);
  font: 800 10px/1 var(--font-mono);
}
.boost kbd { position: absolute; bottom: 2px; left: 50%; transform: translateX(-50%); padding: 0 3px; font-size: 9px; border: 0; background: none; color: var(--muted); }
.boost.is-empty { opacity: 0.45; }
.boost.is-empty .boost-n { background: var(--surface-2); color: var(--muted); }
.boost.is-aiming { background: var(--acid); box-shadow: 0 0 0 3px var(--hot); }
.boost.is-aiming .boost-g { color: var(--acid-ink); }
.boost-aim { font: 600 11px/1.3 var(--font-mono); color: var(--hot); }
.board.is-aiming { cursor: crosshair; outline: 3px dashed var(--hot); outline-offset: 3px; }

/* Cheat watermark over the board. */
.cheat-mark {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 9;
  padding: 4px 10px 2px;
  border: 3px solid var(--hot);
  color: var(--hot);
  font: 22px/1 var(--font-stamp);
  transform: rotate(-8deg);
  opacity: 0.85;
  pointer-events: none;
}

/* Affinity level 3: that character's tiles glow (static, no flashing). Filters stay off on phones. */
@media (min-width: 720px) {
  body[data-glow~="1"] .tile[data-slot="1"] .tile-face,
  body[data-glow~="2"] .tile[data-slot="2"] .tile-face,
  body[data-glow~="3"] .tile[data-slot="3"] .tile-face,
  body[data-glow~="4"] .tile[data-slot="4"] .tile-face,
  body[data-glow~="5"] .tile[data-slot="5"] .tile-face,
  body[data-glow~="6"] .tile[data-slot="6"] .tile-face {
    filter: drop-shadow(0 0 4px var(--warn)) drop-shadow(0 0 1px var(--warn));
  }
}

@media (max-width: 719px), (max-height: 520px) and (max-width: 1023px) {
  .hud-boost { grid-column: 1 / -1; flex-direction: row; align-items: center; gap: 8px; }
  .hud-boost-head { flex-direction: column; align-items: flex-start; gap: 4px; flex: none; }
  .hud-boost-head .hud-label { display: none; }
  .boost-grid { flex: 1; }
  .boost { min-height: 44px; }
  .boost-aim { display: none; }
}
