:root {
  --paper: #f6f1e7;
  --ink: #3b3530;
  --panel: rgba(255, 252, 246, 0.78);
  --shadow: 0 6px 22px rgba(70, 50, 30, 0.16);
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--paper);
  color: var(--ink);
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  font-family: system-ui, -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

canvas {
  position: fixed;
  left: 0;
  top: 0;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  cursor: pointer;
}

#intro {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
  transition: opacity 1.2s ease;
  line-height: 1.6;
  opacity: 0.8;
  padding: 0 16px;
}
#intro .title {
  font-size: 30px;
  font-weight: 300;
  letter-spacing: 0.3em;
  margin: 0 0 8px;
}
#intro p { margin: 0; font-size: 15px; }
#intro.hide { opacity: 0; }

#toolbar {
  position: fixed;
  top: calc(14px + env(safe-area-inset-top));
  right: calc(14px + env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  flex-wrap: wrap-reverse;
  align-content: flex-start;
  max-height: calc(100dvh - 130px);
  gap: 10px;
}
a.tool { color: inherit; }
.tool {
  width: 46px;
  height: 46px;
  border: none;
  border-radius: 50%;
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  display: grid;
  place-items: center;
  padding: 0;
  transition: transform 0.15s ease;
}
.tool:active { transform: scale(0.9); }
.tool svg { width: 24px; height: 24px; }
#size-dot { transition: r 0.2s ease; }
#btn-mode[hidden] { display: none; }
#btn-mode[data-mode="oil"] .water,
#btn-mode[data-mode="water"] .oil { display: none; }
body[data-mode="oil"] { background: #e3edf0; }
#btn-sound .off { display: none; }
#btn-sound.muted .on { display: none; }
#btn-sound.muted .off { display: inline; }

#palette {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: var(--panel);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
}
.swatch {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 50%;
  padding: 0;
  background: radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.55), transparent 42%), var(--c);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.18), 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform 0.2s cubic-bezier(.3, 1.6, .5, 1), box-shadow 0.2s ease;
}
.swatch.active {
  transform: translateY(-5px) scale(1.15);
  box-shadow: inset 0 -3px 6px rgba(0, 0, 0, 0.18), 0 0 0 3px #fff, 0 0 0 5px var(--c), 0 6px 12px rgba(0, 0, 0, 0.2);
}

#color-name {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  font-size: 14px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--panel);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}
#color-name.show { opacity: 1; }

@media (max-width: 620px) {
  #palette {
    display: grid;
    grid-template-columns: repeat(6, 38px);
    gap: 12px 14px;
    border-radius: 26px;
    padding: 12px 16px;
  }
  #color-name { bottom: calc(136px + env(safe-area-inset-bottom)); }
}

#error {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  background: var(--paper);
  font-size: 16px;
}
#error[hidden] { display: none; }
