/* Giao diện game nối trái cây — mọi giá trị màu, bo góc và đổ bóng lấy đúng
   theo `Naruto Onet v2.dc.html`. Phong cách "kẹo": bóng cứng đổ thẳng xuống
   dưới, nút lún xuống khi bấm. */

:root {
  --yellow: #ffd63a;
  --yellow-edge: #e0b400;
  --pink: #ff4b7a;
  --pink-edge: #d92a5b;
  --cyan: #4dd8ff;
  --cyan-edge: #17b6e6;

  --ink: #555;
  --ink-strong: #444;
  --ink-soft: #777;
  --ink-faint: #9a9aa3;
  --ink-ghost: #c4c4cc;

  --panel: #f3f3f6;
  --panel-edge: #e3e3e9;
  --empty: #e6e6eb;

  --tile: 66px;
  --gap: 6px;
}

* { box-sizing: border-box; }

/* Chỉ trình đọc màn hình thấy. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html, body { height: 100%; }

body {
  margin: 0;
  background: #f3f3f5;
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--pink); }
a:hover { color: #ffcf33; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}

@keyframes bob {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}

@keyframes pop {
  0%   { transform: scale(1);   opacity: 1; }
  45%  { transform: scale(1.22); opacity: 1; }
  100% { transform: scale(0.35); opacity: 0; }
}

@keyframes draw {
  from { stroke-dashoffset: var(--len); }
  to   { stroke-dashoffset: 0; }
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 4px 0 var(--edge), 0 0 0 0 rgba(77, 216, 255, 0); }
  50%      { box-shadow: 0 4px 0 var(--edge), 0 0 0 6px rgba(77, 216, 255, 0.35); }
}

/* --- khung máy ------------------------------------------------------------ */

.stage {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}

.frame {
  flex: none;
  position: relative;
  background: #fff;
  border-radius: 36px;
  overflow: hidden;
  box-shadow: 0 0 0 12px #e9e9ee, 0 30px 80px rgba(0, 0, 0, 0.12);
  color: var(--ink);
  user-select: none;
  transform-origin: center center;
}

.screen {
  position: absolute;
  inset: 0;
  display: flex;
}

.screen[hidden] { display: none; }

/* --- nút kiểu kẹo --------------------------------------------------------- */

.candy {
  border: 0;
  border-radius: 8px;
  color: #fff;
  font-family: inherit;
  font-weight: 900;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--fill);
  box-shadow: 0 var(--lift, 6px) 0 var(--edge);
  transition: transform 0.08s, box-shadow 0.08s, filter 0.08s;
}

.candy:hover { filter: brightness(1.06); }

.candy:active,
.candy.is-pressed {
  transform: translateY(calc(var(--lift, 6px) - 2px));
  box-shadow: 0 2px 0 var(--edge);
}

.candy:disabled {
  cursor: default;
  filter: grayscale(0.55) brightness(1.02);
  opacity: 0.65;
}

.candy:disabled:active {
  transform: none;
  box-shadow: 0 var(--lift, 6px) 0 var(--edge);
}

.candy:focus-visible {
  outline: 3px solid #2f80ed;
  outline-offset: 3px;
}

.candy--yellow { --fill: var(--yellow); --edge: var(--yellow-edge); }
.candy--pink   { --fill: var(--pink);   --edge: var(--pink-edge); }
.candy--cyan   { --fill: var(--cyan);   --edge: var(--cyan-edge); }

/* --- màn hình menu -------------------------------------------------------- */

.menu {
  flex-direction: column;
  align-items: center;
  padding: 28px 36px 24px;
}

.menu__top {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pills, .toggles { display: flex; gap: 8px; }

.pill {
  --lift: 4px;
  height: 34px;
  padding: 0 12px;
  gap: 6px;
  font-size: 16px;
  cursor: default;
}

.pill__coin {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff6c2, #ffcf33 60%, #e0a300);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.55), 0 1px 1px rgba(0, 0, 0, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 900;
  color: #b57f00;
}

.toggle {
  --lift: 4px;
  width: 38px;
  height: 34px;
  font-size: 18px;
  position: relative;
}

.toggle--sound { font-size: 16px; }

/* Gạch chéo báo đang tắt. */
.toggle[aria-pressed='true']::after {
  content: '';
  position: absolute;
  width: 3px;
  height: 24px;
  background: #fff;
  transform: rotate(45deg);
  border-radius: 2px;
}

.menu__hero {
  width: 268px;
  height: 268px;
  border-radius: 56px;
  background: url('assets/fruit-hero.png') center / cover no-repeat;
  box-shadow: 0 14px 0 var(--panel-edge), 0 22px 40px rgba(0, 0, 0, 0.12);
}

.menu__modes {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.mode {
  --lift: 8px;
  height: 92px;
  border-radius: 10px;
  flex-direction: column;
}

.mode__name {
  font-weight: 900;
  font-size: 34px;
  letter-spacing: 4px;
  line-height: 1;
}

.mode__sub {
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 3px;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 4px;
}

.menu__hint {
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 3px;
  color: var(--ink-ghost);
  text-align: center;
}

.menu__best {
  font-weight: 800;
  font-size: 11px;
  letter-spacing: 2px;
  color: var(--ink-ghost);
  margin-bottom: 6px;
}

.spacer { flex: 1; }
.spacer--tall { flex: 1.2; }

/* --- màn hình chơi -------------------------------------------------------- */

.side {
  width: 270px;
  padding: 30px 0 30px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.stat {
  font-weight: 800;
  font-size: 22px;
  color: var(--ink-soft);
  display: flex;
  justify-content: space-between;
  width: 200px;
}

.stat--stacked {
  flex-direction: column;
  justify-content: flex-start;
  gap: 2px;
}

.stat__value { font-weight: 900; }
.stat__value--level { color: var(--ink-strong); }
.stat__value--score { color: var(--ink-ghost); font-style: italic; }
.stat__value--lives { color: var(--pink); }

.stat__label-row {
  display: flex;
  justify-content: space-between;
  width: 200px;
}

.stat__seconds {
  font-weight: 900;
  font-size: 18px;
  color: var(--ink-ghost);
  font-variant-numeric: tabular-nums;
}

.timebar {
  height: 18px;
  border-radius: 9px;
  background: #efeff3;
  overflow: hidden;
  width: 200px;
}

.timebar__fill {
  height: 100%;
  border-radius: 9px;
  background: linear-gradient(90deg, #4dd8ff, #2fb344, #ffd63a, #f97316, #ff4b7a);
  transition: width 0.12s linear;
}

.timebar--low .timebar__fill { animation: pulse 0.8s ease-in-out infinite; }

.side__actions {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 200px;
}

.action {
  height: 46px;
  gap: 10px;
  font-size: 18px;
  letter-spacing: 1px;
}

.action__count {
  background: rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  padding: 0 8px;
  font-size: 14px;
}

.play {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-right: 30px;
}

.board-panel {
  position: relative;
  background: var(--panel);
  padding: 12px;
  border-radius: 24px;
  box-shadow: 0 8px 0 var(--panel-edge);
}

.board {
  position: relative;
  display: grid;
  gap: var(--gap);
  grid-template-columns: repeat(var(--cols), var(--tile));
}

.tile {
  width: var(--tile);
  height: var(--tile);
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 4px 0 var(--edge);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s, background 0.12s, box-shadow 0.12s;
}

.tile__art {
  display: block;
  width: calc(var(--tile) - 6px);
  height: calc(var(--tile) - 6px);
  pointer-events: none;
  background-image: url('assets/fruit-sprite.png');
  background-repeat: no-repeat;
  /* Sprite sheet 5x5: phóng to gấp 5 lần ô để mỗi ô vừa khít. */
  background-size: calc((var(--tile) - 6px) * 5) calc((var(--tile) - 6px) * 5);
  background-position: calc(var(--sx) * (var(--tile) - 6px) * -1) calc(var(--sy) * (var(--tile) - 6px) * -1);
  transition: filter 0.12s;
}

.tile:focus-visible {
  outline: 3px solid #2f80ed;
  outline-offset: 2px;
}

.tile.is-empty {
  background: var(--empty);
  box-shadow: none;
  cursor: default;
}

.tile.is-empty .tile__art { visibility: hidden; }

.tile.is-selected {
  background: #fff7cf;
  box-shadow: 0 4px 0 #ffb400;
  transform: translateY(-3px);
}

.tile.is-selected .tile__art { filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3)); }

.tile.is-hint {
  background: #e6fbff;
  animation: pulse 0.9s ease-in-out infinite;
}

.tile.is-bad { animation: shake 0.3s; }

.tile.is-vanishing {
  animation: pop 0.28s ease-in forwards;
  pointer-events: none;
}

/* Nét nối, vẽ đè lên bàn và được phép tràn ra ngoài rìa. */
.board__path {
  position: absolute;
  pointer-events: none;
  overflow: visible;
  z-index: 2;
}

.board__path polyline {
  fill: none;
  stroke: #ff4b7a;
  stroke-width: 6;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.18));
  animation: draw 0.16s linear;
}

.board__path polyline.glow {
  stroke: #fff;
  stroke-width: 12;
  opacity: 0.9;
}

.back {
  position: absolute;
  right: 24px;
  top: 22px;
  border: 0;
  background: none;
  font-family: inherit;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 2px;
  color: var(--ink-ghost);
  cursor: pointer;
  padding: 4px 6px;
}

.back:hover { color: var(--ink-soft); }

.credit {
  position: absolute;
  left: 290px;
  bottom: 12px;
  font: 10px/1.4 ui-monospace, monospace;
  color: var(--ink-ghost);
}

/* --- lớp phủ (thắng / hết giờ / tạm dừng) --------------------------------- */

.overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
}

.overlay[hidden] { display: none; }

.overlay__box {
  width: 400px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}

.overlay__big {
  font-weight: 900;
  font-size: 64px;
  color: var(--ink-strong);
  line-height: 1;
  animation: bob 1.6s ease-in-out infinite;
}

.overlay__title {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 3px;
  color: var(--ink-ghost);
}

.overlay__sub {
  font-weight: 800;
  font-size: 14px;
  color: var(--ink-faint);
  margin-bottom: 22px;
}

.overlay__btn {
  --lift: 8px;
  width: 320px;
  height: 64px;
  font-size: 26px;
  letter-spacing: 2px;
}

.overlay__btn + .overlay__btn { margin-top: 12px; }

@media (prefers-reduced-motion: reduce) {
  .overlay__big,
  .tile.is-hint,
  .timebar--low .timebar__fill { animation: none; }
  .board__path polyline { animation: none; }
  .tile { transition: background 0.12s; }
}
