* {
  box-sizing: border-box;
}

:root {
  --bg: #787878;
  --text: #ffffff;
  --muted: rgba(255, 255, 255, 0.74);
  --led: #bff8ff;
  --blue: #06f;
  --danger: #d60000;
}

html {
  width: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: grid;
  place-items: center;
  overflow-x: hidden;
}

.app {
  width: 100%;
  max-width: 980px;
  min-height: 100vh;
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.header {
  text-align: center;
  margin-bottom: 12px;
  padding: 0 14px;
}

h1 {
  margin: 0;
  font-family: "Space Grotesk", system-ui, sans-serif;
  font-size: clamp(30px, 4vw, 48px);
  line-height: 0.98;
  letter-spacing: -0.055em;
  font-weight: 700;
  text-wrap: balance;
  text-shadow: 0 3px 18px rgba(0, 0, 0, 0.18);
}

.subtitle {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.stage {
  width: 100%;
  display: grid;
  place-items: center;
}

.helmet-wrap {
  position: relative;
  width: min(86vw, 760px);
  aspect-ratio: 1 / 1;
}

.helmet-img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
  filter: drop-shadow(0 28px 70px rgba(0, 0, 0, 0.35));
}

.pixel-overlay {
  --cols: 62;
  --rows: 78;
  --dot-scale: 0.92;

  position: absolute;
  left: 26.6%;
  top: 29.25%;
  width: 47.95%;
  height: 62.35%;

  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);

  z-index: 5;
  user-select: none;
  touch-action: none;
}

.pixel {
  width: calc(100% * var(--dot-scale));
  height: calc(100% * var(--dot-scale));
  align-self: center;
  justify-self: center;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
  touch-action: none;
  transition:
    transform 0.05s ease,
    background 0.08s ease,
    box-shadow 0.08s ease,
    opacity 0.08s ease;
}

.pixel:hover {
  transform: scale(1.25);
  background: rgba(191, 248, 255, 0.32);
  box-shadow:
    0 0 2px rgba(191, 248, 255, 0.55),
    0 0 5px rgba(191, 248, 255, 0.35);
}

.pixel.on {
  background: var(--pixel-color);
  box-shadow:
    0 0 2px var(--pixel-color),
    0 0 4px var(--pixel-color);
}

.pixel.on:hover {
  transform: scale(1.2);
  box-shadow:
    0 0 3px var(--pixel-color),
    0 0 7px var(--pixel-color);
}

.pixel-overlay.guides .pixel {
  outline: 1px solid rgba(191, 248, 255, 0.16);
  background: rgba(191, 248, 255, 0.045);
}

.pixel-overlay.guides .pixel.on {
  background: var(--pixel-color);
}

.toolbar {
  margin-top: -20px;
  width: min(94vw, 920px);
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px;
  z-index: 20;
}

.tool-btn {
  align-items: center;
  background-color: #fff;
  border: 2px solid #000;
  box-sizing: border-box;
  color: #000;
  cursor: pointer;
  display: inline-flex;
  fill: #000;
  font-family: "Inter", sans-serif;
  font-size: 15px;
  font-weight: 700;
  height: 48px;
  justify-content: center;
  letter-spacing: -0.8px;
  line-height: 24px;
  min-width: 150px;
  outline: 0;
  padding: 0 17px;
  text-align: center;
  text-decoration: none;
  transition: all 0.2s ease;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  white-space: nowrap;
}

.tool-btn:focus {
  color: #171e29;
}

.tool-btn:hover {
  border-color: var(--blue);
  color: var(--blue);
  fill: var(--blue);
  transform: translateY(-1px);
}

.tool-btn:active {
  border-color: var(--blue);
  color: var(--blue);
  fill: var(--blue);
  transform: translateY(0);
}

.tool-btn.active {
  border-color: var(--blue);
  color: var(--blue);
  fill: var(--blue);
  background: #eef5ff;
}

.tool-btn.danger:hover {
  border-color: var(--danger);
  color: var(--danger);
  fill: var(--danger);
}

.tool-btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
  border-color: #000;
  color: #000;
  fill: #000;
}

.btn-icon {
  display: inline-block;
  margin-right: 7px;
  font-weight: 800;
}

.size-control {
  display: inline-flex;
  align-items: center;
  height: 48px;
}

.size-btn {
  width: 48px;
  min-width: 48px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.size-control .size-btn:first-child {
  border-right-width: 1px;
}

.size-control .size-btn:last-child {
  border-left-width: 1px;
}

.size-readout {
  height: 48px;
  min-width: 126px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  background: #fff;
  border-top: 2px solid #000;
  border-bottom: 2px solid #000;
  color: #000;
  font-family: "Inter", sans-serif;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.8px;
  user-select: none;
}

.meta {
  margin-top: 10px;
  height: 14px;
  color: rgba(255, 255, 255, 0.45);
  font-size: 12px;
  text-align: center;
}

@media (min-width: 768px) {
  .tool-btn {
    min-width: 170px;
  }

  .size-btn {
    min-width: 48px;
  }
}

@media (max-width: 700px) {
  html,
  body {
    width: 100%;
    overflow-x: hidden;
    overscroll-behavior: none;
  }

  body {
    place-items: start center;
  }

  .app {
    width: 100%;
    max-width: 100%;
    min-height: 100svh;
    padding: 18px 12px 24px;
    justify-content: flex-start;
    align-items: center;
    overflow-x: hidden;
  }

  .header {
    width: 100%;
    margin-top: 12px;
    margin-bottom: 6px;
    padding: 0 10px;
  }

  h1 {
    font-size: clamp(28px, 9vw, 38px);
    line-height: 0.96;
  }

  .subtitle {
    font-size: 14px;
    max-width: 310px;
    margin-left: auto;
    margin-right: auto;
  }

  .stage {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: visible;
  }

  .helmet-wrap {
    width: min(94vw, 560px);
    max-width: 100%;
    margin: 0 auto;
  }

  .toolbar {
    width: min(100%, 390px);
    max-width: calc(100vw - 24px);
    margin: -4px auto 0;
    padding: 0;
    gap: 10px;
    display: grid;
    grid-template-columns: 1fr;
    justify-items: stretch;
  }

  .tool-btn {
    width: 100%;
    min-width: 0;
    max-width: none;
    height: 46px;
    font-size: 15px;
  }

  .tool-btn:hover {
    border-color: #000;
    color: #000;
    fill: #000;
    transform: none;
  }

  .tool-btn.active:hover {
    border-color: var(--blue);
    color: var(--blue);
    fill: var(--blue);
    background: #eef5ff;
  }

  .tool-btn.danger:hover {
    border-color: #000;
    color: #000;
    fill: #000;
  }

  .tool-btn:disabled:hover {
    border-color: #000;
    color: #000;
    fill: #000;
  }

  .size-control {
    width: 100%;
    height: 46px;
    display: grid;
    grid-template-columns: 46px 1fr 46px;
  }

  .size-btn {
    width: 46px;
    min-width: 46px;
    height: 46px;
  }

  .size-readout {
    width: 100%;
    min-width: 0;
    height: 46px;
  }

  .meta {
    display: none;
  }
}