:root {
  --bg: #0f1013;
  --sheet: #17181c;
  --segment: #22242a;
  --line: #272a31;
  --text: #ececef;
  --sub: #8a8d96;
  --sub-2: #a5a8b1;
  --grip: #3a3d46;
  --font: 'Noto Sans JP', system-ui, -apple-system, sans-serif;
  --mono: 'DM Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --header-h: 52px;
  --tap: 44px;
  color-scheme: dark;
}

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

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

button:focus-visible,
.slider:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  -webkit-user-select: none;
  user-select: none;
}

/* ヘッダー */
.header {
  flex: none;
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px 0 16px;
  position: relative;
  z-index: 20;
}

.app-name {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.space-switch { position: relative; }

.space-button {
  height: var(--tap);
  min-width: var(--tap);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  background: var(--segment);
}

.space-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 168px;
  padding: 4px;
  border-radius: 12px;
  background: var(--segment);
  border: 1px solid var(--line);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.45);
  display: flex;
  flex-direction: column;
}

.space-menu[hidden] { display: none; }

.space-menu button {
  height: var(--tap);
  padding: 0 12px;
  border-radius: 8px;
  text-align: left;
  font-size: 14px;
  color: var(--sub-2);
}

.space-menu button[aria-checked='true'] {
  color: var(--text);
  font-weight: 700;
  background: rgb(255 255 255 / 0.06);
}

/* 3Dビュー */
.viewport {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  outline: none;
}

.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.marker {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
}

.marker-dot {
  position: absolute;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  box-shadow: 0 0 0 1px rgb(0 0 0 / 0.4), 0 1px 5px rgb(0 0 0 / 0.45);
}

.marker.is-selected .marker-dot {
  width: 28px;
  height: 28px;
  margin: -14px 0 0 -14px;
  border-width: 3px;
  box-shadow: 0 0 0 3px rgb(15 16 19 / 0.6), 0 0 0 5px #fff, 0 2px 10px rgb(0 0 0 / 0.5);
}

.marker-tag,
.corner {
  position: absolute;
  left: 0;
  top: 0;
  white-space: nowrap;
}

.marker-tag {
  padding: 3px 9px;
  border-radius: 999px;
  background: rgb(15 16 19 / 0.85);
  box-shadow: 0 0 0 1px rgb(255 255 255 / 0.1);
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  font-weight: 500;
}

.corner {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: #fff;
  transform: translate(-50%, -50%);
  text-shadow: 0 1px 3px rgb(0 0 0 / 0.8);
}

.corner.is-back { color: var(--sub); }

.hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  margin: 0;
  text-align: center;
  font-size: 11px;
  color: var(--sub);
  pointer-events: none;
}

.note {
  position: absolute;
  left: 16px;
  right: 64px;
  top: 6px;
  margin: 0;
  font-size: 11px;
  line-height: 1.5;
  color: var(--sub-2);
  pointer-events: none;
}

/* スライダー（K と RGB の断面） */
.slider {
  position: relative;
  touch-action: none;
  cursor: pointer;
  --v: 0;
}

.slider-track {
  position: absolute;
  border-radius: 999px;
  background: var(--track, var(--segment));
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.14);
}

.slider-thumb {
  position: absolute;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--thumb, #888);
  box-shadow: 0 1px 6px rgb(0 0 0 / 0.5);
}

.slider.is-vertical { width: var(--tap); flex: 1; }
.slider.is-vertical .slider-track { left: 50%; width: 8px; margin-left: -4px; top: 12px; bottom: 12px; }
.slider.is-vertical .slider-thumb { left: 50%; top: calc(12px + var(--v) * (100% - 24px)); }

.slider.is-horizontal { height: var(--tap); flex: 1; }
.slider.is-horizontal .slider-track { top: 50%; height: 8px; margin-top: -4px; left: 12px; right: 12px; }
.slider.is-horizontal .slider-thumb { top: 50%; left: calc(12px + var(--v) * (100% - 24px)); }

.control-label,
.control-value {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--sub-2);
  text-align: center;
}

.control-value { min-width: 40px; }

.k-control {
  position: absolute;
  right: 4px;
  top: 40px;
  bottom: 32px;
  width: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.slice-control {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 26px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.axis-buttons {
  display: flex;
  padding: 2px;
  border-radius: 10px;
  background: var(--segment);
}

.axis-buttons button {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--sub-2);
}

.axis-buttons button[aria-checked='true'] {
  background: #fff;
  color: #000;
  font-weight: 500;
}

[hidden] { display: none !important; }

/* ボトムシート */
.sheet {
  flex: none;
  position: relative;
  z-index: 10;
  background: var(--sheet);
  border-radius: 20px 20px 0 0;
  padding: 0 16px calc(12px + env(safe-area-inset-bottom));
  overflow: hidden;
  touch-action: none;
  transition: height 0.26s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sheet-grip {
  display: flex;
  width: 100%;
  height: 28px;
  align-items: center;
  justify-content: center;
}

.sheet-grip span {
  width: 36px;
  height: 5px;
  border-radius: 999px;
  background: var(--grip);
}

.app[data-sheet='expanded'] .sheet-compact,
.app[data-sheet='compact'] .sheet-full { display: none; }

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
  background: var(--segment);
}

.tabs button {
  height: 40px;
  border-radius: 10px;
  font-size: 13px;
  color: var(--sub-2);
  white-space: nowrap;
}

.tabs button[aria-selected='true'] {
  background: #fff;
  color: #000;
  font-weight: 700;
}

.swatches {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
  margin-top: 14px;
}

.swatch {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  text-align: center;
}

.swatch-chip {
  height: 52px;
  border-radius: 10px;
  box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.08);
}

.swatch.is-selected .swatch-chip {
  box-shadow: 0 0 0 2px var(--sheet), 0 0 0 4px #fff;
}

.swatch-label {
  font-size: 11px;
  color: var(--sub-2);
  line-height: 14px;
}

.swatch-hex {
  margin-top: -4px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 16px;
  color: var(--text);
}

.swatches.is-small { margin-top: 2px; }
.swatches.is-small .swatch-chip { height: 36px; }

.compact-hex {
  margin: 10px 0 0;
  font-family: var(--mono);
  font-size: 15px;
  text-align: center;
}

.compact-hint {
  margin: 4px 0 0;
  font-size: 11px;
  color: var(--sub);
  text-align: center;
}

.info {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
}

.info li {
  display: grid;
  grid-template-columns: 60px 1fr var(--tap);
  align-items: center;
  height: var(--tap);
  border-top: 1px solid var(--line);
}

.info-label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--sub);
}

.info-value {
  font-family: var(--mono);
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.2s;
}

.info li.is-copied .info-value { color: #fff; }

.copy-button {
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  color: var(--sub-2);
  border-radius: 10px;
}

.copy-button:active { background: var(--segment); }
.copy-button .icon-check { display: none; }
.is-copied .copy-button .icon-copy { display: none; }
.is-copied .copy-button .icon-check { display: block; color: #fff; }

.toast {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + var(--header-h) + 10px);
  transform: translate(-50%, -8px);
  padding: 8px 14px;
  border-radius: 999px;
  background: #fff;
  color: #000;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  z-index: 30;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* PC：3Dを左、パネルを右 */
@media (min-width: 900px) {
  .app {
    display: grid;
    grid-template-columns: 1fr 400px;
    grid-template-rows: var(--header-h) 1fr;
  }

  .header { grid-column: 1 / -1; }

  .sheet {
    height: auto !important;
    border-radius: 20px 0 0 0;
    padding-top: 20px;
    touch-action: auto;
    overflow-y: auto;
  }

  .sheet-grip,
  .sheet-compact { display: none !important; }

  .app[data-sheet] .sheet-full { display: block; }
}
