:root {
  color-scheme: light;
  --paper: #faf7f0;
  --ink: #23221f;
  --muted: #6e6a61;
  --line: #cfc6b5;
  --tile: #fffdf8;
  --tile-2: #f1eadc;
  --selected: #0e7490;
  --matched: #7c8a1f;
  --accent: #b45309;
  --shadow: 0 14px 28px rgba(55, 42, 24, 0.12);
  --tile-w: 60px;
  --tile-h: 84px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(14, 116, 144, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(180, 83, 9, 0.16), transparent 38%),
    var(--paper);
  color: var(--ink);
  font-family: "Yu Gothic UI", "Hiragino Sans", Meiryo, system-ui, sans-serif;
}

button {
  font: inherit;
}

.app {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 20px clamp(10px, 2vw, 22px) 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.topbar > div:first-child {
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 18px;
  flex-wrap: wrap;
}

h1 {
  margin: 0;
  font-family: "HGS行書体", "HGP行書体", "Yu Mincho", "YuMincho", "Hiragino Mincho ProN", serif;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1;
  letter-spacing: 0;
  font-weight: 800;
  color: #17130d;
  text-shadow:
    0 2px 0 rgba(180, 83, 9, 0.18),
    0 8px 18px rgba(23, 19, 13, 0.18);
}

p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.gameIntro {
  max-width: 720px;
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 1.5;
}

.actions {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}

.actions button {
  width: 44px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.82);
  color: var(--ink);
  cursor: pointer;
  font-size: 22px;
  font-weight: 800;
  box-shadow: 0 6px 16px rgba(55, 42, 24, 0.08);
}

.actions button:hover {
  border-color: var(--accent);
}

.actions button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.status {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.status > div {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 9px 2px;
}

.label {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.status strong {
  font-size: 22px;
}

.combo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
  min-height: 27px;
  padding: 2px 10px;
  border: 1px solid rgba(180, 83, 9, 0.34);
  border-radius: 999px;
  background: rgba(250, 204, 21, 0.18);
  color: #92400e;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
}

.combo strong {
  color: #dc2626;
  font-size: 18px;
  font-weight: 950;
  line-height: 1;
}

.combo[hidden] {
  display: none;
}

.boardWrap {
  position: relative;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 34%),
    #1f6f4a;
  box-shadow: var(--shadow);
  overflow: auto;
}

.boardWrap.paused::after {
  content: "一時停止中";
  position: absolute;
  inset: 18px;
  z-index: 8;
  display: grid;
  place-items: center;
  background: rgba(250, 247, 240, 0.92);
  color: var(--ink);
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0;
  pointer-events: none;
}

.board {
  display: grid;
  grid-template-columns: repeat(17, var(--tile-w));
  grid-template-rows: repeat(8, var(--tile-h));
  gap: 0;
  width: max-content;
  margin: 0 auto;
}

.connectionLine {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 5;
  overflow: visible;
  pointer-events: none;
}

.connectionLine polyline {
  fill: none;
  stroke: rgba(14, 116, 144, 0.92);
  stroke-width: 5;
  stroke-linecap: round;
  stroke-linejoin: round;
  filter: drop-shadow(0 0 5px rgba(255, 253, 248, 0.92));
}

.connectionLine .connectionGlow {
  stroke: rgba(250, 204, 21, 0.84);
  stroke-width: 9;
  opacity: 0.7;
}

.firework {
  position: absolute;
  z-index: 7;
  width: 0;
  height: 0;
  pointer-events: none;
}

.fireworkParticle {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--size);
  height: var(--size);
  border-radius: 999px;
  background: #facc15;
  box-shadow:
    0 0 6px rgba(250, 204, 21, 0.85),
    0 0 12px rgba(14, 116, 144, 0.42);
  transform: translate(-50%, -50%) scale(0.4);
  animation: fireworkBurst 560ms ease-out forwards;
}

.fireworkParticle:nth-child(3n + 1) {
  background: #0e7490;
}

.fireworkParticle:nth-child(3n + 2) {
  background: #dc2626;
}

@keyframes fireworkBurst {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.4);
  }

  22% {
    opacity: 1;
  }

  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1);
  }
}

.tile {
  display: grid;
  place-items: center;
  position: relative;
  padding: 0;
  width: var(--tile-w);
  height: var(--tile-h);
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #25231f;
  cursor: pointer;
  overflow: hidden;
  user-select: none;
  font-size: 16px;
  font-weight: 800;
  line-height: 1;
  box-shadow: none;
  transition: opacity 120ms ease;
}

.tileImage {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

.tile:hover {
  opacity: 0.86;
}

.tile.selected {
  z-index: 2;
}

.tile.hint {
  z-index: 2;
}

.tile.selected::after,
.tile.hint::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 3px solid rgba(14, 116, 144, 0.72);
  pointer-events: none;
}

.tile.hint::after {
  border-color: rgba(124, 138, 31, 0.68);
}

.tile.empty {
  visibility: hidden;
  pointer-events: none;
}

.tile.clearing {
  opacity: 0.35;
  transform: scale(0.9);
}

.message {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 10;
  min-width: min(460px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.98), rgba(250, 247, 240, 0.96));
  padding: 20px;
  text-align: center;
  font-weight: 800;
  box-shadow:
    0 22px 48px rgba(31, 41, 32, 0.2),
    0 0 0 4px rgba(255, 253, 248, 0.42);
}

.clearResult {
  display: grid;
  gap: 10px;
  text-align: center;
}

.clearSummary,
.scorePanel,
.rankingPanel {
  border: 1px solid rgba(207, 198, 181, 0.9);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.82);
  padding: 11px 14px;
}

.clearSummary {
  background:
    linear-gradient(135deg, rgba(250, 204, 21, 0.16), transparent 48%),
    rgba(255, 253, 248, 0.9);
}

.clearTitle {
  font-size: 21px;
}

.clearComment {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.scorePanel {
  display: grid;
  gap: 4px;
}

.scoreLabel {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0;
}

.clearScore {
  color: #991b1b;
  font-size: 34px;
  font-weight: 900;
  line-height: 1;
}

.bestUpdated {
  color: #b45309;
  font-size: 18px;
  font-weight: 900;
}

.bestRank,
.rankingTitle {
  color: var(--muted);
  font-size: 13px;
}

.rankingTitle {
  margin-bottom: 7px;
  font-weight: 900;
}

.clearResult ol {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  text-align: left;
  list-style-position: inside;
}

.clearResult li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: baseline;
  border-top: 1px solid rgba(207, 198, 181, 0.58);
  padding-top: 5px;
}

.clearResult li strong {
  color: var(--ink);
}

.clearResult li span,
.clearResult li small {
  color: var(--muted);
  font-size: 12px;
}

.message button {
  display: inline-block;
  margin-top: 12px;
  padding: 8px 14px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: #fffdf8;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
}

.message button:hover {
  background: #f8ead8;
}

.credits {
  margin-top: 10px;
  color: var(--muted);
  font-size: 11px;
  text-align: right;
}

@media (max-width: 620px) {
  :root {
    --tile-w: 23px;
    --tile-h: 32px;
  }

  .app {
    padding-inline: 6px;
  }

  .topbar {
    align-items: flex-end;
  }

  .topbar > div:first-child {
    display: block;
  }

  .gameIntro {
    margin-top: 6px;
  }

  .actions button {
    width: 40px;
    height: 40px;
  }

  .status strong {
    font-size: 19px;
  }

  .boardWrap {
    padding: 12px;
  }

  .boardWrap.paused::after {
    inset: 12px;
    font-size: 20px;
  }

  .board {
    margin: 0;
  }

}
