:root {
  --c-base: #ffffff;
  --c-text: #202124;
  --c-muted: #5f6368;
  --c-main: #1a73e8;
  --c-main-light: #f8fafd;
  --c-surface: #f1f3f4;
  --c-surface-strong: #e8eaed;
  --c-border: #dadce0;
  --c-border-light: #edf0f2;
  --font-family: 'Noto Sans JP', sans-serif;
  --font-size-body: 0.875rem;
  --font-size-sm: 0.75rem;
  --font-size-h1: 1.75rem;
  --font-size-h2: 1.125rem;
  --font-size-h3: 0.8125rem;
  --line-height: 1.2;
  --letter-spacing: 0.04em;
  --space-xs: 0.25rem;
  --space-sm: 0.375rem;
  --space-md: 0.75rem;
  --space-lg: 1rem;
  --container-padding: clamp(0.75rem, 2vw, 1.5rem);
  --border-radius: 12px;
  --touch-target-min: 44px;
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: var(--font-family);
  font-size: var(--font-size-body);
  line-height: var(--line-height);
  letter-spacing: var(--letter-spacing);
  color: var(--c-text);
  background: var(--c-main-light);
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
  letter-spacing: inherit;
}

button,
label.button {
  user-select: none;
}

.skip-link {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 20;
  transform: translateY(-120%);
  min-height: var(--touch-target-min);
  padding: 0.75rem 1rem;
  background: var(--c-text);
  color: var(--c-base);
}

.skip-link:focus-visible {
  transform: translateY(0);
  outline: 3px solid color-mix(in srgb, var(--c-main) 45%, var(--c-base));
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  justify-content: space-between;
  padding: var(--space-md) var(--container-padding);
  background: var(--c-base);
}

.brand-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.375rem 0.75rem;
}

.app-header h1,
.app-header p,
.control-panel h2,
.control-panel h3,
.empty-state h2,
.empty-state p,
.preview-footer p {
  margin: 0;
}

.app-header h1 {
  font-size: var(--font-size-h1);
  line-height: 1.15;
  font-family: 'Lato', var(--font-family);
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--c-text);
}

.brand-by {
  font-family: 'Lato', var(--font-family);
  font-size: 0.75rem;
  font-weight: 300;
  letter-spacing: 0.08em;
  color: var(--c-muted);
  text-decoration: none;
}

.brand-by:hover {
  color: var(--c-main);
}

.app-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem 0.875rem;
  align-items: center;
  font-family: 'Lato', var(--font-family);
  font-size: 0.6875rem;
  font-weight: 400;
  letter-spacing: 0.08em;
}

.app-nav a,
.brand-by {
  color: var(--c-muted);
  text-decoration: none;
}

.app-nav a:hover,
.brand-by:hover {
  color: var(--c-main);
}

.app-nav a:focus-visible,
.brand-by:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--c-main) 45%, var(--c-base));
  outline-offset: 3px;
  border-radius: 999px;
}

.preview-footer,
.range-row,
.empty-state p,
.color-row {
  font-size: var(--font-size-sm);
}

.header-actions,
.view-actions,
.panel-head {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch-target-min);
  padding: 0.5rem 0.875rem;
  border: 0;
  border-radius: 999px;
  color: var(--c-text);
  background: var(--c-surface);
  font-weight: 400;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.button-primary {
  background: var(--c-main);
  color: var(--c-base);
}

.button-small {
  min-height: var(--touch-target-min);
  padding-inline: 0.75rem;
  font-size: var(--font-size-sm);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.button:hover:not(:disabled),
label.button:hover {
  background: var(--c-surface-strong);
}

.button-primary:hover:not(:disabled),
label.button-primary:hover {
  background: #1558b0;
}

.button:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--c-main) 45%, var(--c-base));
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 1fr;
  height: calc(100vh - 77px);
  min-height: 0;
}

.workspace {
  min-width: 0;
  padding: var(--container-padding);
  background: var(--c-main-light);
}

.drop-zone {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  height: calc(100vh - 153px);
  background-color: var(--c-base);
  background-image:
    linear-gradient(45deg, color-mix(in srgb, var(--c-text) 7%, var(--c-base)) 25%, transparent 25%),
    linear-gradient(-45deg, color-mix(in srgb, var(--c-text) 7%, var(--c-base)) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, color-mix(in srgb, var(--c-text) 7%, var(--c-base)) 75%),
    linear-gradient(-45deg, transparent 75%, color-mix(in srgb, var(--c-text) 7%, var(--c-base)) 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  overflow: hidden;
}

.drop-zone.is-dragging {
  background-color: #e8f0fe;
}

#previewCanvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 173px);
  width: auto;
  height: auto;
}

.empty-state {
  position: absolute;
  display: grid;
  gap: var(--space-sm);
  place-items: center;
  width: min(92%, 560px);
  padding: var(--space-lg);
  border-radius: 24px;
  background: var(--c-base);
  text-align: center;
}

.empty-state[hidden] {
  display: none;
}

.empty-state h2,
.control-panel h2 {
  font-size: var(--font-size-h2);
  font-weight: 700;
}

.preview-footer {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  justify-content: space-between;
  padding-top: var(--space-md);
  color: var(--c-muted);
}

.control-panel {
  display: grid;
  align-content: start;
  gap: 0.625rem;
  padding: 0.875rem;
  background: var(--c-base);
}

.panel-head {
  justify-content: space-between;
}

.control-group {
  display: grid;
  gap: 0.375rem;
  border-bottom: 0;
  border-radius: 18px;
  padding: 0.75rem;
  background: var(--c-main-light);
}

.control-group h3 {
  font-size: var(--font-size-h3);
  font-weight: 700;
  line-height: 1.15;
  color: var(--c-text);
  margin-bottom: 0.125rem;
}

.range-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-md);
  font-weight: 400;
  color: var(--c-muted);
  padding-top: 0.125rem;
}

output {
  min-width: 4rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 24px;
  min-height: 24px;
  margin: -0.125rem 0 0.25rem;
  accent-color: var(--c-main);
  appearance: none;
  background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border: 0;
  border-radius: 999px;
  background: var(--range-track, var(--c-surface-strong));
}

input[type="range"]::-webkit-slider-thumb {
  width: 16px;
  height: 16px;
  margin-top: -5px;
  border: 2px solid var(--c-base);
  border-radius: 50%;
  background: var(--c-main);
  appearance: none;
}

input[type="range"]::-moz-range-track {
  height: 6px;
  border: 0;
  border-radius: 999px;
  background: var(--range-track, var(--c-surface-strong));
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: 2px solid var(--c-base);
  border-radius: 50%;
  background: var(--c-main);
}

#brightness {
  --range-track: linear-gradient(90deg, #222222 0%, #777777 50%, #ffffff 100%);
}

#saturation {
  --range-track: linear-gradient(90deg, #9a9a9a 0%, #ff4d4d 18%, #ffcc00 34%, #35c46b 50%, #24a8ff 66%, #6b5cff 82%, #ff4dd2 100%);
}

#density {
  --range-track: linear-gradient(90deg, #f7f7f7 0%, #bdbdbd 35%, #777777 65%, #222222 100%);
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 0;
  border-radius: 999px;
  background: var(--c-surface);
  overflow: hidden;
}

.segmented-five {
  grid-template-columns: repeat(5, 1fr);
}

.segmented label {
  min-height: 32px;
  cursor: pointer;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  min-height: 32px;
  padding: 0.375rem;
  font-size: var(--font-size-sm);
  font-weight: 400;
}

.segmented input:checked + span {
  background: var(--c-base);
  color: var(--c-main);
  outline: 0;
}

.segmented input:focus-visible + span {
  outline: 3px solid color-mix(in srgb, var(--c-main) 45%, var(--c-base));
  outline-offset: -3px;
}

.download-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-sm);
}

.download-button {
  min-height: 40px;
  background: var(--c-surface);
}

.download-button:not(:disabled):hover {
  background: var(--c-surface-strong);
}

#curveCanvas {
  display: none;
  width: 100%;
  max-height: 44px;
  height: auto;
  border: 1px solid var(--c-border);
  border-radius: var(--border-radius);
  background: var(--c-base);
}

.color-row {
  display: grid;
  grid-template-columns: auto 44px 1fr;
  align-items: center;
  gap: var(--space-sm);
}

.color-row label {
  font-weight: 400;
}

input[type="color"] {
  width: 44px;
  height: 32px;
  padding: 2px;
  border: 0;
  border-radius: var(--border-radius);
  background: var(--c-surface);
}

.swatches {
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
}

.swatch {
  width: 32px;
  height: 32px;
  border: 2px solid var(--c-base);
  border-radius: 999px;
  cursor: pointer;
}

.swatch-white {
  background: #ffffff;
}

.swatch-gray {
  background: #d9d9d9;
}

.swatch-black {
  background: #333333;
}

@media (min-width: 768px) {
  .app-header,
  .preview-footer {
    flex-direction: row;
    align-items: center;
  }

  .brand-row {
    flex-direction: row;
    align-items: baseline;
  }
}

@media (min-width: 1024px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr) minmax(360px, 420px);
  }

  .control-panel {
    border-top: 0;
    height: calc(100vh - 77px);
    overflow: auto;
  }
}

@media (max-width: 1023px) {
  body {
    overflow: auto;
  }

  .app-shell {
    height: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
