:root {
  --walnut: #3e2a1f;
  --walnut-deep: #24160f;
  --walnut-mid: #5c4030;
  --linen: #e8dfd0;
  --ink: #2a1810;
  --cadmium-yellow: #f0b400;
  --cadmium-yellow-deep: #a86a08;
  --cadmium-red: #c4321a;
  --mix: #d9cfc3;
  --swatch: #c4321a;
  /* Clean CJK faces — avoid brush fonts that look jagged at large sizes */
  --font-ui: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-brand: "Noto Serif SC", "Songti SC", "STSong", serif;
}

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

html,
body {
  height: 100%;
  margin: 0;
}

body {
  color: var(--linen);
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.45;
  font-weight: 500;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  background-color: var(--walnut);
  background-image:
    repeating-radial-gradient(
      circle at 18% 22%,
      rgba(255, 214, 160, 0.05) 0 0.6px,
      transparent 0.85px 6px
    ),
    linear-gradient(168deg, var(--walnut-mid) 0%, var(--walnut) 46%, #2c1c14 100%);
  overflow: hidden;
}

button {
  font-family: inherit;
  touch-action: manipulation;
}

.desk {
  height: 100dvh;
  max-height: 100dvh;
  width: min(1200px, 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding:
    calc(0.45rem + env(safe-area-inset-top))
    calc(0.65rem + env(safe-area-inset-right))
    calc(0.55rem + env(safe-area-inset-bottom))
    calc(0.65rem + env(safe-area-inset-left));
  min-height: 0;
}

.desk-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex: 0 0 auto;
  position: relative;
}

.brand {
  margin: 0;
  text-align: center;
  font-family: var(--font-brand);
  font-size: clamp(1.45rem, 3.8vh, 2.35rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  line-height: 1.2;
  color: var(--cadmium-yellow);
  text-shadow: 0 1px 0 rgba(36, 22, 15, 0.35);
}

.btn-voice {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  min-height: 40px;
  padding: 0.35rem 0.7rem;
  border: 2px solid var(--cadmium-yellow-deep);
  border-radius: 8px;
  background: var(--cadmium-yellow);
  color: var(--ink);
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 2px 0 var(--cadmium-yellow-deep);
}

.btn-voice[aria-pressed="false"] {
  background: #f3eadc;
  border-color: var(--walnut);
  box-shadow: 0 2px 0 var(--walnut);
  opacity: 0.85;
}

.studio {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(150px, 26%) minmax(0, 1fr);
  gap: 0.65rem;
  align-items: stretch;
}

.studio-left {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  min-height: 0;
  min-width: 0;
}

.palette-panel,
.bowl-panel,
.canvas-panel {
  color: var(--ink);
  background-color: var(--linen);
  background-image:
    repeating-linear-gradient(
      90deg,
      rgba(92, 64, 40, 0.028) 0 1px,
      transparent 1px 3px
    ),
    repeating-linear-gradient(
      0deg,
      rgba(92, 64, 40, 0.022) 0 1px,
      transparent 1px 3px
    );
  border: 3px solid #6a4a34;
  box-shadow:
    inset 0 1px 0 rgba(255, 248, 236, 0.65),
    0 5px 0 var(--walnut-deep);
  min-height: 0;
}

.palette-panel {
  flex: 1 1 45%;
  display: flex;
  flex-direction: column;
  border-radius: 14px 6px 12px 6px;
  padding: 0.45rem 0.5rem 0.55rem;
  overflow: auto;
}

.bowl-panel {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  border-radius: 6px 14px 6px 12px;
  padding: 0.45rem 0.5rem 0.55rem;
}

.canvas-panel {
  display: flex;
  flex-direction: column;
  border-radius: 6px;
  padding: 0.45rem 0.55rem 0.55rem;
  min-width: 0;
}

.panel-label {
  margin: 0 0 0.4rem;
  font-size: clamp(0.95rem, 2.2vh, 1.2rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  line-height: 1.15;
  color: var(--walnut);
}

.palette {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.55rem 0.45rem;
  align-content: start;
  justify-items: center;
  flex: 1 1 auto;
  padding: 0.2rem 0.1rem;
}

.swatch {
  --swatch: #c4321a;
  position: relative;
  width: clamp(44px, 7.5vh, 58px);
  height: clamp(44px, 7.5vh, 58px);
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 40% 45% 42% 48%;
  cursor: pointer;
  background:
    radial-gradient(circle at 30% 26%, rgba(255, 255, 255, 0.78), transparent 42%),
    radial-gradient(circle at 74% 80%, rgba(36, 16, 8, 0.48), transparent 50%),
    var(--swatch);
  box-shadow:
    inset 0 -6px 7px rgba(40, 16, 8, 0.22),
    2px 3px 0 rgba(36, 22, 15, 0.38);
}

.swatch:active {
  transform: scale(0.94);
}

/* Soft paint-dab delete — large hit area, quiet look */
.swatch-delete {
  position: absolute;
  top: -6px;
  right: -6px;
  box-sizing: border-box;
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 48% 42% 50% 45%;
  background:
    radial-gradient(circle at 32% 28%, rgba(255, 255, 255, 0.95), transparent 55%),
    radial-gradient(circle at 70% 75%, rgba(90, 50, 30, 0.18), transparent 55%),
    #f6efe4;
  color: #a65a48;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow:
    inset 0 -2px 3px rgba(60, 30, 15, 0.12),
    0 1px 2px rgba(36, 22, 15, 0.2);
  opacity: 0.88;
}

.swatch-delete::before {
  content: "";
  position: absolute;
  inset: -10px;
}

.swatch-delete:hover,
.swatch-delete:focus-visible {
  opacity: 1;
  color: #8f3d2c;
  transform: scale(1.06);
}

.swatch-delete:active {
  transform: scale(0.94);
}

.bowl {
  --mix: #d9cfc3;
  width: min(118px, 28vw, 18vh);
  aspect-ratio: 1;
  margin: 0.1rem auto 0.25rem;
  border-radius: 50%;
  border: 8px solid #6e5344;
  background:
    radial-gradient(circle at 35% 30%, #fff8, transparent 40%),
    var(--mix);
  box-shadow:
    inset 0 10px 16px rgba(36, 18, 10, 0.38),
    inset 0 -8px 12px rgba(255, 248, 236, 0.2),
    0 5px 0 #3a291f;
}

.bowl.is-stirring {
  animation: oil-stir 600ms ease-in-out;
}

@keyframes oil-stir {
  0% {
    filter: hue-rotate(0deg) brightness(1);
    transform: rotate(0deg);
  }
  45% {
    filter: hue-rotate(16deg) brightness(1.14);
    transform: rotate(7deg);
  }
  100% {
    filter: hue-rotate(0deg) brightness(1);
    transform: rotate(0deg);
  }
}

.hint {
  margin: 0.15rem 0 0.45rem;
  min-height: 2.4em;
  text-align: center;
  font-size: clamp(0.85rem, 1.8vh, 1.05rem);
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink);
}

.bowl-actions {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.4rem;
}

.btn {
  appearance: none;
  flex: 1 1 0;
  min-width: 0;
  min-height: 44px;
  padding: 0.45rem 0.5rem;
  border: 2px solid var(--cadmium-yellow-deep);
  border-radius: 8px;
  background: var(--cadmium-yellow);
  color: var(--ink);
  font-size: clamp(0.9rem, 1.9vh, 1.1rem);
  line-height: 1.15;
  cursor: pointer;
  box-shadow: 0 3px 0 var(--cadmium-yellow-deep);
}

.btn:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 var(--cadmium-yellow-deep);
}

.btn-ghost {
  background: #f3eadc;
  color: var(--ink);
  border-color: var(--walnut);
  box-shadow: 0 3px 0 var(--walnut);
}

.btn-ghost:active {
  box-shadow: 0 1px 0 var(--walnut);
}

.btn-compact {
  flex: 0 0 auto;
  min-width: 4.5rem;
  min-height: 40px;
  padding: 0.3rem 0.7rem;
}

.canvas-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex: 0 0 auto;
  margin-bottom: 0.35rem;
}

.canvas-toolbar .panel-label {
  margin: 0;
}

#paint-canvas {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  height: 100%;
  max-height: 100%;
  touch-action: none;
  background: #efe4d4;
  border: 10px solid #d5c6b0;
  box-shadow:
    inset 0 0 0 1px rgba(90, 60, 32, 0.28),
    0 0 0 6px #4e3426,
    0 6px 0 var(--walnut-deep);
}

.swatch:focus-visible,
.swatch-delete:focus-visible,
.btn:focus-visible,
.btn-voice:focus-visible {
  outline: 3px solid var(--cadmium-yellow);
  outline-offset: 2px;
}

/* Portrait / narrow: still try side-by-side if wide enough; else stack compactly */
@media (max-width: 720px) and (orientation: portrait) {
  body {
    overflow: auto;
  }

  .desk {
    height: auto;
    max-height: none;
    min-height: 100dvh;
  }

  .studio {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(42vh, 1fr);
  }

  .studio-left {
    flex-direction: row;
    align-items: stretch;
  }

  .palette-panel,
  .bowl-panel {
    flex: 1 1 50%;
  }

  .palette {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .btn-voice {
    position: static;
    transform: none;
  }

  .desk-header {
    justify-content: space-between;
  }
}

@media (prefers-reduced-motion: reduce) {
  .bowl.is-stirring,
  .swatch:active,
  .btn:active {
    animation: none;
    transform: none;
  }
}
