:root {
  color-scheme: light only;
  --page-red: #f06060;
  --dialog-red: #a74343;
  --soft-red: #ffa1a1;
  --timer-red: #fd9090;
  --timer-text: #ffcaca;
  --button-orange: #fcad26;
  --tile-border: #ddd;
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body,
#app {
  width: 100%;
  height: 100%;
  min-height: 100%;
}

html {
  background: var(--page-red);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--page-red);
  color: #fff;
  font: 12px/1.5 "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.page {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  min-height: 100svh;
}

.start-screen {
  overflow: hidden;
  background: var(--page-red);
}

.start-screen h1 {
  margin: 0.67em 12px;
  padding: 0;
  text-align: center;
  font-size: 28px;
  line-height: 1.5;
  text-shadow: 1px 1px 1px #ab3c3c;
}

.help-text {
  height: 30px;
  margin: 0;
  color: var(--soft-red);
  text-align: center;
  font-size: 16px;
  line-height: 1.5;
}

.start-actions {
  position: fixed;
  right: 0;
  bottom: max(80px, calc(54px + env(safe-area-inset-bottom)));
  left: 0;
  width: 100%;
  text-align: center;
}

.game-button {
  position: relative;
  display: inline-block;
  width: 220px;
  height: 45px;
  margin: 15px 30px;
  padding: 0 18px;
  border: 0;
  border-radius: 7px;
  outline: 0;
  background: var(--button-orange);
  color: #fff;
  cursor: pointer;
  font-size: 20px;
  font-weight: 700;
  line-height: 45px;
  letter-spacing: 1px;
  text-transform: uppercase;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.game-button:hover {
  filter: brightness(1.035);
}

.game-button:active {
  transform: translateY(1px);
  filter: brightness(0.97);
}

.game-button:focus-visible,
.pause-button:focus-visible,
.color-tile:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.95);
  outline-offset: 2px;
}

.game-screen {
  background: var(--page-red);
}

.game-header {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  width: 100%;
  height: 50px;
  color: var(--soft-red);
  font-size: 16px;
  line-height: 50px;
  text-align: center;
  user-select: none;
}

.level {
  position: absolute;
  top: 0;
  left: 10px;
  width: 80px;
  height: 50px;
}

.level em {
  font-style: normal;
}

.time {
  display: inline-block;
  min-width: 44px;
  padding: 0 10px;
  border-radius: 10px;
  background: var(--timer-red);
  color: var(--timer-text);
  font-size: 20px;
  font-weight: 700;
  line-height: 32px;
}

.time.danger {
  background: #fff;
  color: #ff0505;
  animation: danger-pulse 0.72s ease-in-out infinite alternate;
}

.pause-button {
  position: absolute;
  top: 5px;
  right: 0;
  width: 80px;
  height: 40px;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: var(--button-orange);
  color: #fff;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  line-height: 40px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.pause-button:hover {
  filter: brightness(1.035);
}

.pause-button:active {
  transform: translateY(1px);
}

.color-board {
  position: absolute;
  top: 50px;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  grid-template-columns: repeat(var(--grid-size, 2), 1fr);
  grid-template-rows: repeat(var(--grid-size, 2), 1fr);
  width: min(500px, calc(100vw - 20px));
  height: min(500px, calc(100vw - 20px));
  margin: 15px auto;
  padding: 10px;
  border-radius: 10px;
  background: transparent;
}

.color-tile {
  display: block;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 5px solid var(--tile-border);
  border-radius: 10px;
  background: var(--tile-color);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.color-board[data-grid-size="5"] .color-tile,
.color-board[data-grid-size="6"] .color-tile,
.color-board[data-grid-size="7"] .color-tile,
.color-board[data-grid-size="8"] .color-tile,
.color-board[data-grid-size="9"] .color-tile {
  border-width: 3px;
}

.dialog-screen {
  z-index: 10;
  overflow: auto;
  box-sizing: border-box;
  padding-top: 5px;
  background: var(--dialog-red);
}

.dialog-content {
  width: 100%;
  min-height: 100%;
  padding: 10px 16px 32px;
  text-align: center;
  font-size: 20px;
}

.pause-content h2,
.result-label {
  margin: 0;
  color: #ffe2c5;
  font-size: 40px;
  line-height: 60px;
}

.pause-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}

.pause-content h2 {
  margin-top: 10px;
}

.result-score {
  margin: 5px;
  font-size: 28px;
  line-height: 1.5;
}

.result-content > p {
  max-width: 500px;
  margin: 0 auto;
}

.result-label {
  color: #ff0;
}

.game-tip {
  margin-top: 18px !important;
  color: rgba(255, 255, 255, 0.86);
  font-size: 14px;
  line-height: 1.75;
}

noscript {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--dialog-red);
  color: #fff;
  font-size: 18px;
  text-align: center;
}

@keyframes danger-pulse {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.08);
  }
}

@media (orientation: landscape) {
  .game-header {
    width: 80px;
    height: 100%;
  }

  .level {
    left: 0;
  }

  .time {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    min-width: 0;
    height: 50px;
    margin-top: -25px;
    padding: 0;
    line-height: 50px;
  }

  .pause-button {
    top: auto;
    right: 0;
    bottom: max(15px, env(safe-area-inset-bottom));
  }

  .color-board {
    top: 0;
    left: 80px;
    width: min(500px, calc(100vh - 20px), calc(100vw - 100px));
    height: min(500px, calc(100vh - 20px), calc(100vw - 100px));
  }

  .dialog-screen {
    padding-top: 0;
    padding-left: 80px;
  }
}

@media (max-width: 361px) {
  .color-board[data-grid-size="2"] .color-tile,
  .color-board[data-grid-size="3"] .color-tile,
  .color-board[data-grid-size="4"] .color-tile {
    border-width: 2px;
    border-radius: 5px;
  }

  .color-board[data-grid-size="5"] .color-tile,
  .color-board[data-grid-size="6"] .color-tile,
  .color-board[data-grid-size="7"] .color-tile,
  .color-board[data-grid-size="8"] .color-tile,
  .color-board[data-grid-size="9"] .color-tile {
    border-width: 1px;
    border-radius: 3px;
  }
}

@media (max-height: 540px) and (orientation: portrait) {
  .start-screen h1 {
    margin-top: 0.35em;
    margin-bottom: 0.35em;
  }

  .start-actions {
    bottom: max(28px, env(safe-area-inset-bottom));
  }

  .game-tip {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .time.danger {
    animation: none;
  }
}

.qrcode {
  width: 220px;
  margin: 18px auto 10px;
  color: #fff;
  font-size: 17px;
  line-height: 1.5;
}

.qrcode a,
.qrcode img {
  display: block;
}

.qrcode a {
  width: 196px;
  margin: 8px auto 0;
  padding: 8px;
  border-radius: 8px;
  background: #fff;
}

.qrcode img {
  width: 180px;
  height: 180px;
}

@media (max-width: 800px) {
  .qrcode {
    display: none;
  }
}
