body:has(.c48) {
  background: #0d151b;
  color: #eaf3f1;
}

body:has(.c48) > header {
  max-width: 560px;
  padding-bottom: 12px;
}

body:has(.c48) > header a {
  color: #9dafaf;
  font-size: 13px;
}

main:has(.c48) {
  max-width: 560px;
  background: transparent;
  padding-top: 12px;
}

.c48 {
  --accent: #7ee0c3;
  --muted: #9bafba;
  --panel: #17242d;
  --line: #2b3e49;
  --gap: clamp(6px, 2.2vw, 11px);
  --slide: 120ms;
  width: 100%;
}

.c48-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.c48-eyebrow {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .18em;
  color: var(--muted);
}

.c48-head h1 {
  margin: 0;
  font-size: 40px;
  line-height: 1.1;
  letter-spacing: .06em;
}

.c48-head h1 span {
  margin-left: 14px;
  font-size: 12px;
  font-weight: 400;
  letter-spacing: .12em;
  color: var(--muted);
}

.c48-tag {
  margin: 0;
  font-size: 13px;
  color: var(--accent);
  text-align: right;
}

.c48-bar {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.c48-stat {
  position: relative;
  padding: 10px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.c48-stat span {
  display: block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .14em;
  color: var(--muted);
}

.c48-stat strong {
  display: block;
  font-size: 24px;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.c48-stat em {
  position: absolute;
  right: 12px;
  bottom: 10px;
  font-size: 14px;
  font-style: normal;
  font-weight: 700;
  color: var(--accent);
  opacity: 0;
  pointer-events: none;
}

.c48-stat em.show {
  animation: c48-gain .7s ease-out;
}

.c48 button {
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: #eaf3f1;
  background: #213440;
  border: 1px solid #3b515e;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background .15s;
}

.c48 button:hover:not(:disabled) {
  background: #304a59;
}

.c48 button:focus-visible,
.c48-board:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.c48 button:disabled {
  opacity: .4;
  cursor: default;
}

.c48 .c48-primary {
  color: #0b2a21;
  background: var(--accent);
  border-color: var(--accent);
}

.c48 .c48-primary:hover:not(:disabled) {
  background: #a0efd9;
}

.c48-actions {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.c48-actions button {
  flex: 1;
}

/* ---- 盤面 ---- */
.c48-board-wrap {
  position: relative;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
}

.c48-board {
  position: relative;
  aspect-ratio: 1;
  width: 100%;
  padding: calc(var(--gap) / 2);
  background: #0b131b;
  border: 1px solid #3a515d;
  border-radius: 14px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, .3);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.c48-grid,
.c48-tiles {
  position: absolute;
  inset: calc(var(--gap) / 2);
}

.c48-grid {
  display: grid;
  grid-template: repeat(4, 1fr) / repeat(4, 1fr);
}

.c48-cell {
  padding: calc(var(--gap) / 2);
}

.c48-cell::before {
  content: '';
  display: block;
  width: 100%;
  height: 100%;
  background: #15252f;
  border-radius: 9px;
}

.c48-tiles {
  container-type: size;
}

.c48-tile {
  position: absolute;
  top: 0;
  left: 0;
  width: 25%;
  height: 25%;
  padding: calc(var(--gap) / 2);
  transform: translate(calc(var(--c, 0) * 100%), calc(var(--r, 0) * 100%));
  transition: transform var(--slide) ease-out;
  will-change: transform;
}

.c48-tile-inner {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: 9cqw;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: #fff;
  background: #274150;
  border-radius: 9px;
}

.c48-tile-inner[data-digits="3"] { font-size: 7.4cqw; }
.c48-tile-inner[data-digits="4"] { font-size: 6cqw; }
.c48-tile-inner[data-digits="5"] { font-size: 4.8cqw; }

.c48-tile[data-level="1"] .c48-tile-inner { background: #274150; color: #d9eef5; }
.c48-tile[data-level="2"] .c48-tile-inner { background: #2d5566; color: #e5f4f8; }
.c48-tile[data-level="3"] .c48-tile-inner { background: #2f7a8a; }
.c48-tile[data-level="4"] .c48-tile-inner { background: #24977f; }
.c48-tile[data-level="5"] .c48-tile-inner { background: #35b57f; color: #06241a; }
.c48-tile[data-level="6"] .c48-tile-inner { background: #86cc55; color: #14260a; }
.c48-tile[data-level="7"] .c48-tile-inner { background: #d6d349; color: #2a2807; box-shadow: 0 0 14px rgba(214, 211, 73, .35); }
.c48-tile[data-level="8"] .c48-tile-inner { background: #f2b84b; color: #2e1d03; box-shadow: 0 0 16px rgba(242, 184, 75, .4); }
.c48-tile[data-level="9"] .c48-tile-inner { background: #f59a45; color: #2e1503; box-shadow: 0 0 18px rgba(245, 154, 69, .45); }
.c48-tile[data-level="10"] .c48-tile-inner { background: #f2724a; box-shadow: 0 0 20px rgba(242, 114, 74, .5); }
.c48-tile[data-level="11"] .c48-tile-inner { background: #ef4a6a; box-shadow: 0 0 26px rgba(239, 74, 106, .65); }
.c48-tile[data-level="12"] .c48-tile-inner { background: #a855e8; box-shadow: 0 0 28px rgba(168, 85, 232, .7); }

.c48-tile-inner.is-new {
  animation: c48-appear .16s ease-out;
}

.c48-tile-inner.is-merged {
  animation: c48-pop .16s ease-out;
}

/* ---- オーバーレイ ---- */
.c48-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 20px;
  text-align: center;
  background: rgba(11, 19, 27, .88);
  border-radius: 14px;
}

.c48-overlay[hidden] {
  display: none;
}

.c48-overlay-title {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
}

.c48-overlay-desc {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
}

.c48-overlay-buttons {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

/* ---- 補助 ---- */
.c48-pad {
  display: none;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-width: 480px;
  margin: 14px auto 0;
}

.c48-pad button {
  font-size: 20px;
  padding: 12px 0;
}

@media (pointer: coarse) {
  .c48-pad {
    display: grid;
  }
}

.c48-status {
  min-height: 1.6em;
  margin: 12px 0 0;
  font-size: 12px;
  text-align: center;
  color: var(--accent);
}

.c48-note {
  margin: 0;
  font-size: 11px;
  text-align: center;
  color: var(--muted);
}

.c48-how {
  max-width: 480px;
  margin: 14px auto 0;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.c48-how h2 {
  margin: 0 0 8px;
  font-size: 13px;
  color: #eaf3f1;
}

.c48-how dl {
  margin: 0;
  font-size: 12px;
}

.c48-how dl div {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.c48-how dt {
  font-family: monospace;
  color: #dce8e8;
}

.c48-how dd {
  margin: 0;
}

.c48-how p {
  margin: 8px 0 0;
  font-size: 11px;
  line-height: 1.6;
}

@keyframes c48-appear {
  from { transform: scale(.3); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes c48-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

@keyframes c48-gain {
  0% { opacity: 1; transform: translateY(0); }
  100% { opacity: 0; transform: translateY(-18px); }
}

@media (max-width: 600px) {
  main:has(.c48) {
    margin: 0;
    padding: 12px;
  }
  .c48-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    margin-bottom: 14px;
  }
  .c48-head h1 {
    font-size: 32px;
  }
  .c48-tag {
    text-align: left;
    font-size: 12px;
  }
  .c48-stat {
    padding: 8px 10px;
  }
  .c48-stat strong {
    font-size: 20px;
  }
  .c48-overlay-title {
    font-size: 21px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .c48 {
    --slide: 0ms;
  }
  .c48-tile-inner.is-new,
  .c48-tile-inner.is-merged,
  .c48-stat em.show {
    animation: none;
  }
  .c48 button {
    transition: none;
  }
}
