:root {
  color-scheme: light;
  font-family: system-ui, sans-serif;
  background: #f4e0d0;
  color: #482f35;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

.app {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  height: 100vh;
  height: var(--viewport-height, 100dvh);
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
    env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: radial-gradient(ellipse at top, #fff5e9, #f4e0d0 64%, #e9c7b5);
}

.stage {
  display: grid;
  place-items: center;
  min-width: 0;
  overflow: hidden;
}

.game {
  position: relative;
  width: min(100vw, 50vh);
  height: 100%;
  overflow: hidden;
  background: #edcfb7;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: min(100%, max(18rem, var(--game-width, 100%)));
  margin-inline: auto;
  padding: 2px 6px;
}

.toolbar output {
  min-width: 0;
  font-size: 0.75rem;
  line-height: 1.25;
}

button, .action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  padding: 6px 10px;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 650;
  text-decoration: none;
  color: #482f35;
  background: #dce8d7;
  touch-action: manipulation;
  cursor: pointer;
}

.toolbar button { flex: none; }
button:disabled { opacity: 0.62; cursor: default; }
.warning { color: #872f2b; }
:focus-visible { outline: 2px solid #315851; outline-offset: 2px; }

.loader, .overlay {
  display: grid;
  place-items: center;
  position: absolute;
  inset: 0;
  padding: 16px;
}

.loader {
  align-content: center;
  gap: 12px;
  text-align: center;
  background: radial-gradient(ellipse at top, #fff7ec, #ecd0bb);
}

.loader h1, .panel h2 { margin: 0; }
.loader p, .panel p { margin: 0; line-height: 1.45; }
.loader img { border-radius: 18px; }
progress { width: min(85%, 200px); accent-color: #53796e; }

.overlay {
  z-index: 2;
  background: rgb(48 32 34 / 48%);
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right))
    max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 420px);
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 18px;
  border-radius: 16px;
  background: #fff7ed;
  box-shadow: 0 12px 36px rgb(61 41 42 / 24%);
}

.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.panel #close-panel { align-self: stretch; background: #efdfd0; }
#device-save-status, #app-cache-status { font-size: 0.875rem; }
