:root {
  color-scheme: dark;
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  background: #0e0c0a;
  color: #f2e4c6;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% -20%, rgba(180, 123, 55, 0.18), transparent 48%),
    #0e0c0a;
}

button {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  height: 100dvh;
  min-height: 0;
}

.toolbar {
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  gap: 24px;
  padding: 9px max(14px, env(safe-area-inset-right)) 9px max(14px, env(safe-area-inset-left));
  border-bottom: 1px solid #4f3d26;
  background: rgba(23, 18, 14, 0.96);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
}

.brand,
.toolbar-actions {
  display: flex;
  align-items: center;
}

.brand {
  min-width: 0;
  gap: 11px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border: 2px solid #df9f49;
  border-radius: 4px;
  background:
    linear-gradient(135deg, transparent 46%, #df9f49 47% 53%, transparent 54%),
    linear-gradient(45deg, #6c8b65 0 43%, #bea46f 44% 64%, #5b7891 65%);
  box-shadow: 3px 3px 0 #5a3b21;
}

.brand div {
  display: grid;
  min-width: 0;
  line-height: 1.15;
}

.brand strong {
  color: #f4c77b;
  font-size: 16px;
  letter-spacing: 0.04em;
}

.brand span {
  overflow: hidden;
  color: #aa9475;
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar-actions {
  gap: 12px;
}

.save-state {
  color: #ad9b7f;
  font-size: 11px;
  white-space: nowrap;
}

.save-state::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-right: 6px;
  border-radius: 50%;
  background: #6d8c65;
  box-shadow: 0 0 0 2px rgba(109, 140, 101, 0.18);
}

.toolbar-button {
  display: inline-block;
  padding: 7px 11px;
  border: 1px solid #75552e;
  border-radius: 4px;
  background: #352718;
  color: #f0d6a8;
  cursor: pointer;
  text-decoration: none;
}

.toolbar-button[hidden] {
  display: none;
}

.toolbar-button:hover,
.toolbar-button:focus-visible {
  border-color: #d79a48;
  background: #49331c;
  outline: none;
}

.download-link {
  border-color: #b9813e;
  background: #63431f;
  color: #fff0cf;
}

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

.canvas-shell {
  position: relative;
  width: min(100%, calc((100dvh - 111px) * 16 / 9));
  aspect-ratio: 16 / 9;
  max-height: 100%;
  overflow: hidden;
  border: 1px solid #4f3d26;
  border-radius: 5px;
  background: #090807;
  box-shadow: 0 16px 50px rgba(0, 0, 0, 0.42);
}

#canvas,
#loadingCanvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100% !important;
  height: 100% !important;
  min-width: 0 !important;
  min-height: 0 !important;
  max-width: 100%;
  max-height: 100%;
  image-rendering: crisp-edges;
  image-rendering: pixelated;
  touch-action: none;
}

#canvas {
  visibility: hidden;
  cursor: crosshair;
}

#canvas:focus-visible {
  outline: 2px solid #df9f49;
  outline-offset: -2px;
}

#loadingCanvas {
  background: #17120e;
}

.loading-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #d7b77e;
  font-size: clamp(12px, 1.5vw, 17px);
  pointer-events: none;
}

.loading-spinner {
  width: 18px;
  height: 18px;
  border: 2px solid #554128;
  border-top-color: #d99d4c;
  border-radius: 50%;
  animation: spin 0.8s steps(8) infinite;
}

.help-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 33px;
  gap: 24px;
  padding: 6px max(12px, env(safe-area-inset-right)) max(6px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  border-top: 1px solid #30261a;
  background: #13100d;
  color: #8e7d64;
  font-size: 10px;
  text-align: center;
}

.help-strip strong {
  color: #c6aa77;
  font-weight: 600;
}

noscript {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #17120e;
  color: #f4c77b;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 640px) {
  .toolbar {
    min-height: 50px;
  }

  .brand div span,
  .save-state,
  .help-strip span:first-child {
    display: none;
  }

  .canvas-shell {
    width: min(100%, calc((100dvh - 93px) * 16 / 9));
  }

  .stage {
    padding: 5px;
  }

  .help-strip {
    min-height: 28px;
  }
}

@media (max-width: 420px) {
  .toolbar {
    gap: 8px;
    padding-inline: 8px;
  }

  .brand {
    gap: 7px;
  }

  .brand-mark {
    width: 25px;
    height: 25px;
  }

  .toolbar-actions {
    gap: 6px;
  }

  .toolbar-button {
    padding-inline: 8px;
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading-spinner {
    animation: none;
  }
}
