* { box-sizing: border-box; }

body {
  padding-top: max(0.75rem, env(safe-area-inset-top, 0px));
  margin: 0;
  min-height: 100vh;
  background: #0f1419;
  color: #fff;
  font-family: "Inter", system-ui, sans-serif;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 0.75rem;
  /* 下に余白（広告・ホームバーと被りにくく） */
  padding-bottom: max(1.5rem, env(safe-area-inset-bottom, 0px) + 1rem);
}

#app {
  margin: 0 auto;
  width: min(100%, 40rem);
  position: relative;
}

#site-header {
  text-align: center;
  margin-bottom: 0.75rem;
}

#site-title {
  margin: 0;
  font-size: clamp(1.15rem, 4.5vw, 1.6rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.screen {
  text-align: center;
  padding: 0.5rem 0 1rem;
}

.screen.hidden,
.screen[hidden] {
  display: none !important;
}

.blurb {
  opacity: 0.85;
  line-height: 1.45;
  margin: 0.5rem 0 0.65rem;
  font-size: clamp(0.85rem, 3.6vw, 1.05rem);
  letter-spacing: 0.02em;
}

button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  font: inherit;
  font-size: 1rem;
  padding: 0.75rem 1.5rem;
  border-radius: 12px;
  cursor: pointer;
  backdrop-filter: blur(12px);
}

button:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.2);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

#screen-playing {
  padding: 0;
  text-align: left;
  position: relative;
  /* 盤の下に余白を確保 */
  margin-bottom: 1.25rem;
}

#play-layout {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-areas:
    "hud"
    "board";
  gap: 0.75rem;
  justify-items: center;
}

#hud-left {
  grid-area: hud;
  width: min(100%, 22rem);
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  align-items: stretch;
  justify-content: center;
  gap: 0.5rem;
}

#game-container {
  touch-action: none;
  grid-area: board;
  justify-self: center;
  background: #1a222c;
  border-radius: 8px;
  overflow: hidden;
  line-height: 0;
}

#overlay,
#next-panel {
  padding: 0.55rem 0.75rem;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.25);
}

#overlay {
  color: #fff;
  font-size: 0.85rem;
  text-align: left;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
  min-width: 7.5rem;
}

#overlay span {
  display: block;
  margin: 0;
}

#next-panel {
  text-align: center;
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.next-title {
  font-size: 0.7rem;
  opacity: 0.9;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin: 0;
}

#next-blocks {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.next-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
  background: hsl(200 70% 45%);
}

/* Result overlay */
.result-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 20, 25, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: 12px;
  z-index: 10;
  padding: 1rem;
}

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

.result-card {
  width: min(100%, 22rem);
  padding: 1.25rem 1.25rem 1.5rem;
  background: rgba(26, 34, 44, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.result-card h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
}

.result-summary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin: 0.75rem 0 1rem;
}

.result-board {
  display: block;
  width: 7.5rem;
  height: auto;
  border-radius: 8px;
  background: #1a222c;
  border: 1px solid rgba(255, 255, 255, 0.15);
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
}

#result-score {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0;
  text-align: left;
}

.ad-slot {
  margin: 1rem auto;
  width: min(100%, 18rem);
  aspect-ratio: 1 / 1;
  max-width: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-slot ins.adsbygoogle {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
  min-height: 0 !important;
}
.rule-example {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin: 0.35rem 0 0.5rem;
}

.rule-cell {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 6px;
  font-weight: 700;
  font-size: 1.05rem;
  color: #fff;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35);
  /* background set by paintRuleExample (blockHue) */
}

.rule-arrow {
  opacity: 0.75;
  font-size: 1.1rem;
  margin: 0 0.1rem;
}

.rule-score {
  font-weight: 700;
  font-size: 1.05rem;
  color: #9fe870;
}

.rule-caption {
  margin: 0 auto 1.25rem;
  max-width: 18rem;
  font-size: clamp(0.75rem, 3.2vw, 0.88rem);
  opacity: 0.75;
  line-height: 1.45;
}

#controls-help {
  margin: 1.5rem auto 0;
  max-width: 22rem;
  width: 100%;
  padding: 1rem 0 1.1rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  text-align: left;
  box-sizing: border-box;
  overflow: hidden;
}

.controls-heading {
  margin: 0 0 0.65rem;
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
}

.controls-list {
  margin: 0;
  padding-left: 1.2rem;
  font-size: 0.85rem;
  line-height: 1.65;
}

.controls-list kbd {
  font-size: 0.78rem;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
}

/* Ads only on title / result — never cover the board while playing */
#screen-playing > .ad-slot,
#screen-playing .ad-slot:not(#ad-result) {
  display: none !important;
}

#screen-title.hidden #ad-title,
#screen-title[hidden] #ad-title {
  display: none !important;
}

#ad-title {
  margin-top: 1.25rem;
}


@media (pointer: fine) and (min-width: 480px) {
  .controls-schemes {
    flex-direction: row;
    align-items: flex-start;
    gap: 1rem;
  }
  .controls-scheme {
    flex: 1;
    min-width: 0;
  }
}
#btn-start {
  background: linear-gradient(180deg, #5b8def 0%, #3d6fd8 100%);
  border: 1px solid rgba(255, 255, 255, 0.35);
  font-weight: 700;
  font-size: 1.1rem;
  padding: 0.9rem 2rem;
  min-width: 12rem;
  box-shadow: 0 4px 16px rgba(61, 111, 216, 0.45);
}

#btn-start:hover {
  background: linear-gradient(180deg, #6b9bf5 0%, #4a7ee0 100%);
  box-shadow: 0 6px 20px rgba(61, 111, 216, 0.55);
}

#btn-start:active {
  transform: translateY(1px);
  box-shadow: 0 2px 10px rgba(61, 111, 216, 0.4);
}
.controls-heading {
  margin: 0 0 0.75rem;
  padding: 0 1.1rem;
  font-size: 0.95rem;
  font-weight: 700;
  text-align: center;
}

.controls-carousel {
  width: 100%;
}

.controls-track {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.controls-track::-webkit-scrollbar {
  display: none;
}

.controls-slide {
  flex: 0 0 100%;
  scroll-snap-align: start;
  box-sizing: border-box;
  padding: 0 1.15rem 0.25rem;
}

.controls-scheme-label {
  margin: 0 0 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  opacity: 0.7;
  letter-spacing: 0.06em;
}

.controls-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.85rem;
  line-height: 1.7;
}

.controls-dots {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  margin-top: 0.65rem;
  padding: 0 1rem;
}

.controls-dots[hidden] {
  display: none !important;
}

.controls-dot {
  width: 0.45rem;
  height: 0.45rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  cursor: pointer;
}

.controls-dot[aria-current="true"] {
  background: rgba(255, 255, 255, 0.9);
}

/* PC: two schemes in first view; 3+ still carousel */
@media (pointer: fine) and (min-width: 520px) {
  #controls-help {
    max-width: 36rem;
    padding-top: 1.15rem;
    padding-bottom: 1.2rem;
  }
  .controls-slide {
    flex-basis: 50%;
  }
}
