:root {
  --bg1: #e8f5ff;
  --bg2: #fff7dc;
  --card: #ffffff;
  --ink: #243044;
  --muted: #607089;
  --blue: #1565c0;
  --blue2: #0d47a1;
  --accent: #ffb300;
  --danger: #e53935;
  --shadow: 0 16px 40px rgba(20, 60, 100, 0.18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", "Yu Gothic", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, var(--bg2), transparent 35%), linear-gradient(135deg, var(--bg1), #f6fbff 55%, #eef6ff);
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 16px 12px 6px;
}

.game-card {
  background: rgba(255,255,255,0.92);
  border: 1px solid rgba(21,101,192,0.14);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 16px;
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

h1 {
  margin: 0;
  font-size: clamp(1.5rem, 4vw, 2.45rem);
  letter-spacing: 0.05em;
}

.lead {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.score-box {
  min-width: 76px;
  padding: 8px 12px;
  text-align: center;
  background: #f3f8ff;
  border: 1px solid #d7e6f8;
  border-radius: 16px;
}

.score-box span { display: block; color: var(--muted); font-size: 0.78rem; }
.score-box strong { font-size: 1.7rem; color: var(--blue); }

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

.hud div {
  background: #f8fbff;
  border: 1px solid #dcecff;
  border-radius: 14px;
  padding: 8px 6px;
  text-align: center;
  font-size: 0.9rem;
  color: var(--muted);
}

.hud strong {
  color: var(--ink);
  font-size: 1.15rem;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  max-height: min(66vh, 680px);
  border-radius: 18px;
  overflow: hidden;
  background: #172033;
  border: 3px solid #20304a;
}

#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
}

.message-layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 20px;
  text-align: center;
  color: #fff;
  background: linear-gradient(180deg, rgba(10,19,34,0.82), rgba(10,19,34,0.68));
}

.message-layer.hidden { display: none; }
.message-layer h2 { margin: 0; font-size: clamp(1.6rem, 5vw, 3rem); }
.message-layer p { margin: 0; max-width: 620px; line-height: 1.7; }

button {
  border: none;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(21,101,192,0.24);
  transition: transform 0.04s, background 0.18s;
  user-select: none;
}

button:hover { background: var(--blue2); }
button:active, button.is-pressed { transform: translateY(1px) scale(0.98); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

#startBtn { padding: 12px 28px; font-size: 1.05rem; background: var(--accent); color: #332300; }
#startBtn:hover { background: #ffa000; }

.control-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 12px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 42px);
  gap: 6px;
}

.dpad button {
  width: 48px;
  height: 42px;
  font-size: 1rem;
}

.dpad button[data-dir="up"] { grid-column: 2; grid-row: 1; }
.dpad button[data-dir="left"] { grid-column: 1; grid-row: 2; }
.dpad button[data-dir="down"] { grid-column: 2; grid-row: 2; }
.dpad button[data-dir="right"] { grid-column: 3; grid-row: 2; }

.vacuum-btn {
  width: 118px;
  height: 58px;
  background: var(--danger);
  font-size: 1rem;
}
.vacuum-btn:hover { background: #c62828; }

.help-text {
  margin-top: 8px;
  color: var(--muted);
  text-align: center;
  font-size: 0.86rem;
}

.site-footer {
  text-align: center;
  color: #1565c0;
  background: rgba(255,255,255,0.55);
  border-top: 1px solid rgba(21,101,192,0.18);
  padding: 8px 8px 10px;
  font-size: 0.9rem;
}

.site-footer a {
  color: #1565c0;
  text-decoration: none;
  font-weight: 700;
}

.site-footer a:hover { color: #0d47a1; }

@media (max-width: 640px) {
  .app-shell { padding: 8px 6px 4px; }
  .game-card { padding: 10px; border-radius: 16px; }
  .title-row { align-items: flex-start; }
  .hud { grid-template-columns: repeat(2, 1fr); }
  .canvas-wrap { aspect-ratio: 1 / 1; max-height: none; }
  .control-panel { gap: 10px; }
  .dpad { grid-template-columns: repeat(3, 42px); grid-template-rows: repeat(3, 38px); }
  .dpad button { width: 42px; height: 38px; }
  .vacuum-btn { width: 104px; height: 54px; }
}

.ad-panel {
  width: 100%;
  margin: 0 0 12px;
  padding: 0;
  border: 1px solid #d7e6f8;
  border-radius: 12px;
  background: #ffffff;
  overflow: hidden;
}

.ad-panel[hidden] {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
}

.ad-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  background: #f4f8ff;
  border-bottom: 1px solid #d7e6f8;
}

.ad-label {
  font-size: 0.72rem;
  color: #4f6f91;
  line-height: 1.3;
  text-align: left;
}

.ad-close-btn {
  margin: 0 !important;
  padding: 3px 8px !important;
  min-height: 0;
  height: auto;
  line-height: 1.2;
  border: none;
  border-radius: 999px;
  background: #1565c0;
  color: #ffffff;
  font-size: 0.72rem !important;
  font-weight: 700;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  box-shadow: none;
}

.ad-close-btn:hover { background: #0d47a1; }
.ad-close-btn[hidden] { display: none !important; }

.ad-body {
  padding: 8px;
  background: #ffffff;
  min-height: 90px;
}
