/* shuimo — cream water surface + premium floating controls */

:root {
  --water: #f6ecda;
  --water-deep: #efe3cf;
  --ink: #2a2a2a;
  --ink-soft: #4a4a4a;
  --panel-bg: rgba(255, 252, 244, 0.72);
  --panel-border: rgba(60, 50, 30, 0.10);
  --panel-shadow: 0 6px 24px rgba(50, 40, 20, 0.10), 0 1px 2px rgba(50, 40, 20, 0.06);
  --vermillion: #b8332b;
  --selected-ring: rgba(20, 20, 20, 0.55);
  --font-serif: "Hiragino Mincho ProN", "Yu Mincho", "Songti SC", "Noto Serif JP", "Times New Roman", serif;
  --font-sans:  "Hiragino Sans", "Yu Gothic", "PingFang SC", "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: radial-gradient(120% 80% at 50% 40%, var(--water) 0%, var(--water-deep) 100%);
  font-family: var(--font-sans);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

/* ---------- Webcam overlay (M2) ---------- */

/* The video sits above the canvas, mirrored, in multiply blend so the ink
   shows through the hand silhouette — user feels their hand is "in" the
   water rather than floating over it. Hidden until gestures enabled. */
#webcam {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  object-fit: cover;
  transform: scaleX(-1);
  mix-blend-mode: multiply;
  opacity: 0;
  pointer-events: none;
  z-index: 2;
  transition: opacity 0.45s ease;
  /* Slight desaturation + warmth so the hand reads as part of the cream water. */
  filter: saturate(0.55) contrast(1.05) brightness(1.05);
}
#webcam.visible {
  opacity: 0.62;
}

/* Subtle progress ring around an open palm — fills clockwise as the hold
   approaches 1.5s. Uses conic-gradient + radial mask for a clean ring. */
#palm-ring {
  position: fixed;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: conic-gradient(
    rgba(184, 51, 43, 0.78) calc(var(--p, 0) * 360deg),
    rgba(184, 51, 43, 0.08) 0
  );
  -webkit-mask: radial-gradient(circle, transparent 60%, black 62%);
          mask: radial-gradient(circle, transparent 60%, black 62%);
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
  z-index: 4;
}
#palm-ring.visible {
  opacity: 1;
  transform: scale(1);
}

/* Lightweight inline status toast for gesture state changes. */
#gesture-toast {
  position: fixed;
  left: 50%;
  bottom: calc(clamp(20px, 4vh, 36px) + 64px);
  transform: translate(-50%, 8px);
  padding: 8px 14px;
  background: rgba(255, 252, 244, 0.92);
  color: var(--ink);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(10px) saturate(140%);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  font-size: 13px;
  letter-spacing: 0.02em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
  z-index: 11;
  max-width: min(420px, 80vw);
  text-align: center;
}
#gesture-toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* Language-toggle fade — briefly hides all translatable labels during the
   text swap so it reads as a graceful crossfade instead of a snap. */
.lang-fading [data-i18n],
.lang-fading .action-label,
.lang-fading .help-title,
.lang-fading .help-text strong,
.lang-fading .help-text small,
.lang-fading .help-foot {
  opacity: 0;
  transition: opacity 0.18s ease;
}

/* Gesture button active / loading affordances. */
.action.is-active {
  background: rgba(184, 51, 43, 0.10);
  color: var(--vermillion);
}
.action.is-active:hover:not(:disabled) {
  background: rgba(184, 51, 43, 0.16);
  color: var(--vermillion);
}
.action.is-loading {
  cursor: progress;
  opacity: 0.7;
}

/* Brief vermillion pulse on the "?" button right after the first time gestures
   come on, so the user notices help exists without us hijacking the canvas. */
#btn-help.pulse {
  animation: helpPulse 1.1s ease-in-out 3;
}
@keyframes helpPulse {
  0%, 100% { box-shadow: 0 0 0 0   rgba(184, 51, 43, 0.45); }
  50%      { box-shadow: 0 0 0 8px rgba(184, 51, 43, 0);    }
}

/* ---------- Help overlay ---------- */

.help-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 4vw;
}
.help-overlay[hidden] { display: none; }

.help-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(50, 40, 20, 0.18);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  animation: fadeIn 0.25s ease;
  cursor: pointer;
}

.help-card {
  position: relative;
  background: rgba(255, 252, 244, 0.96);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 36px clamp(24px, 4vw, 44px) 28px;
  box-shadow: 0 18px 56px rgba(50, 40, 20, 0.18);
  max-width: 460px;
  width: 100%;
  font-family: var(--font-sans);
  animation: cardIn 0.32s cubic-bezier(0.2, 0.7, 0.3, 1);
  /* Slight paper texture via subtle gradient. */
  background-image:
    radial-gradient(120% 80% at 20% 0%, rgba(255, 255, 255, 0.55) 0%, rgba(255, 252, 244, 0) 60%),
    radial-gradient(120% 80% at 80% 100%, rgba(50, 40, 20, 0.04) 0%, rgba(255, 252, 244, 0) 50%);
}

.help-close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  border-radius: 50%;
  transition: background 0.15s ease, color 0.15s ease;
}
.help-close:hover { background: rgba(40, 30, 15, 0.06); color: var(--ink); }

.help-eyebrow {
  font-family: var(--font-serif);
  letter-spacing: 0.32em;
  color: var(--vermillion);
  font-size: 12px;
  margin: 0 0 6px;
  text-transform: none;
}
.help-title {
  font-family: var(--font-serif);
  font-size: 22px;
  font-weight: 500;
  margin: 0 0 20px;
  color: var(--ink);
  letter-spacing: 0.02em;
}

.help-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.help-item {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.help-icon {
  flex: none;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  /* Emoji color is system-controlled; the subtle paper-ring frames it.  */
  background: rgba(184, 51, 43, 0.08);
  border-radius: 50%;
}
.help-text strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 3px;
  letter-spacing: 0.01em;
}
.help-text small {
  display: block;
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.5;
}
.help-foot {
  margin: 22px 0 0;
  font-size: 11px;
  color: rgba(60, 50, 30, 0.55);
  text-align: center;
  letter-spacing: 0.06em;
}
.help-foot kbd {
  font-family: inherit;
  background: rgba(40, 30, 15, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  border: 1px solid rgba(40, 30, 15, 0.06);
}

@keyframes cardIn {
  from { transform: scale(0.96) translateY(8px); opacity: 0; }
  to   { transform: scale(1)    translateY(0);    opacity: 1; }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* Mobile: near-fullscreen overlay with larger hit targets. */
@media (max-width: 560px) {
  .help-overlay { padding: 0; }
  .help-card {
    max-width: none;
    width: 100vw;
    min-height: 100vh;
    border-radius: 0;
    padding: clamp(48px, 10vh, 80px) 24px 32px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    animation: none;
  }
  .help-close {
    width: 44px;
    height: 44px;
    top: 16px;
    right: 16px;
    font-size: 28px;
  }
  .help-list { gap: 18px; }
  .help-icon { width: 36px; height: 36px; font-size: 26px; }
  .help-text strong { font-size: 15px; }
  .help-text small { font-size: 14px; }
}

/* ---------- Watermark ---------- */

.watermark {
  position: fixed;
  right: clamp(18px, 3vw, 36px);
  top: clamp(20px, 4vh, 48px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-family: var(--font-serif);
  color: rgba(50, 35, 15, 0.32);
  font-size: clamp(18px, 2.2vw, 26px);
  letter-spacing: 0.1em;
  pointer-events: none;
  user-select: none;
}
.watermark .kanji {
  line-height: 1.1;
  font-weight: 500;
}
.watermark .hanko {
  margin-top: 10px;
  width: clamp(22px, 2.6vw, 30px);
  height: clamp(22px, 2.6vw, 30px);
  border: 1.5px solid var(--vermillion);
  color: var(--vermillion);
  border-radius: 4px;
  display: grid;
  place-items: center;
  font-size: clamp(11px, 1.4vw, 15px);
  background: rgba(255, 248, 240, 0.18);
  transform: rotate(-2deg);
  opacity: 0.85;
}

/* ---------- Hint ---------- */

.hint {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-family: var(--font-serif);
  color: rgba(40, 30, 15, 0.55);
  letter-spacing: 0.08em;
  pointer-events: none;
  text-align: center;
  opacity: 0;
  animation: hintIn 0.8s ease-out 0.3s forwards;
  transition: opacity 0.7s ease;
}
.hint.fade { opacity: 0 !important; }
.hint-en { font-size: clamp(14px, 1.8vw, 18px); }
.hint-jp { font-size: clamp(11px, 1.4vw, 14px); letter-spacing: 0.25em; opacity: 0.8; }

@keyframes hintIn {
  to { opacity: 1; }
}

/* ---------- Panel ---------- */

.panel {
  position: fixed;
  left: 50%;
  bottom: clamp(20px, 4vh, 36px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  box-shadow: var(--panel-shadow);
  backdrop-filter: blur(14px) saturate(140%);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  z-index: 10;
}

.swatches {
  display: flex;
  gap: 8px;
}

.swatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  padding: 0;
  cursor: pointer;
  background: var(--c, #888);
  position: relative;
  outline: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.10);
}
.swatch:hover { transform: scale(1.08); }
.swatch[aria-checked="true"] {
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08), 0 0 0 2px var(--selected-ring), 0 1px 3px rgba(0,0,0,0.18);
  transform: scale(1.08);
}
.swatch.rainbow {
  background: conic-gradient(from 0deg, #C53030, #D4A017, #2D6A4F, #1B3A6B, #6B2D6A, #C53030);
}

/* ---------- Palette edit mode ---------- */

/* × button overlaid on each removable swatch; hidden unless editing. */
.swatch-x {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--vermillion);
  color: #fff;
  font-size: 13px;
  line-height: 1;
  font-weight: 600;
  display: none;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.swatches.editing .swatch-x {
  display: flex;
  pointer-events: auto;
}
/* Subtle "editable" wiggle on hover in edit mode. */
.swatches.editing .swatch:not(.swatch-add):not(.rainbow):hover {
  transform: scale(1.12);
}
/* In edit mode, the selection ring is dropped so the × hit target reads cleanly. */
.swatches.editing .swatch[aria-checked="true"] {
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.18);
}

/* "+" slot — dashed outline matching the panel's border vibe. */
.swatch.swatch-add {
  background: transparent;
  border: 1.5px dashed rgba(60, 50, 30, 0.32);
  box-shadow: none;
  color: rgba(60, 50, 30, 0.55);
  font-size: 18px;
  line-height: 1;
  font-weight: 400;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.swatch.swatch-add:hover {
  border-color: var(--vermillion);
  color: var(--vermillion);
  transform: scale(1.08);
}
.swatch.swatch-add .swatch-x { display: none !important; }

/* Hidden native color picker — we trigger it from a swatch click. */
#palette-picker {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

/* Mobile: ensure tap targets stay >= 36px. */
@media (max-width: 480px) {
  .swatch { width: 32px; height: 32px; }
  .swatches.editing .swatch { width: 36px; height: 36px; }
  .swatch-x { width: 18px; height: 18px; font-size: 14px; top: -6px; right: -6px; }
}

.divider {
  width: 1px;
  height: 22px;
  background: rgba(60, 50, 30, 0.16);
}

.actions {
  display: flex;
  gap: 4px;
}

.action {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-family: var(--font-sans);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  position: relative;
}
.action:hover:not(:disabled) {
  background: rgba(40, 30, 15, 0.06);
  color: var(--ink);
}
.action:active:not(:disabled) {
  background: rgba(40, 30, 15, 0.12);
}
.action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.action svg {
  width: 16px;
  height: 16px;
}
.action .badge {
  font-style: normal;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 2px 5px;
  margin-left: 2px;
  border-radius: 4px;
  background: rgba(184, 51, 43, 0.10);
  color: var(--vermillion);
}

@media (max-width: 480px) {
  .action span:not(.badge) { display: none; }
  .action { padding: 7px 9px; }
  .panel { gap: 10px; padding: 8px 10px; }
  .watermark { font-size: 18px; }
}
