:root {
  --bg-top: #050505;
  --bg-bottom: #020202;
  --panel: #050505;
  --panel-strong: #0d0d0d;
  --text-main: #f7f7f5;
  --text-soft: #7d7d79;
  --border: rgba(255, 255, 255, 0.12);
  --shadow: 0 20px 44px rgba(0, 0, 0, 0.42);
  --accent: #9a9a95;
  --accent-strong: #f1f1ed;
  --accent-deep: #a8a8a2;
  --cream: #0a0a0a;
}

* {
  box-sizing: border-box;
}

html,
body {
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Noto Sans JP", sans-serif;
  color: var(--text-main);
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

.page-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: clamp(28px, 5vh, 52px) 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

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

.hero {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: stretch;
  margin-bottom: 8px;
}

.hero-copy,
.panel {
  border-radius: 26px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.hero-copy {
  flex: 1;
  padding: 22px 24px 18px;
}

.hero-home {
  width: auto;
  height: auto;
  min-height: 0;
  display: inline-grid;
  justify-items: start;
  gap: 12px;
  padding: 0;
  text-align: left;
  border: 0;
  cursor: pointer;
  font: inherit;
  letter-spacing: normal;
  text-transform: none;
  color: inherit;
  background: var(--panel);
  box-shadow: none;
  line-height: inherit;
  transition: none;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
}

.hero-logo {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
}

.hero-logo-main {
  max-height: 45px;
}

.hero-logo-sub {
  max-height: 18px;
}

.hero-home:hover {
  transform: none;
}

.hero-home:focus,
.hero-home:focus-visible,
.hero-home:active {
  outline: none;
  box-shadow: none;
  transform: none;
}

h1,
h2,
h3 {
  margin: 0;
}

h1 {
  font-family: "Montserrat", sans-serif;
  font-size: clamp(2.2rem, 5vw, 3.5rem);
  line-height: 1;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: #f7f8fa;
}

.app-grid {
  display: grid;
  grid-template-columns: 360px minmax(0, 1fr);
  grid-template-areas:
    "controls preview"
    "actions actions";
  gap: 16px;
  align-content: start;
  align-items: start;
}

.app-grid:not(.is-preview-active) {
  grid-template-columns: minmax(320px, 420px);
  grid-template-areas: "upload";
  justify-content: center;
}

.panel {
  padding: 16px;
}

.upload-panel {
  grid-area: upload;
}

.is-hidden {
  display: none !important;
}

.controls-panel {
  grid-area: controls;
}

.controls-panel,
.actions-panel {
  opacity: 1;
  transform: translateY(0);
}

.controls-panel.is-revealing-panel,
.actions-panel.is-revealing-panel {
  animation: panelReveal 360ms ease both;
}

.actions-panel {
  grid-area: actions;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: min(100%, 420px);
  justify-self: center;
}

.info-panel {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.controls-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  justify-content: space-between;
  align-self: stretch;
}

.info-panel.has-image {
  opacity: 0.82;
}

.info-disclosure {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 10px;
}

.info-disclosure:last-child {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 10px;
}

.info-summary {
  list-style: none;
  cursor: pointer;
  width: 100%;
  font-size: 0.78rem;
  line-height: 1.45;
  color: rgba(255, 255, 255, 0.64);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.info-summary::-webkit-details-marker {
  display: none;
}

.info-summary::after {
  content: "+";
  font-family: "Montserrat", sans-serif;
  font-size: 0.76rem;
  color: var(--text-soft);
}

.info-disclosure[open] .info-summary::after {
  content: "−";
}

.info-compact {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 10px 0;
}

.info-compact-summary {
  list-style: none;
  cursor: pointer;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-family: "Montserrat", sans-serif;
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.info-compact-summary::-webkit-details-marker {
  display: none;
}

.info-compact-summary::after {
  content: "+";
  font-size: 0.78rem;
}

.info-compact[open] .info-compact-summary::after {
  content: "−";
}

.info-compact-content {
  display: grid;
  gap: 10px;
  padding-top: 10px;
}

.info-content {
  display: grid;
  gap: 6px;
  padding-top: 8px;
}

.info-text,
.info-note {
  margin: 0;
  line-height: 1.65;
  font-size: 0.76rem;
  color: rgba(255, 255, 255, 0.56);
}

.info-note {
  color: rgba(255, 255, 255, 0.4);
  font-size: 0.72rem;
  line-height: 1.6;
}

.info-link {
  color: rgba(255, 255, 255, 0.68);
  text-decoration: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.info-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
  line-height: 1.6;
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.52);
}

.upload-box {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 152px;
  padding: 24px;
  border: 1px dashed rgba(255, 255, 255, 0.14);
  border-radius: 0;
  background: #0c0c0c;
  text-align: center;
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease;
}

.upload-box:hover {
  border-color: rgba(255, 255, 255, 0.32);
  background: #101010;
}

.upload-box.is-dragover {
  border-color: rgba(255, 255, 255, 0.42);
  background: #141414;
}

.upload-box input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.upload-title {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.5;
  letter-spacing: 0.04em;
}

.upload-sub {
  display: block;
  margin-top: 8px;
  color: var(--text-soft);
  font-size: 0.84rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.control-group {
  display: grid;
  gap: 10px;
}

.control-group.is-disabled {
  opacity: 0.38;
}

.control-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.control-group label {
  font-family: "Montserrat", sans-serif;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-soft);
}

.control-value {
  font-family: "Montserrat", sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-soft);
}

select,
input[type="color"],
input[type="range"] {
  width: 100%;
}

select,
input[type="color"] {
  height: 48px;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 0;
  font: inherit;
  color: var(--text-main);
  background: var(--panel-strong);
}

input[type="color"] {
  padding: 6px;
}

.range-row {
  display: grid;
  grid-template-columns: 42px 1fr 42px;
  align-items: center;
  gap: 12px;
}

.step-btn {
  height: 40px;
  border-radius: 999px;
  background: #101010;
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  font-size: 1.15rem;
  font-weight: 700;
  box-shadow: none;
}

.step-btn:disabled,
input[type="range"]:disabled {
  cursor: default;
}

input[type="range"]:disabled {
  opacity: 0.65;
}

input[type="range"] {
  height: 28px;
  appearance: none;
  background: transparent;
  border-radius: 999px;
  outline: none;
  touch-action: pan-x;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.28);
  border-radius: 999px;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border-radius: 50%;
  background: #ffffff;
  border: 0;
  box-shadow: 0 0 0 10px rgba(255, 255, 255, 0.001);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.28);
  border-radius: 999px;
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #ffffff;
  border: 0;
}

.color-presets {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.color-swatch {
  height: 48px;
  border-radius: 0;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: transparent;
  box-shadow: none;
  position: relative;
  overflow: hidden;
}

.color-swatch[data-color="#ffffff"] {
  background: #ffffff;
}

.color-swatch[data-color="#d9d9d9"] {
  background: #d9d9d9;
}

.color-swatch[data-color="#7a7a7a"] {
  background: #7a7a7a;
}

.color-swatch[data-color="#000000"] {
  background: #000000;
}

.color-swatch.is-active {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4), 0 0 18px rgba(255, 255, 255, 0.12);
}

.custom-swatch {
  display: grid;
  grid-template-rows: auto 1fr;
  background: #101010;
  cursor: pointer;
  padding: 6px;
  align-items: stretch;
}

.custom-swatch-label {
  font-family: "Montserrat", sans-serif;
  font-size: 0.54rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-soft);
  position: static;
  display: block;
  margin-bottom: 4px;
  line-height: 1;
  text-align: left;
}

.custom-swatch-preview {
  display: block;
  width: 100%;
  min-height: 0;
  flex: 1;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: #ffffff;
}

.custom-swatch input[type="color"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
  padding: 0;
  border: 0;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.action-row button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.button-icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

.button-icon svg {
  width: 18px;
  height: 18px;
  display: block;
}

button {
  border: 1px solid transparent;
  border-radius: 0;
  height: 48px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease, border-color 180ms ease,
    background 180ms ease;
  font-family: "Montserrat", sans-serif;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

button:hover {
  transform: translateY(-2px);
}

.secondary-btn {
  background: #f5f5f0;
  color: #0a0a0a;
  border-color: rgba(255, 255, 255, 0.12);
  box-shadow: none;
}

.ghost-btn {
  background: #0c0c0c;
  color: var(--text-main);
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow: none;
}


.preview-panel {
  grid-area: preview;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.preview-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 12px;
}

.preview-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}

.preview-note {
  margin: 0;
  padding-left: 4px;
  font-family: "Montserrat", sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: var(--text-soft);
  text-align: left;
  opacity: 0;
  transform: translateY(8px);
}

.preview-meta.is-active .preview-note {
  opacity: 1;
  transform: translateY(0);
}

.controls-panel.is-revealing-panel .preview-note,
.preview-panel.is-revealing-note .preview-note {
  animation: panelReveal 360ms ease both;
}

.preview-meta.is-active .trace-actions {
  opacity: 1;
  transform: translateY(0);
}

.preview-meta.is-active .mode-switch {
  opacity: 1;
  transform: translateY(0);
}

.controls-panel.is-revealing-panel .trace-actions,
.preview-panel.is-revealing-note .trace-actions {
  animation: panelReveal 360ms ease both;
}

.controls-panel.is-revealing-panel .mode-switch,
.preview-panel.is-revealing-note .mode-switch {
  animation: panelReveal 360ms ease both;
}

.mode-btn {
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  display: block;
  align-self: stretch;
  min-width: 94px;
  height: 40px;
  margin: 0;
  padding: 0 16px;
  border: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  color: rgba(255, 255, 255, 0.58);
  font-size: 0.68rem;
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.08em;
  text-align: center;
  box-shadow: none;
}

.mode-btn:focus,
.mode-btn:focus-visible,
.mode-btn:active {
  outline: none;
  box-shadow: none;
}

.mode-btn:hover {
  transform: none;
}

.mode-btn.is-active {
  background: #f1f1ed;
  color: #080808;
  box-shadow: none;
}

.mode-btn.is-active:focus,
.mode-btn.is-active:focus-visible,
.mode-btn.is-active:active {
  background: #f1f1ed;
  color: #080808;
  box-shadow: none;
}

.mode-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.mode-switch {
  overflow: hidden;
  display: inline-grid;
  grid-template-columns: repeat(2, auto);
  gap: 0;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  align-items: stretch;
  opacity: 0;
  transform: translateY(8px);
}

.mode-switch .mode-btn:last-child {
  border-right: 0;
}

.trace-actions {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-left: 12px;
  padding: 0;
  border-left: 0;
  border-radius: 0;
  background: transparent;
  opacity: 0;
  transform: translateY(8px);
}

.trace-actions.is-hidden {
  display: none !important;
}

.trace-actions-label {
  display: inline-block;
  padding-left: 2px;
  font-family: "Montserrat", sans-serif;
  font-size: 0.56rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.44);
}

.trace-actions-row {
  display: inline-grid;
  grid-template-columns: repeat(2, auto);
  gap: 6px;
}

.trace-action-btn {
  min-width: 58px;
  height: 28px;
  padding: 0 10px;
  border-radius: 10px;
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  color: rgba(255, 255, 255, 0.76);
  font-size: 0.62rem;
  letter-spacing: 0.06em;
}

.canvas-wrap {
  position: relative;
  border-radius: 0;
  padding: 0;
  background: #0c0c0c;
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: grid;
  place-items: center;
  overflow: hidden;
  touch-action: auto;
  overscroll-behavior: auto;
}

.canvas-wrap.is-tracing {
  touch-action: none;
  overscroll-behavior: contain;
}

.canvas-stage {
  position: relative;
  display: inline-block;
  width: auto;
  max-width: 100%;
  line-height: 0;
  isolation: isolate;
}

canvas {
  display: block;
  width: auto;
  max-width: 100%;
  height: auto;
  max-height: 52vh;
  margin: 0 auto;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  cursor: crosshair;
  opacity: 1;
  transition: opacity 320ms ease;
}

.interaction-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
  background: transparent;
  touch-action: auto;
  pointer-events: none;
}

.interaction-canvas.is-interactive {
  pointer-events: auto;
}

.interaction-canvas.is-tracing {
  cursor: crosshair;
  touch-action: none;
}

.canvas-wrap.is-revealing canvas {
  opacity: 0;
}

.canvas-wrap.is-loading canvas,
.canvas-wrap.is-loading .interaction-canvas {
  opacity: 0;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: block;
  background: transparent;
  z-index: 2;
  pointer-events: none;
}

.loading-surface {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #0f0f0f;
}

.loading-stage {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
}

.shimmer-block {
  position: relative;
  overflow: hidden;
}

.shimmer-block::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.04) 35%,
    rgba(255, 255, 255, 0.18) 50%,
    rgba(255, 255, 255, 0.04) 65%,
    transparent 100%
  );
  animation: shimmer 1.6s ease-in-out infinite;
}

.canvas-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  pointer-events: none;
  color: var(--text-soft);
}

.canvas-placeholder p {
  margin: 0;
  font-family: "Montserrat", sans-serif;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.canvas-placeholder span {
  display: block;
  margin-top: 8px;
  font-size: 0.82rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.canvas-placeholder[hidden] {
  display: none !important;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

@keyframes panelReveal {
  from {
    opacity: 0;
    transform: translateY(10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 960px) {
  .hero,
  .app-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .page-shell {
    width: min(100% - 24px, 375px);
    padding: 20px 0 32px;
    height: auto;
  }

  .hero {
    gap: 16px;
    margin-bottom: 8px;
  }

  .hero-copy,
  .panel {
    border-radius: 22px;
  }

  .hero-copy {
    padding: 22px 20px;
  }

  .info-panel {
    gap: 8px;
  }

  h1 {
    font-size: clamp(2.2rem, 11vw, 3.2rem);
  }

  .hero-logo-main {
    max-height: 37px;
  }

  .hero-logo-sub {
    max-height: 14px;
  }

  .app-grid {
    grid-template-areas:
      "upload"
      "preview"
      "controls"
      "actions";
    gap: 16px;
  }

  .panel {
    padding: 16px;
  }

  .controls-panel {
    gap: 12px;
    justify-content: flex-start;
    align-self: auto;
  }

  .upload-box {
    min-height: 144px;
    padding: 18px;
    border-radius: 0;
  }

  .upload-title {
    font-size: 1rem;
  }

  .upload-sub {
    font-size: 0.88rem;
  }

  .range-row {
    grid-template-columns: 44px 1fr 44px;
    gap: 10px;
  }

  input[type="range"] {
    height: 34px;
  }

  input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
  }

  input[type="range"]::-webkit-slider-thumb {
    width: 16px;
    height: 16px;
    margin-top: -6px;
  }

  input[type="range"]::-moz-range-track {
    height: 4px;
  }

  input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
  }

  .step-btn {
    height: 44px;
  }

  button,
  select,
  input[type="color"] {
    height: 52px;
  }

  .tips-card {
    padding: 16px;
    border-radius: 18px;
  }

  .status-pill {
    white-space: normal;
    line-height: 1.45;
  }

  .canvas-wrap {
    min-height: 272px;
    padding: 0;
    border-radius: 0;
  }

  .preview-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 13px;
  }

  .preview-tools {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .actions-panel {
    width: auto;
    justify-self: stretch;
  }

  .mode-switch {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .trace-actions {
    width: 100%;
    margin-left: 0;
    padding: 0;
    border-left: 0;
    border-radius: 0;
    background: none;
  }

  .trace-actions-row {
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  canvas {
    width: auto;
    max-width: min(100%, 320px);
    height: auto;
    max-height: 40vh;
    border-radius: 0;
  }

  .loading-surface {
    width: 100%;
    height: 100%;
  }

  .loading-stage {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
  }

}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 16px, 375px);
    padding-top: 12px;
    height: auto;
  }

  .hero-copy,
  .hero-card,
  .panel {
    border-radius: 20px;
  }

  .hero-copy,
  .panel {
    padding: 16px;
  }

  .app-grid {
    gap: 12px;
  }

  .hero-home {
    gap: 10px;
  }

  .hero-logo-main {
    max-height: 29px;
  }

  .hero-logo-sub {
    max-height: 11px;
  }

  .preview-panel {
    padding-bottom: 10px;
  }

  .controls-panel {
    padding-top: 10px;
  }

  .action-row {
    grid-template-columns: 1fr 1fr;
  }


  .canvas-wrap {
    min-height: 248px;
    padding: 0;
  }

  canvas {
    width: auto;
    max-width: min(100%, 300px);
    height: auto;
    max-height: 36vh;
  }

  .loading-surface {
    width: 100%;
    height: 100%;
  }

  .loading-stage {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
  }

  .control-group {
    gap: 6px;
  }

  .range-row {
    grid-template-columns: 40px 1fr 40px;
    gap: 8px;
  }

  .step-btn {
    height: 40px;
  }

  .color-presets {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .color-swatch {
    height: 42px;
  }

  .tips-card ul {
    padding-left: 16px;
    line-height: 1.65;
  }
}
