html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #ecebe4;
  touch-action: none;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #151515;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
}

.tool-stage,
.sketch-host {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  height: 100vh;
}

.sketch-host canvas {
  display: block;
  width: min(100vw, 150vh) !important;
  height: min(100vh, 66.6667vw) !important;
  max-width: 100vw;
  max-height: 100vh;
  cursor: crosshair;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

.tool-ui,
.show-ui {
  position: fixed;
  z-index: 10;
  pointer-events: auto;
}

.tool-ui {
  left: 14px;
  top: 14px;
  display: grid;
  gap: 8px;
  width: min(520px, calc(100vw - 28px));
  padding: 9px;
  border: 1px solid rgba(20, 20, 18, 0.16);
  border-radius: 8px;
  background: rgba(247, 246, 239, 0.9);
  box-shadow: 0 14px 36px rgba(31, 30, 25, 0.13);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.back-link,
button {
  min-height: 44px;
  border: 1px solid rgba(20, 20, 18, 0.2);
  border-radius: 6px;
  background: rgba(255, 255, 252, 0.84);
  color: #151515;
  font: inherit;
  font-size: 13px;
  line-height: 1;
  letter-spacing: 0;
  touch-action: manipulation;
}

.back-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  text-decoration: none;
  white-space: nowrap;
}

.tool-actions {
  display: grid;
  grid-template-columns: 1.1fr repeat(3, 0.72fr) 0.95fr;
  gap: 7px;
}

button {
  padding: 0 12px;
  cursor: pointer;
}

.back-link:focus-visible,
button:focus-visible {
  outline: 2px solid #151515;
  outline-offset: 2px;
}

button:active,
.back-link:active {
  transform: translateY(1px);
}

.show-ui {
  left: 14px;
  top: 14px;
  min-width: 56px;
  background: rgba(247, 246, 239, 0.9);
  box-shadow: 0 10px 28px rgba(31, 30, 25, 0.13);
}

[hidden] {
  display: none !important;
}

@media (max-width: 720px) {
  .tool-ui {
    top: auto;
    bottom: 12px;
    left: 12px;
    width: calc(100vw - 24px);
  }

  .tool-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #hideButton {
    grid-column: 1 / -1;
  }

  .show-ui {
    top: auto;
    bottom: 12px;
    left: 12px;
  }
}

@media (max-width: 420px) {
  .tool-actions {
    grid-template-columns: 1fr;
  }
}
