* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #87ceeb; font-family: "Trebuchet MS", "Comic Sans MS", system-ui, sans-serif; color: #263238; user-select: none; -webkit-user-select: none; touch-action: none; }
#app, #app canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }

.panel { background: rgba(255, 255, 255, 0.9); border: 3px solid #263238; border-radius: 14px; box-shadow: 0 4px 0 #263238; padding: 8px 14px; font-weight: bold; }

#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button, #hud .panel { pointer-events: auto; }
#objective { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; font-size: 18px; max-width: calc(50vw - 90px); }
#timer-wrap { position: absolute; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
#timer { font-size: 26px; min-width: 110px; text-align: center; }
#timer.warn { background: #ffcdd2; animation: pulse 0.5s infinite alternate; }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.08); } }
#arrow-wrap { width: 64px; height: 64px; border-radius: 50%; background: rgba(255,255,255,0.85); border: 3px solid #263238; display: flex; align-items: center; justify-content: center; }
#arrow { font-size: 40px; color: #ff5722; transform: rotate(-90deg); line-height: 1; text-shadow: 0 2px 0 #263238; }
#distance { font-weight: bold; color: #fff; text-shadow: 0 2px 0 #263238, 0 0 4px #263238; }
#top-buttons { position: absolute; top: max(12px, env(safe-area-inset-top)); right: 12px; display: flex; gap: 8px; }

.tool-btn { font: inherit; font-weight: bold; font-size: 18px; background: #ffe14d; border: 3px solid #263238; border-radius: 12px; box-shadow: 0 4px 0 #263238; padding: 8px 14px; cursor: pointer; color: #263238; }
.tool-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #263238; }
.tool-btn.on { background: #4cd964; }
.tool-btn.small { font-size: 15px; padding: 6px 10px; }

#build-bar { position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; max-width: 94vw; }
#palette { display: flex; gap: 6px; }
.swatch { width: 34px; height: 34px; border-radius: 8px; border: 3px solid #263238; cursor: pointer; padding: 0; }
.swatch.selected { outline: 4px solid #ff5722; outline-offset: 1px; transform: scale(1.1); }
#build-hint { width: 100%; text-align: center; font-size: 13px; color: #546e7a; }

#toast { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); font-size: 34px; font-weight: bold; color: #fff; text-shadow: 0 3px 0 #263238, 0 0 6px #263238; opacity: 0; transition: opacity 0.3s; text-align: center; pointer-events: none; }
#toast.show { opacity: 1; }

#touch { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; padding: 16px max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-bottom)); pointer-events: none; }
.touch-left, .touch-right { display: flex; gap: 14px; align-items: flex-end; pointer-events: auto; }
.touch-btn { width: 76px; height: 76px; border-radius: 50%; font-size: 30px; background: rgba(255,255,255,0.85); border: 3px solid #263238; box-shadow: 0 4px 0 #263238; color: #263238; touch-action: none; }
.touch-btn.small { width: 62px; height: 62px; font-size: 24px; }
.touch-btn.gas { width: 92px; height: 92px; background: rgba(76, 217, 100, 0.9); }
.touch-btn.pressed { transform: translateY(3px); box-shadow: 0 1px 0 #263238; filter: brightness(0.9); }
/* On touch screens the build panel sits on the right, clear of the drive buttons */
body.touch #build-bar { bottom: auto; top: 70px; right: 12px; left: auto; transform: none; flex-direction: column; flex-wrap: nowrap; width: 132px; padding: 8px; gap: 6px; }
body.touch #palette { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
body.touch .swatch { width: 32px; height: 32px; }
body.touch #build-hint { display: none; }
body.touch #build-bar .tool-btn.small { width: 100%; font-size: 14px; padding: 5px 6px; }

.overlay { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(40, 120, 200, 0.35); padding: 16px; }
.card { background: #fffdf5; border: 4px solid #263238; border-radius: 22px; box-shadow: 0 8px 0 #263238; padding: 22px 26px; max-width: 640px; width: 100%; text-align: center; max-height: 96vh; overflow: auto; }
.card h1 { margin: 0 0 6px; font-size: clamp(28px, 6vw, 46px); color: #ff5722; text-shadow: 0 3px 0 #263238; }
.card h1 span { color: #ffc107; }
.card h2 { margin: 6px 0; font-size: 34px; }
.tagline { font-size: 18px; margin: 6px 0 14px; }
.howto { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-bottom: 16px; }
.howto > div { background: #e3f2fd; border: 3px solid #263238; border-radius: 14px; padding: 10px; font-size: 15px; }
.howto small { color: #546e7a; }
kbd { background: #fff; border: 2px solid #263238; border-radius: 6px; padding: 0 6px; font-family: inherit; }
.big-btn { font: inherit; font-size: 28px; font-weight: bold; padding: 12px 36px; background: #4cd964; color: #fff; text-shadow: 0 2px 0 #263238; border: 4px solid #263238; border-radius: 18px; box-shadow: 0 6px 0 #263238; cursor: pointer; }
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 #263238; }
.small-note { font-size: 13px; color: #546e7a; margin-bottom: 0; }
#end-emoji { font-size: 64px; }
#end-text { font-size: 18px; }
#error { position: fixed; inset: auto 10px 10px 10px; background: #ffebee; border: 3px solid #c62828; border-radius: 12px; padding: 10px; font-weight: bold; }

@media (max-height: 500px) {
  #objective { font-size: 14px; padding: 6px 10px; }
  #timer { font-size: 20px; min-width: 80px; padding: 4px 10px; }
  #arrow-wrap { width: 50px; height: 50px; }
  #arrow { font-size: 30px; }
}
@media (max-width: 640px) {
  #objective { font-size: 14px; max-width: 92vw; top: auto; bottom: 118px; left: 50%; transform: translateX(-50%); text-align: center; }
  #timer { font-size: 20px; min-width: 80px; }
  .tool-btn { font-size: 15px; padding: 6px 10px; }
  .swatch { width: 28px; height: 28px; }
  .touch-btn { width: 64px; height: 64px; }
  .touch-btn.gas { width: 80px; height: 80px; }
}
