:root {
  --bg: #e6e6e6;
  --panel: #f5f5f5;
  --accent: #0078d7;
  --text: #1b1b1b;
  --sub: #4a4a4a;
  --border: #d0d0d0;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  --radius: 10px;
  --scale: 1;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body {
  margin: 0;
  font-family: 'Segoe UI', 'Noto Sans JP', system-ui, -apple-system;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  align-items: center;
  /* reduced vertical padding so UI fits when scale=1 */
  padding: 10px 12px 18px;
  zoom: var(--scale);
  transform-origin: top left;
}

@supports not (zoom: 1) {
  body { transform: scale(var(--scale)); }
}

.app {
  width: min(1180px, 100%);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  align-items: start;
}

.hero {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  gap: 6px 14px;
  padding: 14px 16px;
}

.title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.1px;
  color: #0b0b0b;
}

.subtitle {
  color: var(--sub);
  font-size: 13px;
}

.controls {
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  display: flex;
  gap: 8px;
  align-items: center;
}

button {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: linear-gradient(180deg, #ffffff, #f1f1f1);
  color: #0b0b0b;
  transition: background 0.15s ease, transform 0.08s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

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

button.ghost {
  background: var(--accent);
  color: #ffffff;
  border-color: #0062b6;
}

.stage-wrap {
  position: relative;
  width: min(1400px, 100%);
  margin: 4px auto 4px;
  background: #FFB6D9;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: grid;
  place-items: center;
  /* Prevent parent from hijacking touch gestures */
  touch-action: none;
}

#game {
  width: 100%;
  height: auto;
  display: block;
  background: #FFB6D9;
  /* Mobile touch: prevent browser gestures interfering with drag */
  touch-action: none;
  -ms-touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.overlay {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}


.debug-log {
  position: fixed;
  right: 10px;
  bottom: 10px;
  background: rgba(0, 0, 0, 0.5);
  color: #e5ecff;
  padding: 8px 10px;
  border-radius: 8px;
  font-family: 'Consolas', 'Menlo', monospace;
  font-size: 11px;
  line-height: 1.35;
  max-width: 260px;
  white-space: pre-wrap;
  pointer-events: none;
  z-index: 100;
}

.stat {
  background: rgba(255, 255, 255, 0.9);
  color: #0b0b0b;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 12px;
  display: grid;
  gap: 1px;
  min-width: 86px;
  border: 1px solid var(--border);
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

.stat span { opacity: 0.7; }
.stat strong { font-size: 16px; letter-spacing: 0.2px; }

.notes {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 20px;
  box-shadow: var(--shadow);
  color: var(--text);
}

.notes h2 { margin: 8px 0 6px; font-size: 16px; }
.notes ul, .notes ol { margin: 4px 0 0 18px; color: var(--sub); line-height: 1.55; }
.notes li { margin-bottom: 4px; }
.notes code { background: rgba(0,0,0,0.04); padding: 2px 6px; border-radius: 4px; }
.mini { color: var(--sub); font-size: 12px; margin-top: 8px; }
.hint { color: var(--sub); font-size: 12px; }

@media (max-width: 720px) {
  body { padding: 12px 8px 32px; }
  .hero { grid-template-columns: 1fr; grid-template-rows: auto; }
  .controls { grid-column: 1 / 2; grid-row: 2 / 3; flex-wrap: wrap; justify-content: flex-start; }
  .layout { grid-template-columns: 1fr; }
  #game { height: auto; }
  /* constrain stage height on small screens to prevent overflow */
  .stage-wrap { max-height: 420px; }
  #game { max-height: 360px; }
  /* compact debug log on small screens */
  .debug-log {
    max-width: 160px;
    font-size: 10px;
    max-height: 180px;
    overflow: auto;
    padding: 6px 8px;
    /* place inside the stage to avoid covering bottom UI */
    position: absolute;
    right: 12px;
    top: 12px;
    bottom: auto;
    z-index: 220;
    pointer-events: none;
  }
}

/* Start screen overlay */
.start-screen {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10,10,12,0.55);
  z-index: 200;
}
.start-card {
  background: var(--panel);
  padding: 28px 32px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  text-align: center;
  max-width: 520px;
}
.start-card h1 { font-size: 18px; margin: 4px 0 8px; }
.start-card p { color: var(--sub); margin-bottom: 12px; }
.start-instructions { text-align: left; color: var(--sub); }
.start-instructions dl { margin: 8px 0 0 0; padding-left: 0; }
.start-instructions dt { font-weight: 700; margin-top: 8px; }
.start-instructions dd { margin: 4px 0 8px 0; }
.start-card button { font-size: 16px; padding: 10px 18px; }
