/* Trút Giận — phong cách trang truyện tranh: giấy ngà, mực đen, đỏ – vàng. */
:root {
  --paper: #f4e9d4;
  --paper-2: #ead9b8;
  --ink: #1b1410;
  --red: #e4372b;
  --red-deep: #b3221a;
  --yellow: #ffc928;
  --cyan: #2bb6c9;
  --white: #fffaf0;
  --shadow: 4px 4px 0 var(--ink);
  --display: 'Bangers', 'Baloo 2', Impact, sans-serif;
  --body: 'Baloo 2', ui-rounded, 'Segoe UI', system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--body);
  font-weight: 500;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

#app {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 38%, rgba(255, 250, 240, 0.9), rgba(255, 250, 240, 0) 55%),
    radial-gradient(circle, rgba(27, 20, 16, 0.13) 1.3px, transparent 1.8px) 0 0 / 13px 13px,
    linear-gradient(180deg, var(--paper), var(--paper-2));
}

/* ---------- Sân đấu ---------- */
#stage { position: absolute; inset: 0; touch-action: none; outline: none; cursor: crosshair; }
#stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#fx { pointer-events: none; }
.rays {
  position: absolute;
  left: 50%; top: 40%;
  width: 220vmax; height: 220vmax;
  translate: -50% -50%;
  background: repeating-conic-gradient(rgba(228, 55, 43, 0.13) 0 5deg, transparent 5deg 12deg);
  -webkit-mask-image: radial-gradient(circle, transparent 0 9%, #000 26%, transparent 60%);
  mask-image: radial-gradient(circle, transparent 0 9%, #000 26%, transparent 60%);
  opacity: 0.55;
  animation: spin 90s linear infinite;
  transition: opacity 0.35s ease-out;
}
#stage.hit .rays { opacity: 1; transition: none; }
@keyframes spin { to { rotate: 360deg; } }

.panel {
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

/* ---------- HUD ---------- */
.hud {
  position: absolute;
  top: calc(10px + var(--safe-t)); left: 12px; right: 12px;
  display: flex; align-items: center; gap: 12px;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.brand {
  font-family: var(--display);
  font-size: 30px; line-height: 1.3; letter-spacing: 1px;
  color: var(--white);
  background: var(--ink);
  padding: 0 12px 0 10px;
  border-radius: 8px;
  rotate: -3deg;
  white-space: nowrap;
}
.brand b { font-weight: 400; color: var(--yellow); }
.meter { flex: 1; max-width: 430px; margin: 0 auto; padding: 6px 10px 8px; }
.meter-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; font-weight: 700; line-height: 1.3; }
.meter-label { font-family: var(--display); font-size: 19px; font-weight: 400; letter-spacing: 1px; text-transform: uppercase; color: var(--red); }
.bar { height: 16px; margin-top: 3px; border: 2.5px solid var(--ink); border-radius: 99px; background: #e8dcc6; overflow: hidden; }
.bar i {
  display: block; height: 100%; width: 100%;
  background:
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.28) 0 8px, transparent 8px 16px),
    linear-gradient(90deg, var(--cyan), var(--yellow) 38%, var(--red) 75%);
  background-size: 22.6px 100%, 430px 100%;
  border-right: 2.5px solid var(--ink);
  transition: width 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  animation: stripes 0.8s linear infinite;
}
@keyframes stripes { to { background-position: 22.6px 0, 0 0; } }
.tools { display: flex; gap: 8px; }
.tool {
  width: 44px; height: 44px; padding: 9px;
  background: var(--white);
  border: 3px solid var(--ink); border-radius: 12px;
  box-shadow: 3px 3px 0 var(--ink);
  transition: translate 0.08s, box-shadow 0.08s;
}
.tool:active { translate: 3px 3px; box-shadow: 0 0 0 var(--ink); }
.tool svg { width: 100%; height: 100%; fill: none; stroke: var(--ink); stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.tool .off { display: none; }
.tool[aria-pressed='false'] .on { display: none; }
.tool[aria-pressed='false'] .off { display: inline; }

.score {
  position: absolute;
  top: calc(84px + var(--safe-t)); left: 16px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  pointer-events: none;
}
.stat { display: flex; align-items: baseline; gap: 7px; font-weight: 700; font-size: 15px; }
.stat b { font-family: var(--display); font-weight: 400; font-size: 46px; line-height: 1; letter-spacing: 1px; -webkit-text-stroke: 1px var(--ink); }
.stat b.pop { animation: pop 0.18s ease-out; }
.combo {
  font-family: var(--display); font-size: 24px; letter-spacing: 1px; line-height: 1.25;
  color: var(--white); background: var(--red);
  border: 3px solid var(--ink); border-radius: 10px;
  padding: 0 10px; rotate: -5deg;
  box-shadow: 3px 3px 0 var(--ink);
  transform-origin: left center;
}
.combo span { color: var(--yellow); font-size: 30px; }
.combo b { font-weight: 400; }
.combo.pop { animation: pop 0.2s ease-out; }
@keyframes pop { 0% { scale: 1.45; } 100% { scale: 1; } }

.hint {
  position: absolute; left: 0; right: 0;
  bottom: calc(118px + var(--safe-b));
  margin: 0; text-align: center;
  font-size: 15px; font-weight: 700;
  pointer-events: none;
  transition: opacity 0.4s;
}
.hint.gone { opacity: 0; }

/* ---------- Thanh chọn đòn ---------- */
.dock {
  position: absolute; left: 50%; translate: -50% 0;
  bottom: calc(14px + var(--safe-b));
  display: flex; gap: 8px;
  padding: 8px;
  background: var(--ink);
  border-radius: 20px;
  box-shadow: 0 10px 30px rgba(27, 20, 16, 0.25);
}
.dock button {
  position: relative;
  width: 68px; height: 78px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  background: var(--white);
  border: 0; border-radius: 13px;
  transition: translate 0.12s, background-color 0.12s, rotate 0.12s;
}
.dock .ico { font-size: 30px; line-height: 1.1; transition: scale 0.15s; }
.dock .lbl { font-family: var(--display); font-size: 21px; line-height: 1.3; letter-spacing: 1px; }
.dock kbd { position: absolute; top: 4px; right: 6px; font: 700 11px var(--body); opacity: 0.4; }
.dock button:hover { translate: 0 -3px; }
.dock button[aria-pressed='true'] { background: var(--yellow); translate: 0 -9px; rotate: -3deg; box-shadow: 0 0 0 3px var(--ink), 4px 6px 0 3px var(--red); }
.dock button[aria-pressed='true'] .ico { scale: 1.18; }
.dock button:focus-visible, .tool:focus-visible, .btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }

/* ---------- Màn hình phủ ---------- */
.screen {
  position: absolute; inset: 0; z-index: 5;
  display: none; place-items: center;
  padding: calc(20px + var(--safe-t)) 18px calc(20px + var(--safe-b));
  overflow: auto;
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 250, 240, 0.95), rgba(255, 250, 240, 0) 60%),
    radial-gradient(circle, rgba(27, 20, 16, 0.13) 1.3px, transparent 1.8px) 0 0 / 13px 13px,
    linear-gradient(180deg, var(--paper), var(--paper-2));
}
#app[data-screen='start'] #screenStart,
#app[data-screen='crop'] #screenCrop { display: grid; }
#app:not([data-screen='play']) :is(.hud, .score, .dock, .hint) { visibility: hidden; }
#screenStart.drag::after {
  content: 'Thả ảnh vào đây!';
  position: absolute; inset: 14px;
  display: grid; place-items: center;
  font-family: var(--display); font-size: 44px; color: var(--red);
  background: rgba(255, 250, 240, 0.88);
  border: 4px dashed var(--ink); border-radius: 22px;
}

.start-card { position: relative; width: min(100%, 470px); text-align: center; }
.start-card > * { animation: rise 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2) backwards; }
.start-card > :nth-child(2) { animation-delay: 0.06s; }
.start-card > :nth-child(3) { animation-delay: 0.14s; }
.start-card > :nth-child(4) { animation-delay: 0.2s; }
.start-card > :nth-child(n + 5) { animation-delay: 0.26s; }
@keyframes rise { from { opacity: 0; translate: 0 18px; } }
.kicker {
  display: inline-block; margin: 0;
  font-weight: 800; font-size: 14px; letter-spacing: 2px; text-transform: uppercase;
  background: var(--ink); color: var(--yellow);
  padding: 3px 12px; border-radius: 99px;
}
h1 {
  margin: 34px 0 6px;
  font-family: var(--display); font-weight: 400;
  font-size: clamp(84px, 25vw, 142px); line-height: 0.98; letter-spacing: 3px;
  rotate: -5deg;
}
h1 span { display: block; padding-top: 0.12em; -webkit-text-stroke: 3px var(--ink); paint-order: stroke fill; }
h1 span:first-child { color: var(--yellow); text-shadow: 6px 6px 0 var(--ink); translate: -7% 0; }
h1 span:last-child { color: var(--red); text-shadow: 6px 6px 0 var(--ink); translate: 6% -12%; }
.lead { margin: 4px auto 18px; max-width: 400px; font-size: 18px; line-height: 1.45; }
.lead b { font-weight: 800; background: linear-gradient(transparent 58%, var(--yellow) 58%); }
.sub { margin: 10px 0 14px; font-size: 14px; opacity: 0.72; }
.privacy { margin: 18px 0 0; font-size: 13.5px; font-weight: 700; opacity: 0.75; }
.error { margin: 12px 0 0; font-weight: 700; color: var(--red-deep); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 8px 22px;
  font-family: var(--display); font-size: 25px; letter-spacing: 1px; line-height: 1.3;
  border: 3px solid var(--ink); border-radius: 14px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: translate 0.08s, box-shadow 0.08s, rotate 0.15s;
}
.btn svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--red); color: var(--white); }
.btn-primary:hover { rotate: -1.5deg; }
.btn-ghost { background: var(--white); font-size: 20px; min-height: 44px; padding: 4px 16px; box-shadow: 3px 3px 0 var(--ink); }
.btn:active { translate: 4px 4px; box-shadow: 0 0 0 var(--ink); }
#drop { font-size: 28px; padding: 12px 26px; }

.deco {
  position: absolute; z-index: 0;
  font-family: var(--display); font-size: clamp(34px, 7vw, 62px); line-height: 1.3;
  color: var(--white); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
  text-shadow: 4px 4px 0 var(--ink);
  opacity: 0.9;
  animation: wobble 2.6s ease-in-out infinite;
}
.deco-a { top: 9%; left: 7%; rotate: -14deg; color: var(--yellow); }
.deco-b { top: 16%; right: 6%; rotate: 11deg; color: var(--red); animation-delay: -0.9s; }
.deco-c { bottom: 9%; left: 10%; rotate: 8deg; color: var(--cyan); animation-delay: -1.7s; }
@keyframes wobble { 50% { scale: 1.1; translate: 0 -6px; } }

.crop-card { width: min(100%, 420px); padding: 16px 18px 18px; text-align: center; }
.crop-card h2, .result-card h2 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 36px; line-height: 1.3; letter-spacing: 1px; color: var(--red); }
.crop-card .sub { margin: 0 0 10px; }
.crop-wrap { width: min(100%, 300px, 42vh); margin: 0 auto; border: 3px solid var(--ink); border-radius: 12px; overflow: hidden; background: #2a211b; }
#cropCanvas { display: block; width: 100%; aspect-ratio: 368 / 448; touch-action: none; cursor: grab; }
#cropCanvas:active { cursor: grabbing; }
.zoom { display: flex; align-items: center; gap: 10px; margin: 12px auto 14px; max-width: 300px; font-weight: 800; font-size: 22px; }
.zoom input { flex: 1; accent-color: var(--red); height: 28px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }

.overlay {
  position: absolute; inset: 0; z-index: 6;
  display: grid; place-items: center; padding: 20px;
  background: rgba(27, 20, 16, 0.45);
  animation: fade 0.25s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.result-card { width: min(100%, 430px); padding: 22px 20px 24px; text-align: center; animation: slam 0.4s cubic-bezier(0.2, 1.4, 0.4, 1) backwards; }
.result-card h2 { font-size: 52px; margin-top: 6px; }
@keyframes slam { from { scale: 1.6; rotate: -8deg; opacity: 0; } }

.busy {
  position: absolute; inset: 0; z-index: 8;
  display: grid; place-items: center;
  background: rgba(244, 233, 212, 0.86);
}
.busy span {
  font-family: var(--display); font-size: clamp(34px, 8vw, 54px); line-height: 1.3; letter-spacing: 1px;
  color: var(--white); -webkit-text-stroke: 2px var(--ink); paint-order: stroke fill;
  text-shadow: 4px 4px 0 var(--ink);
  background: var(--red); border: 3px solid var(--ink); border-radius: 16px;
  padding: 6px 22px; rotate: -4deg; box-shadow: var(--shadow);
  animation: wobble 0.7s ease-in-out infinite;
}

.fatal { position: absolute; inset: auto 20px 40%; z-index: 9; text-align: center; font-weight: 700; font-size: 18px; }

/* ---------- Màn hình hẹp ---------- */
@media (max-width: 640px) {
  .brand { display: none; }
  .hud { gap: 8px; }
  .meter { max-width: none; }
  .score { top: calc(88px + var(--safe-t)); left: 14px; }
  .dock { gap: 5px; padding: 6px; width: calc(100% - 16px); max-width: 380px; }
  .dock button { flex: 1; width: auto; height: 70px; }
  .dock kbd { display: none; }
  .dock .ico { font-size: 26px; }
  .dock .lbl { font-size: 19px; }
  .hint { bottom: calc(104px + var(--safe-b)); font-size: 13.5px; }
}
@media (max-height: 520px) {
  .dock button { height: 58px; }
  .dock .ico { font-size: 20px; }
  .hint { display: none; }
  h1 { font-size: 72px; }
}
@media (prefers-reduced-motion: reduce) {
  .rays, .deco, .bar i { animation: none; }
}
