html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: #07090e;
  overflow: hidden;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

#topbar {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: 96vw;
  z-index: 10;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  padding: 6px 10px;
  border-radius: 9999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

#topbar button {
  background: rgba(255, 255, 255, 0.08);
  color: #e2e8f0;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 13px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

#topbar button:hover {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

#topbar button:active {
  transform: translateY(0);
}

canvas#c {
  width: 100vw;
  height: 100vh;
  display: block;
  background: #07090e;
  touch-action: none;
}

/* ------------------ On-Screen Controls Overlay ------------------ */

#onscreen-controls-root {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 9;
}

.onscreen-ctrl-container {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: rgba(15, 23, 42, 0.85);
  color: #f1f5f9;
  border: 1.5px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow:
    0 6px 20px rgba(0, 0, 0, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition:
    transform 0.08s ease,
    background 0.08s ease,
    border-color 0.08s ease;
  touch-action: none;
}

.ctrl-btn:active,
.ctrl-btn.active {
  background: rgba(56, 189, 248, 0.35);
  border-color: #38bdf8;
  color: #ffffff;
  transform: scale(0.94);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.5);
}

/* Mode: Arrows Layout */
.arrows-layout .arrows-row {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.arrows-layout .ctrl-btn {
  width: 58px;
  height: 54px;
  border-radius: 14px;
}

.arrows-layout .arrow-down {
  background: rgba(15, 23, 42, 0.92);
}

/* Mode: Boosted Layout */
.boosted-layout {
  width: min(340px, 92vw);
}

.boosted-layout .boosted-row {
  display: flex;
  width: 100%;
  gap: 8px;
}

.boosted-layout .top-row .boosted-btn {
  flex: 1;
  height: 48px;
  font-size: 13px;
  letter-spacing: 0.03em;
  background: rgba(30, 41, 59, 0.85);
}

.boosted-layout .bottom-row {
  display: flex;
  gap: 8px;
}

.boosted-layout .move-l,
.boosted-layout .move-r {
  width: 64px;
  height: 56px;
}

.boosted-layout .drop-btn {
  flex: 1;
  height: 56px;
  background: rgba(14, 116, 144, 0.5);
  border-color: rgba(56, 189, 248, 0.35);
  font-size: 13px;
  letter-spacing: 0.05em;
}

.boosted-layout .drop-btn:active,
.boosted-layout .drop-btn.active {
  background: rgba(14, 165, 233, 0.6);
  border-color: #38bdf8;
}

/* ------------------ Mode: Whole Screen Touch Zones ------------------ */

.onscreen-zones-overlay {
  position: absolute;
  inset: 0;
  pointer-events: auto;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.zones-guide-layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  pointer-events: none;
  transition: opacity 0.85s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 1;
}

.zones-guide-layer.faded {
  opacity: 0;
}

.zones-half {
  flex: 1;
  display: flex;
  position: relative;
}

.top-half {
  border-bottom: 2px dashed rgba(56, 189, 248, 0.3);
}

.bottom-half {
  border-top: none;
}

.zone-guide-box {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  background: rgba(15, 23, 42, 0.12);
}

.zone-top-l {
  border-right: 2px dashed rgba(56, 189, 248, 0.3);
}

.zone-bot-l {
  flex: 1;
  border-right: 2px dashed rgba(56, 189, 248, 0.3);
}

.zone-bot-center {
  flex: 2;
  border-right: 2px dashed rgba(56, 189, 248, 0.3);
  background: rgba(14, 116, 144, 0.1);
}

.zone-bot-r {
  flex: 1;
}

.guide-chip {
  background: rgba(15, 23, 42, 0.85);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.4);
  padding: 6px 14px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px);
}

/* Touch Interactive Layer (Upper half 50%/50%, Lower half 25%/50%/25%) */
.zones-touch-layer {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  grid-template-rows: 1fr 1fr;
}

/* Upper half zones: exactly 50% / 50% in half */
.zone-action-rot-l {
  grid-column: 1 / 3;
  grid-row: 1 / 2;
}

.zone-action-rot-r {
  grid-column: 3 / 5;
  grid-row: 1 / 2;
}

/* Lower half zones: 25% Left, 50% Drop/Speed, 25% Right */
.zone-action-move-l {
  grid-column: 1 / 2;
  grid-row: 2 / 3;
}

.zone-action-drop {
  grid-column: 2 / 4;
  grid-row: 2 / 3;
}

.zone-action-move-r {
  grid-column: 4 / 5;
  grid-row: 2 / 3;
}

.touch-zone {
  touch-action: none;
  transition: background 0.12s ease;
}

.touch-zone.touched {
  background: rgba(56, 189, 248, 0.15);
}
