:root {
  --page: #1a1b22;
  --surface: #24252c;
  --surface-raised: #2c2d35;
  --ink: #f1f1f4;
  --muted: rgba(241, 241, 244, 0.6);
  --blue: #4da3ff;
  --blue-soft: #8cc4ff;
  --amber: #f2b45c;
  --error: #ff6b6b;
  --thin-line: rgba(255, 255, 255, 0.07);
  --box-line: rgba(255, 255, 255, 0.3);
  --header-height: 58px;
  --footer-height: 24px;
  --viewport-height: 100vh;
}

@supports (height: 100svh) {
  :root {
    --viewport-height: 100svh;
  }
}

* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(ellipse at 50% 20%, #23252e, var(--page) 70%) no-repeat, var(--page);
  background-size: 100% var(--viewport-height), auto;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: var(--header-height);
  padding: 10px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(0, 0, 0, 0.18);
  user-select: none;
}

.header-start {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.home-link {
  position: relative;
  display: flex;
  align-items: center;
  padding-right: 14px;
  border-right: 1px solid rgba(255, 255, 255, 0.15);
  transition: opacity 0.15s;
}

.home-link:hover {
  opacity: 0.8;
}

.home-link-mark {
  display: block;
  width: 30px;
  height: 30px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(135deg, #ef6f5e, #f2b544 45%, #47c99a);
  color: #fff;
}

h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 750;
  white-space: nowrap;
}

.stats {
  display: flex;
  gap: 6px;
  margin: 0;
}

.stat {
  min-width: 70px;
  padding: 5px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
  text-align: center;
}

.stat-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.6;
}

.stat-value {
  margin: 0;
  font-size: 16px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

.mode-picker {
  display: flex;
  gap: 2px;
  padding: 3px;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.05);
}

.mode-option {
  position: relative;
  cursor: pointer;
}

.mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-option span {
  display: block;
  padding: 6px 11px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 650;
  opacity: 0.7;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}

.mode-option:hover span {
  opacity: 1;
}

.mode-option input:checked + span {
  background: var(--ink);
  color: #1d1d27;
  opacity: 1;
}

.mode-option input:focus-visible + span {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

.new-game-button {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: var(--blue);
  color: #0c1726;
  font-size: 14px;
  font-weight: 700;
  transition: background 0.15s, transform 0.1s;
}

.new-game-button:hover {
  background: #6cb4ff;
}

.new-game-button:active {
  transform: scale(0.96);
}

kbd {
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.12);
  font-family: inherit;
  font-size: 10px;
  font-weight: 600;
}

.ghost-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  opacity: 0.85;
}

.ghost-button:hover {
  background: rgba(255, 255, 255, 0.1);
  opacity: 1;
}

#table {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  min-height: calc(var(--viewport-height) - var(--header-height) - var(--footer-height));
  padding: 16px 16px 18px;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.play-area {
  --board-size: min(500px, calc(100vw - 32px), calc((var(--viewport-height) - var(--header-height) - var(--footer-height) - 110px) * 0.75));
  --tray-cell: calc(var(--board-size) / 17);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.status {
  width: var(--board-size);
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.board-wrap {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
}

.board {
  --pad: calc(var(--board-size) * 0.022);
  --gap: calc(var(--board-size) * 0.0075);
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(10, 1fr);
  gap: var(--gap);
  width: 100%;
  height: 100%;
  padding: var(--pad);
  border-radius: calc(var(--pad) * 1.6);
  background: linear-gradient(160deg, #1f2029, #15161c);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 24px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  transition: filter 0.4s;
}

.board.is-over {
  filter: saturate(0.35) brightness(0.8);
}

.board.is-shaking {
  animation: board-combo 0.5s cubic-bezier(0.3, 0.7, 0.3, 1);
}

@keyframes board-combo {
  0%,
  100% {
    transform: translateX(0);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 24px 60px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.05);
  }
  15% {
    transform: translateX(-6px);
    box-shadow: 0 0 0 2px rgba(255, 224, 138, 0.8), 0 0 40px rgba(255, 224, 138, 0.35), inset 0 0 30px rgba(255, 224, 138, 0.18);
  }
  35% {
    transform: translateX(5px);
  }
  55% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(2px);
  }
}

.cell {
  --tint: transparent;
  position: relative;
  border-radius: 20%;
  background: rgba(255, 255, 255, 0.04);
  box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.45);
}

.block {
  border-radius: 20%;
  background: linear-gradient(150deg, color-mix(in srgb, var(--tint) 62%, #fff) 0%, var(--tint) 42%, color-mix(in srgb, var(--tint) 72%, #000) 100%);
  box-shadow: inset 0 2px 1px rgba(255, 255, 255, 0.35), inset 0 -3px 2px rgba(0, 0, 0, 0.22), 0 2px 3px rgba(0, 0, 0, 0.3);
}

.cell.block::after {
  content: "";
  position: absolute;
  inset: 22% 22% 48% 22%;
  border-radius: 40%;
  background: rgba(255, 255, 255, 0.16);
}

.cell.ghost {
  background: color-mix(in srgb, var(--ghost-tint) 38%, transparent);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--ghost-tint) 80%, #fff);
}

.cell.ghost-invalid {
  background: rgba(255, 107, 107, 0.16);
  box-shadow: inset 0 0 0 2px rgba(255, 107, 107, 0.5);
}

.cell.ghost-invalid.block {
  filter: brightness(0.75);
}

.cell.will-clear {
  z-index: 1;
  outline: 2px solid color-mix(in srgb, var(--ghost-tint) 50%, #fff);
  outline-offset: -1px;
}

.cell.will-clear.block {
  --tint: var(--ghost-tint);
  filter: brightness(1.15);
}

.cell.just-placed {
  animation: block-drop 0.22s cubic-bezier(0.3, 1.4, 0.5, 1);
}

.cell.clearing {
  z-index: 2;
  animation: block-clear var(--clear-ms) ease-in var(--clear-delay) forwards;
}

@keyframes block-drop {
  from {
    transform: scale(0.82);
  }
}

@keyframes block-clear {
  30% {
    filter: brightness(1.8);
    transform: scale(1.12);
  }
  100% {
    opacity: 0;
    filter: brightness(2);
    transform: scale(0.2) rotate(18deg);
  }
}

.popup-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.score-popup {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  transform: translate(-50%, -50%);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
  white-space: nowrap;
  animation: popup-rise 0.9s ease-out forwards;
}

.popup-points {
  color: #fff;
  font-size: 18px;
  font-weight: 800;
}

.score-popup.is-big .popup-points {
  color: #ffe08a;
  font-size: 26px;
}

.popup-tag {
  color: #9ef0d2;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

@keyframes popup-rise {
  0% {
    opacity: 0;
    transform: translate(-50%, -30%) scale(0.8);
  }
  15% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.05);
  }
  70% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -140%) scale(1);
  }
}

.tray {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: var(--board-size);
  height: calc(var(--tray-cell) * 5.6 + 16px);
}

.tray-slot {
  display: grid;
  place-items: center;
  min-width: 0;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  touch-action: none;
  cursor: grab;
  transition: background 0.15s, border-color 0.15s, opacity 0.2s;
}

.tray-slot:disabled {
  cursor: default;
}

.tray-slot:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.06);
}

.tray-slot:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.tray-slot.is-selected {
  border-color: rgba(255, 255, 255, 0.4);
  background: rgba(255, 255, 255, 0.08);
}

.tray-slot.is-dragging .piece {
  visibility: hidden;
}

.tray-slot.no-fit .piece {
  opacity: 0.32;
  filter: grayscale(0.7);
}

.piece,
.drag-piece {
  display: grid;
  grid-template-columns: repeat(var(--columns), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
  gap: var(--gap);
}

.piece {
  --slot-inner-width: calc((var(--board-size) - 16px) / 3 - 16px);
  --cell: min(var(--tray-cell), calc(var(--slot-inner-width) / (var(--columns) * 1.1 - 0.1)));
  --gap: calc(var(--cell) * 0.1);
  pointer-events: none;
  transition: opacity 0.2s, filter 0.2s;
}

.piece.is-arriving {
  animation: piece-arrive 0.32s cubic-bezier(0.2, 1.3, 0.4, 1) var(--arrive-delay) backwards;
}

@keyframes piece-arrive {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.6);
  }
}

.drag-piece {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  pointer-events: none;
  filter: drop-shadow(0 12px 16px rgba(0, 0, 0, 0.45));
  will-change: transform;
}

.rules-note {
  margin: 0;
  font-size: 12px;
  text-align: center;
  opacity: 0.5;
}

.stat {
  position: relative;
}

.score-bump {
  position: absolute;
  top: 50%;
  left: 50%;
  color: #5ee0d6;
  font-size: 15px;
  font-weight: 800;
  pointer-events: none;
  white-space: nowrap;
  animation: score-rise 0.75s ease-out forwards;
}

@keyframes score-rise {
  from {
    opacity: 1;
    transform: translate(-50%, -20%);
  }
  to {
    opacity: 0;
    transform: translate(-50%, 90%);
  }
}


.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(10, 11, 14, 0.6);
  backdrop-filter: blur(3px);
  animation: fade-in 0.25s ease-out;
}

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

.result-card {
  width: min(360px, 100%);
  padding: 26px 24px 22px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: var(--surface-raised);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: card-rise 0.35s cubic-bezier(0.2, 0.8, 0.25, 1);
}

.result-card h2 {
  margin: 0 0 16px;
  font-size: 22px;
}

.result-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 0 0 14px;
}

.result-stat {
  min-width: 70px;
  padding: 7px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.05);
}

.result-stat dd {
  margin: 2px 0 0;
  font-size: 17px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.result-note {
  margin: 0 0 14px;
  color: var(--amber);
  font-size: 14px;
  font-weight: 600;
}

.result-actions {
  display: grid;
  gap: 8px;
}

.action {
  height: 42px;
  border: 0;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.08);
  font-size: 15px;
  font-weight: 700;
}

.action:hover {
  background: rgba(255, 255, 255, 0.13);
}

.action.primary {
  background: var(--blue);
  color: #0c1726;
}

.action.primary:hover {
  background: #6cb4ff;
}

.dialog {
  width: min(400px, calc(100vw - 32px));
  max-width: calc(100vw - 32px);
  padding: 24px 22px 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  background: var(--surface-raised);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  color: inherit;
  text-align: center;
}

.dialog[open] {
  animation: card-rise 0.3s cubic-bezier(0.2, 0.8, 0.25, 1);
}

.dialog::backdrop {
  background: rgba(10, 11, 14, 0.6);
  backdrop-filter: blur(3px);
}

.dialog h2 {
  margin: 0 0 14px;
  font-size: 22px;
}

.dialog h3 {
  margin: 18px 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

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

.dialog-actions {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
  margin-top: 16px;
}

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.stats-table th,
.stats-table td {
  padding: 7px 6px;
  text-align: center;
}

.stats-table tbody th {
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.stats-table thead th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.stats-table tbody tr + tr {
  border-top: 1px solid var(--thin-line);
}

.stats-table td {
  font-weight: 700;
}

.dialog .daily-today {
  margin: 0 0 8px;
  color: var(--amber);
  font-weight: 650;
}

.daily-history {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.daily-history li {
  display: flex;
  justify-content: space-between;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
}

.daily-history span {
  color: var(--muted);
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

@keyframes card-rise {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97);
  }
}

.site-footer {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 5px;
  background: rgba(0, 0, 0, 0.18);
  font-size: 10px;
  opacity: 0.7;
}

.site-footer a {
  color: inherit;
}

@media (max-width: 1100px) {
  header {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .button-label {
    display: none;
  }

  .new-game-button {
    width: 38px;
    justify-content: center;
    padding: 0;
  }
}

@media (max-width: 860px) {
  :root {
    --header-height: 104px;
  }

  .rules-note {
    display: none;
  }

  .play-area {
    --board-size: min(500px, calc(100vw - 24px), calc((var(--viewport-height) - var(--header-height) - var(--footer-height) - 80px) * 0.75));
  }
}

@media (max-width: 640px) {
  header {
    padding: 8px 12px;
    gap: 8px;
  }

  .header-start {
    gap: 10px;
  }

  .home-link {
    padding-right: 10px;
  }

  .brand-mark {
    display: none;
  }

  h1 {
    font-size: 17px;
  }

  .stat {
    min-width: 64px;
    padding: 4px 8px;
  }

  .stat-value {
    font-size: 15px;
  }

  .controls {
    width: 100%;
    justify-content: space-between;
    gap: 4px;
  }

  #table {
    align-items: flex-start;
    padding: 10px 10px 14px;
  }

  .result-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }

  .dialog {
    padding: 22px 16px 16px;
  }

  .play-area {
    --board-size: min(calc(100vw - 20px), calc((var(--viewport-height) - var(--header-height) - var(--footer-height) - 70px) * 0.75));
    gap: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cell,
  .board,
  .piece,
  .score-bump,
  .result-overlay,
  .result-card,
  .dialog {
    animation: none !important;
    transition: none !important;
  }

  .score-popup {
    animation: popup-fade 0.9s linear forwards;
  }

  @keyframes popup-fade {
    0%,
    70% {
      opacity: 1;
    }
    100% {
      opacity: 0;
    }
  }
}


.guide {
  max-width: 760px;
  margin: 0 auto;
  padding: 48px 20px 64px;
  color: rgba(241, 241, 244, 0.84);
  font-size: 16px;
  line-height: 1.65;
  user-select: text;
}

.guide h2 {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 24px;
}

.guide h3 {
  margin: 22px 0 6px;
  color: var(--ink);
  font-size: 17px;
}

.guide p,
.guide li {
  margin: 0 0 10px;
}

.guide ul,
.guide ol {
  padding-left: 22px;
}

.guide kbd {
  padding: 1px 6px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 5px;
  background: transparent;
  font: inherit;
  font-size: 13px;
}

.guide h2:not(:first-child) {
  margin-top: 40px;
}

.guide a,
.more-games a {
  color: var(--blue-soft);
}

.more-games {
  max-width: 760px;
  margin: 0 auto;
  padding: 0 20px 64px;
  user-select: text;
}

.more-games h2 {
  margin: 0 0 12px;
  font-size: 20px;
}

.more-games ul {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.noscript-note {
  margin: 0;
  padding: 12px 20px;
  background: var(--blue);
  color: #0c1726;
  text-align: center;
}

@media (max-width: 640px) {
  .site-footer {
    flex-wrap: wrap;
    row-gap: 2px;
    column-gap: 12px;
  }

  .site-footer > [aria-hidden="true"] {
    display: none;
  }
}

.result-note span {
  display: block;
}

.result-note span + span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}
