* {
  box-sizing: border-box;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation; /* タブレット連打時の拡大防止 */
}

html {
  margin: 0;
  height: 100%;
}

body {
  margin: 0;
  height: 100vh;
  font-family: -apple-system,
    BlinkMacSystemFont,
    "Hiragino Sans",
    "Yu Gothic",
    "Meiryo",
    sans-serif;
  background: #f2f2f2;
  display: flex;
  justify-content: center;
  align-items: center;
}

.container {
  margin: 0 auto;
  background: #ffffff;
  border: 2px solid #333;
  width: 100%;
  max-width: 1196px;
  height: 540px;
  display: flex;
  flex-direction: column;
}

.game-header {
  height: 50px;
  padding: 10px;
  background: #ffffff;
  flex: 0 0 50px;
  display: flex;
  align-items: center;
}

.game-main {
  position: relative;
  background: #ffffff;
  flex: 1;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.btn {
  padding: 12px 20px;
  font-size: 16px;
  border: 2px solid #333;
  background: #fff;
  cursor: pointer;
  border-radius: 10px;
  transition: background-color 0.15s ease,
              transform 0.05s ease;
}

.btn:hover {
  background: #d6f0ff;
}

.btn:active {
  transform: scale(0.98);
}

.deco {
  position: absolute;
  font-size: 56px;
  pointer-events: none;
  animation: float 6s ease-in-out infinite;
}

@keyframes float {
  50% {
    transform: translateY(-16px) rotate(6deg);
  }
}

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

#app button {
  font-family: inherit;
  touch-action: manipulation;
  cursor: pointer;
  border: none;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.screen {
  position: absolute;
  inset: 0;
  display: none;
  padding: 20px 28px;
}

.screen.on {
  display: flex;
}

#start {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.levels {
  display: flex;
  gap: 24px;
  margin-top: 10px;
}

.lv {
  width: 300px;
  height: 76px;
  border-radius: 24px;
  color: #fff;
  font-size: 36px;
  font-weight: bold;
  box-shadow: 0 10px 0 rgba(0,0,0,.22);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform .1s;
}

.lv:active {
  transform: translateY(8px);
  box-shadow: 0 2px 0 rgba(0,0,0,.22);
}

.lv.e {
  background: #3cc46e;
}

.lv.n {
  background: #ffa31a;
}

.lv.h {
  background: #ee5a7a;
}

#play {
  flex-direction: column;
  gap: 12px;
  padding: 16px 28px 20px;
}

.main {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.side {
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

#lvname {
  font-size: 36px;
  font-weight: bold;
  color: #fff;
  text-align: center;
  padding: 8px 32px;
  border-radius: 24px;
  box-shadow: 0 6px 0 rgba(0,0,0,.2);
}

#hint {
  background: #fff9d6;
  border: 4px solid #ffc94d;
  border-radius: 24px;
  padding: 12px;
  text-align: center;
  height: 232px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

#hint h3 {
  margin: 0;
  font-size: 30px;
  color: #ff8a00;
}

#hint p {
  margin: 0;
  font-size: 25px;
  font-weight: bold;
  color: #7a5a00;
  line-height: 1.35;
}

#app .btn {
  border: 0;
  padding: 0;
  font-size: 32px;
  font-weight: bold;
  color: #fff;
  border-radius: 26px;
  height: 84px;
  box-shadow: 0 8px 0 rgba(0,0,0,.22);
}

#app .btn:active {
  transform: translateY(6px);
  box-shadow: 0 2px 0 rgba(0,0,0,.22);
}

.quit {
  background: #8a6cf0;
}

.board-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  display: grid;
  background: #fff;
  border: 6px solid #2a6fa0;
  border-radius: 18px;
  overflow: hidden;
  --cs: 68px;
}

.cell {
  width: var(--cs);
  height: var(--cs);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cs)*.6);
  font-weight: bold;
  border: 1px solid #9cc8e3;
  background: #fff;
  cursor: pointer;
}

.cell.given {
  background: #e6f1fa;
}

.cell.rel {
  background: #fff6c9;
}

.cell.given.rel {
  background: #f3eeb9;
}

.cell.same {
  background: #ffe08a;
}

.cell.sel {
  background: #ffd23f;
  outline: 5px solid #ff6b3d;
  outline-offset: -5px;
}

.cell.dup {
  background: #ffb347;
  outline: 6px solid #e0334f;
  outline-offset: -6px;
  position: relative;
  z-index: 1;
  animation: blink .4s ease-in-out 3;
}

@keyframes blink {
  50% {
    transform: scale(1.18);
  }
}

.num.shake {
  animation: nshake .45s;
}

@keyframes nshake {
  20% {
    transform: translateX(-14px);
  }

  40% {
    transform: translateX(14px);
  }

  60% {
    transform: translateX(-9px);
  }

  80% {
    transform: translateX(9px);
  }
}

#padmsg {
  height: 64px;
  border-radius: 22px;
  background: #fff;
  color: #e0334f;
  font-size: 36px;
  font-weight: bold;
  border: 4px solid #e0334f;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
}

#padmsg.on {
  visibility: visible;
  animation: pop2 .3s;
}

#padmsg.ok {
  color: #2eae5b;
  border-color: #2eae5b;
}

@keyframes pop2 {
  from {
    transform: scale(.7);
  }

  to {
    transform: scale(1);
  }
}

.padwrap {
  width: 270px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#pad {
  display: grid;
  grid-template-columns: repeat(3,1fr);
  gap: 12px;
}

.num {
  height: 76px;
  border-radius: 24px;
  font-size: 44px;
  font-weight: bold;
  color: #fff;
  box-shadow: 0 8px 0 rgba(0,0,0,.22);
}

.num:active {
  transform: translateY(6px);
  box-shadow: 0 2px 0 rgba(0,0,0,.22);
}

#clear {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.9);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 5;
}

#clear.on {
  display: flex;
}

#clear h2 {
  margin: 0;
  font-size: 80px;
  color: #ff6b3d;
  text-shadow: 4px 4px 0 #fff,6px 6px 0 #ffc94d;
}

#clear .row {
  display: flex;
  gap: 24px;
}

#clear .btn {
  width: 290px;
}

.big {
  font-size: 90px;
  animation: pop .8s ease-in-out infinite alternate;
}

@keyframes pop {
  to {
    transform: scale(1.15) rotate(-6deg);
  }
}

.conf {
  position: absolute;
  top: -60px;
  font-size: 40px;
  animation: fall linear forwards;
  pointer-events: none;
}

@keyframes fall {
  to {
    transform: translateY(640px) rotate(360deg);
  }
}

.container {
  position: relative;
  background: linear-gradient(#7fd4ff 0%,#c8f0ff 55%,#a8e87a 55.1%,#7fcf4f 100%);
}

.game-main {
  background: rgba(255,255,255,.35);
  min-height: 0;
}

[hidden] {
  display: none!important;
}

.game-header {
  background: transparent;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 12px;
  padding: 5px 12px;
  z-index: 10;
}

.game-header h1 {
  margin: 0;
  font-size: 23px;
  color: #2a6fa0;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

button {
  font-family: inherit;
  touch-action: manipulation;
  cursor: pointer;
}

.game-header .quit {
  border: 0;
  border-radius: 24px;
  color: #fff;
  font-weight: bold;
  font-size: 18px;
  height: 36px;
  padding: 0 18px;
  box-shadow: 0 3px 0 #6247bc;
}

.sound-btn {
  background: #fff0ad;
  border: 3px solid #f2b321;
  border-radius: 50px;
  padding: 5px 12px;
  font-size: 18px;
  font-weight: 700;
  color: #694100;
  box-shadow: 0 3px 0 #d89500;
  min-width: 104px;
}

.sound-btn:hover {
  background: #ffe680;
  border-color: #dc9700;
  color: #5a3500;
}

.sound-btn.sound-off {
  background: #e9edf1;
  border-color: #aeb7c0;
  color: #66717b;
  box-shadow: 0 3px 0 #929ba4;
}

#play {
  padding: 12px 24px 20px;
}

#lvname {
  font-size: 28px;
}

#clear h2 {
  font-size: 54px;
}

#clear h2,#clear .big,#clear .row {
  z-index: 1;
}

#clear .conf {
  z-index: 0;
}

#clear .btn {
  font-size: 28px;
}

@media(max-width:1000px) {
  .levels {
    width: 100%;
    gap: 16px;
  }

  .lv {
    width: auto;
    flex: 1;
    font-size: 34px;
  }

  .side {
    width: 190px;
  }

  .padwrap {
    width: 200px;
  }

  .main {
    gap: 12px;
  }

  #hint p {
    font-size: 21px;
  }

  #hint h3 {
    font-size: 25px;
  }

  #pad {
    gap: 10px;
  }

  .num {
    height: 66px;
    font-size: 36px;
  }

  #padmsg {
    font-size: 27px;
  }
}

@media(max-width:700px) {
  .game-header {
    gap: 4px;
    padding: 5px;
  }

  .game-header h1 {
    font-size: 16px;
  }

  .header-actions {
    gap: 4px;
  }

  .game-header .quit {
    font-size: 13px;
    padding: 0 8px;
  }

  .sound-btn {
    font-size: 14px;
    min-width: 66px;
    padding: 5px 6px;
  }

  #start {
    padding: 20px 12px;
  }

  .levels {
    gap: 10px;
  }

  .lv {
    font-size: 22px;
    height: 60px;
    border-radius: 18px;
  }

  #play {
    padding: 8px 10px 16px;
  }

  .main {
    flex-wrap: wrap;
    justify-content: center;
    align-content: center;
    gap: 12px;
  }

  .side {
    width: 100%;
    flex-direction: row;
    justify-content: center;
    gap: 10px;
    align-items: center;
  }

  #lvname {
    font-size: 18px;
    padding: 8px 16px;
  }

  #hint {
    height: 58px;
    padding: 4px 10px;
    border-width: 2px;
    border-radius: 16px;
    gap: 0;
  }

  #hint h3 {
    display: none;
  }

  #hint p {
    font-size: 13px;
    line-height: 1.15;
  }

  .board-wrap {
    flex: 0 1 auto;
  }

  .padwrap {
    width: 110px;
    gap: 8px;
  }

  #pad {
    grid-template-columns: repeat(2,1fr);
    gap: 8px;
  }

  .num {
    height: 54px;
    font-size: 28px;
    border-radius: 16px;
  }

  #padmsg {
    height: 40px;
    font-size: 16px;
    border-width: 2px;
    border-radius: 12px;
  }

  #clear h2 {
    font-size: 34px;
  }

  #clear .row {
    flex-direction: column;
    gap: 14px;
  }

  #clear .btn {
    width: 260px;
    height: 62px;
    font-size: 24px;
  }
}

@media(prefers-reduced-motion:reduce) {
  .conf,.big {
    animation: none;
  }
}

#start {
  gap: 16px;
  padding: 48px 20px 20px;
}

#start .levels {
  margin-top: 0;
}

.demo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.demo-scene {
  position: relative;
  width: 340px;
  height: 294px;
  --hand-x: 212px;
  --hand-y: 34px;
}

.demo-board {
  position: absolute;
  left: 16px;
  top: 0;
  display: grid;
  grid-template-columns: repeat(4,44px);
  border: 4px solid #2a6fa0;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

.demo-board>span {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 1px solid #9cc8e3;
  font-size: 28px;
  font-weight: bold;
  color: #2a6fa0;
  background: #fff;
}

.demo-board>span:nth-child(4n+2) {
  border-right: 3px solid #2a6fa0;
}

.demo-board>span:nth-child(n+5):nth-child(-n+8) {
  border-bottom: 3px solid #2a6fa0;
}

.demo-board>span.demo-unit {
  background: #fff1be;
}

.demo-board>span.demo-target {
  background: #ffd23f;
  box-shadow: inset 0 0 0 3px #ff6b3d;
}

.demo-scene[data-phase="select"] .demo-target {
  animation: demo-select-cell .65s forwards;
}

@keyframes demo-select-cell {
  0%,45% {
    background: #fff;
    box-shadow: none;
  }

  46%,100% {
    background: #ffd23f;
    box-shadow: inset 0 0 0 3px #ff6b3d;
  }
}

.demo-target b {
  color: #2f8be6;
}

.demo-board>span.demo-duplicate {
  background: #ffd3da;
  color: #c92540;
  box-shadow: inset 0 0 0 3px #e0334f;
  animation: demo-alert .45s ease-in-out 3;
}

.demo-pad {
  position: absolute;
  left: 242px;
  top: 34px;
  display: grid;
  grid-template-columns: repeat(2,40px);
  gap: 10px;
}

.demo-pad>span {
  height: 44px;
  display: grid;
  place-items: center;
  background: #e8473f;
  color: #fff;
  border-radius: 12px;
  font-size: 28px;
  font-weight: bold;
  box-shadow: 0 4px 0 #0003;
}

.demo-pad>span:nth-child(2) {
  background: #2f8be6;
}

.demo-pad>span:nth-child(3) {
  background: #2eae5b;
}

.demo-pad>span:nth-child(4) {
  background: #f09a10;
}

.demo-pad>span.demo-pressed {
  transform: translateY(4px);
  box-shadow: 0 0 0 3px #fff,0 0 0 5px #2a6fa0;
}

.demo-hand {
  position: absolute;
  left: 72px;
  top: 30px;
  font-size: 42px;
  line-height: 1;
  z-index: 2;
  transition: transform 1s ease;
  pointer-events: none;
}

.demo-scene[data-phase="press"] .demo-hand {
  transform: translate(var(--hand-x),var(--hand-y));
}

.demo-scene[data-phase="result"] .demo-hand {
  transform: translate(var(--hand-x),var(--hand-y));
  opacity: 0;
}

.demo-caption {
  position: absolute;
  top: 232px;
  left: 50%;
  transform: translateX(-50%);
  width: min(620px,calc(100vw - 28px));
  text-align: center;
  line-height: 1.4;
  font-size: 28px;
  font-weight: bold;
  color: #2a6fa0;
}

.demo-caption.bad {
  color: #c92540;
}

.demo-caption.ok {
  color: #2eae5b;
}

.demo-feedback {
  position: absolute;
  left: 232px;
  top: 0;
  width: 108px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  visibility: hidden;
  border: 2px solid currentColor;
  border-radius: 10px;
  background: #fff;
  font-size: 17px;
  font-weight: bold;
  white-space: nowrap;
}

.demo-feedback.bad {
  visibility: visible;
  color: #c92540;
}

.demo-feedback.ok {
  visibility: visible;
  color: #2eae5b;
}

@keyframes demo-alert {
  50% {
    box-shadow: inset 0 0 0 5px #e0334f;
  }
}

@media(max-width:700px) {
  .game-header {
    grid-template-columns: 1fr auto 1fr;
  }

  #start {
    gap: 16px;
    padding: 28px 10px 16px;
  }

  .demo-scene {
    width: 300px;
    height: 316px;
  }

  .demo-board {
    left: 0;
  }

  .demo-pad {
    left: 210px;
    gap: 8px;
    grid-template-columns: repeat(2,36px);
  }

  .demo-feedback {
    left: 198px;
    width: 102px;
    font-size: 16px;
  }

  .demo-hand {
    left: 56px;
  }

  .demo-caption {
    top: 212px;
    font-size: 24px;
  }
}

@media(prefers-reduced-motion:reduce) {
  .demo * {
    animation: none!important;
    transition: none!important;
  }

  .demo-hand {
    display: none;
  }
}

.demo-scene[data-phase="waiting"] .demo-hand {
  visibility: hidden;
}

.demo-scene[data-phase="waiting"] .demo-target {
  background: #fff;
  box-shadow: none;
}

.header-level {
  min-width: 0;
  justify-self: start;
}

.game-header #lvname {
  font-size: 20px;
  padding: 4px 16px;
  border-radius: 16px;
  box-shadow: 0 3px 0 rgba(0,0,0,.2);
  white-space: nowrap;
}

@media(max-width:700px) {
  .game-header #lvname {
    font-size: 14px;
    padding: 5px 8px;
  }

  .game-header h1 {
    font-size: 14px;
  }
}

.demo-visual {
  position: absolute;
  inset: 0;
  transform: scale(1.16);
  transform-origin: top center;
}

@media(max-width:700px) {
  .demo-visual {
    transform: scale(1.06);
  }
}
