/* Kambana OS - 2048 */
.app-g2048 { display: flex; flex-direction: column; background: var(--surface); outline: none; position: relative; container-type: inline-size; }
.app-g2048 .g2-head { display: flex; align-items: center; gap: 12px; padding: 14px 16px 6px; }
.app-g2048 .g2-brand { display: flex; align-items: center; gap: 12px; min-width: 0; flex: 1; }
.app-g2048 .g2-logo {
  font-family: var(--font-display); font-weight: 800; font-size: 22px; letter-spacing: -.5px; color: #fff;
  width: 64px; height: 64px; border-radius: 16px; display: grid; place-items: center; flex: 0 0 auto;
  background: linear-gradient(140deg, #fbbf24, #ea580c 70%, #c2410c); box-shadow: 0 8px 20px -8px rgba(234, 88, 12, .7), inset 0 1px 0 rgba(255, 255, 255, .35);
}
.app-g2048 .g2-sub { display: flex; flex-direction: column; gap: 2px; font-size: 13px; color: var(--text-2); min-width: 0; }
.app-g2048 .g2-time { font-family: var(--font-display); font-size: 15px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.app-g2048 .g2-scores { display: flex; gap: 8px; }
.app-g2048 .g2-score {
  position: relative; min-width: 78px; padding: 7px 12px 6px; border-radius: 12px; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--line);
  display: flex; flex-direction: column; align-items: center;
}
.app-g2048 .g2-score small { font-size: 11px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; }
.app-g2048 .g2-score b { font-family: var(--font-display); font-size: 20px; font-variant-numeric: tabular-nums; line-height: 1.15; }
.app-g2048 .g2-add { position: absolute; left: 0; right: 0; top: 10px; text-align: center; font-family: var(--font-display); font-weight: 700; color: #ea580c; opacity: 0; pointer-events: none; }
.app-g2048 .g2-add.show { animation: g2-float .7s var(--ease) forwards; }
@keyframes g2-float { 0% { opacity: 1; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-28px); } }
.app-g2048 .g2-bar { display: flex; align-items: center; gap: 4px; padding: 6px 14px; }
.app-g2048 .g2-btn.on { color: #e5484d; }
.app-g2048 .g2-stage { flex: 1; min-height: 0; display: grid; place-items: center; padding: 6px 12px; }
@media (max-width: 759px) { .app-g2048 .g2-stage { place-items: start center; padding-top: 16px; } }
.app-g2048 .g2-foot { text-align: center; font-size: 12px; color: var(--text-3); padding: 4px 12px 12px; }
.app-g2048 .g2-foot .kbd { margin: 0 1px; }

.app-g2048 .g2-board {
  --gap: 12px; --fs: 80px;
  position: relative; width: 400px; height: 400px; border-radius: calc(var(--gap) * 1.2);
  background: color-mix(in srgb, var(--surface-3) 94%, #0f766e 6%); box-shadow: inset 0 0 0 1px var(--line), 0 16px 40px -24px rgba(0, 0, 0, .5);
  touch-action: none; user-select: none; -webkit-user-select: none;
}
.app-g2048 .g2-cells, .app-g2048 .g2-tiles { position: absolute; inset: var(--gap); }
.app-g2048 .g2-cells { display: grid; grid-template-columns: repeat(4, 1fr); grid-template-rows: repeat(4, 1fr); gap: var(--gap); }
.app-g2048 .g2-cell { border-radius: calc(var(--gap) * .8); background: var(--tile); }
.app-g2048 .g2-tile {
  position: absolute; left: 0; top: 0; width: calc((100% - 3 * var(--gap)) / 4); height: calc((100% - 3 * var(--gap)) / 4);
  transform: translate(calc(var(--c) * (100% + var(--gap))), calc(var(--r) * (100% + var(--gap))));
  transition: transform 110ms ease-in-out; z-index: 2;
}
.app-g2048 .g2-tile.ghost { z-index: 1; }
.app-g2048 .g2-tile > span {
  position: absolute; inset: 0; display: grid; place-items: center; border-radius: calc(var(--gap) * .8);
  font-family: var(--font-display); font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums;
  font-size: calc(var(--fs) * (0.62 - 0.07 * var(--len, 1)));
  background: var(--bg); color: var(--fg, #fff); box-shadow: var(--glow, none), inset 0 -3px 0 rgba(0, 0, 0, .12), inset 0 1px 0 rgba(255, 255, 255, .3);
}
.app-g2048 .g2-tile.new > span { animation: g2-appear 180ms var(--ease) both; }
.app-g2048 .g2-tile.new.wait > span { animation: none; transform: scale(0); opacity: 0; }
.app-g2048 .g2-tile.pop > span { animation: g2-pop 200ms var(--ease) both; }
@keyframes g2-appear { 0% { transform: scale(.1); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes g2-pop { 0% { transform: scale(1); } 45% { transform: scale(1.16); } 100% { transform: scale(1); } }

/* tile colours: mint → teal → sky → amber → coral → rose → magenta → violet → indigo → gold */
.app-g2048 .v2 > span { --bg: #e3f1ee; --fg: #2c4a45; }
.app-g2048 .v4 > span { --bg: #c9e8e1; --fg: #22433d; }
.app-g2048 .v8 > span { --bg: linear-gradient(150deg, #5eead4, #14b8a6); }
.app-g2048 .v16 > span { --bg: linear-gradient(150deg, #38bdf8, #0ea5e9); }
.app-g2048 .v32 > span { --bg: linear-gradient(150deg, #fcd34d, #f59e0b); --fg: #3b2300; }
.app-g2048 .v64 > span { --bg: linear-gradient(150deg, #fb923c, #ea580c); }
.app-g2048 .v128 > span { --bg: linear-gradient(150deg, #fb7185, #e11d48); --glow: 0 0 18px -4px rgba(225, 29, 72, .55); }
.app-g2048 .v256 > span { --bg: linear-gradient(150deg, #f472b6, #db2777); --glow: 0 0 20px -4px rgba(219, 39, 119, .6); }
.app-g2048 .v512 > span { --bg: linear-gradient(150deg, #c084fc, #9333ea); --glow: 0 0 22px -4px rgba(147, 51, 234, .65); }
.app-g2048 .v1024 > span { --bg: linear-gradient(150deg, #818cf8, #4338ca); --glow: 0 0 26px -4px rgba(79, 70, 229, .75); }
.app-g2048 .v2048 > span { --bg: linear-gradient(150deg, #fde047, #f59e0b 60%, #d97706); --fg: #3b2300; --glow: 0 0 34px -2px rgba(250, 204, 21, .85); }
.app-g2048 .vbig > span { --bg: linear-gradient(150deg, #334155, #0f172a); --glow: 0 0 26px -4px rgba(250, 204, 21, .6); --fg: #fde68a; }
[data-theme="dark"] .app-g2048 .v2 > span { --bg: #d5e8e4; }
[data-theme="dark"] .app-g2048 .v4 > span { --bg: #b5ddd4; }

.app-g2048 .g2-hint { position: absolute; inset: 0; display: grid; place-items: center; pointer-events: none; color: #fff; opacity: 0; z-index: 5; }
.app-g2048 .g2-hint .ic { filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .45)); }
.app-g2048 .g2-hint.show { animation: g2-hint 1.4s var(--ease) both; }
.app-g2048 .g2-hint.down .ic { transform: rotate(180deg); }
@keyframes g2-hint { 0% { opacity: 0; transform: scale(.7); } 15% { opacity: .95; transform: scale(1); } 75% { opacity: .95; } 100% { opacity: 0; } }

.app-g2048 .nudge-left { animation: g2-nl .18s; } .app-g2048 .nudge-right { animation: g2-nr .18s; }
.app-g2048 .nudge-up { animation: g2-nu .18s; } .app-g2048 .nudge-down { animation: g2-nd .18s; }
@keyframes g2-nl { 50% { transform: translateX(-5px); } } @keyframes g2-nr { 50% { transform: translateX(5px); } }
@keyframes g2-nu { 50% { transform: translateY(-5px); } } @keyframes g2-nd { 50% { transform: translateY(5px); } }

.app-g2048 .g2-overlay {
  position: absolute; inset: 0; z-index: 20; border-radius: inherit; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 20px; text-align: center; background: color-mix(in srgb, var(--surface) 78%, transparent);
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px); opacity: 0; transition: opacity .3s;
}
.app-g2048 .g2-overlay.show { opacity: 1; }
.app-g2048 .g2-overlay[hidden] { display: none; }
.app-g2048 .g2-overlay h2 { margin: 0; font-family: var(--font-display); font-size: 30px; }
.app-g2048 .g2-overlay.win h2 { background: linear-gradient(90deg, #f59e0b, #e11d48, #9333ea); -webkit-background-clip: text; background-clip: text; color: transparent; }
.app-g2048 .g2-overlay p { margin: 0; color: var(--text-2); font-size: 14px; max-width: 300px; }
.app-g2048 .g2-ov-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; justify-content: center; }
.app-g2048 .g2-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: 8px; width: 100%; max-width: 360px; margin-top: 6px; }
.app-g2048 .g2-stats > div { background: var(--surface-2); border-radius: 12px; padding: 10px 6px; display: flex; flex-direction: column; align-items: center; box-shadow: inset 0 0 0 1px var(--line); }
.app-g2048 .g2-stats b { font-family: var(--font-display); font-size: 20px; }
.app-g2048 .g2-stats small { font-size: 11.5px; color: var(--text-2); }

.reduce-motion .app-g2048 .g2-tile { transition: none; }
.reduce-motion .app-g2048 .g2-tile > span { animation: none !important; }
.reduce-motion .app-g2048 .g2-board { animation: none !important; }

@container (max-width: 420px) {
  .app-g2048 .g2-sub > span:first-child { display: none; }
  .app-g2048 .g2-logo { width: 52px; height: 52px; font-size: 18px; border-radius: 14px; }
  .app-g2048 .g2-score { min-width: 64px; padding: 6px 8px; }
  .app-g2048 .g2-foot { display: none; }
}
