@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg-0: #0a0a0a;
  --bg-1: #121212;
  --bg-2: #191919;
  --bg-3: #222222;
  --bg-4: #2c2c2c;
  --border: #3a3a3a;
  --border-soft: #262626;
  --text-0: #f2f2f0;
  --text-1: #b8b8b5;
  --text-2: #8a8a86;
  --text-3: #5c5c58;
  --amber: #e8a33d;
  --amber-solid: #e8a33d;
  --amber-soft: #4a3a20;
  --verdigris: #5fbfa0;
  --verdigris-soft: #1f3a34;
  --rust: #d1633f;
  --rust-soft: #452420;
  --font-display: 'Space Grotesk', 'Inter', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
  --radius: 6px;
  --radius-lg: 10px;
  --topbar-h: 50px;
  --toolbar-w: 200px;
  --layers-w: 200px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { color-scheme: dark; height: 100%; }

body {
  background: var(--bg-0);
  background-image:
    repeating-linear-gradient(180deg, rgba(128,128,128,0.02) 0px, rgba(128,128,128,0.02) 1px, transparent 1px, transparent 3px);
  color: var(--text-0);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }
::selection { background: var(--amber-soft); color: var(--text-0); }
*:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* ---------- header ---------- */

header {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-1);
  flex-shrink: 0;
  z-index: 10;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.06em;
  color: var(--text-0);
  display: flex;
  align-items: center;
  gap: 8px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.actions .btn,
.actions button,
.actions label {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--text-0);
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;
}

.actions .btn:hover,
.actions button:hover {
  background: var(--bg-4);
  border-color: var(--text-3);
}

#releaseOwner {
  background: var(--rust-soft);
  border-color: var(--rust);
  color: var(--rust);
}
#releaseOwner:hover {
  background: var(--rust);
  color: var(--text-0);
}

/* ---------- main layout ---------- */

main {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ---------- left toolbar ---------- */

.toolbar {
  width: var(--toolbar-w);
  flex-shrink: 0;
  background: var(--bg-1);
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 10px;
  overflow-y: auto;
}

.toolbar .tool {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: var(--radius);
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-1);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  text-align: center;
}

.toolbar .tool:hover {
  background: var(--bg-2);
  color: var(--text-0);
}

.toolbar .tool.active {
  background: var(--amber-soft);
  border-color: var(--amber);
  color: var(--amber);
}

.toolbar label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  color: var(--text-2);
  font-size: 11.5px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding-top: 6px;
  border-top: 1px solid var(--border-soft);
}

.toolbar input[type="range"] {
  width: 100%;
  accent-color: var(--amber);
  background: var(--bg-2);
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 2px;
  outline: none;
  border: none;
}

.toolbar input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--amber);
  cursor: pointer;
  border: 2px solid var(--bg-1);
}

.toolbar input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--amber);
  cursor: pointer;
  border: 2px solid var(--bg-1);
}

#sizeValue {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-1);
  text-align: center;
}

#color {
  width: 100%;
  height: 32px;
  padding: 2px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

/* hue wheel */

#wheel {
  width: 100%;
  aspect-ratio: 1;
  max-width: 140px;
  margin: 0 auto;
  border-radius: 50%;
  background: conic-gradient(
    hsl(0,100%,50%), hsl(30,100%,50%), hsl(60,100%,50%),
    hsl(90,100%,50%), hsl(120,100%,50%), hsl(150,100%,50%),
    hsl(180,100%,50%), hsl(210,100%,50%), hsl(240,100%,50%),
    hsl(270,100%,50%), hsl(300,100%,50%), hsl(330,100%,50%),
    hsl(360,100%,50%)
  );
  border: 2px solid var(--border);
  cursor: crosshair;
  transition: border-color 0.12s;
}

#wheel:hover {
  border-color: var(--amber);
}

#clear {
  background: transparent;
  border: 1px solid var(--rust-soft);
  color: var(--rust);
  padding: 7px 10px;
  border-radius: var(--radius);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  margin-top: auto;
}

#clear:hover {
  background: var(--rust-soft);
  color: var(--text-0);
}

/* ---------- canvas stage ---------- */

.stage {
  flex: 1;
  min-width: 0;
  background: var(--bg-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 24px;
  background-image:
    linear-gradient(45deg, var(--bg-3) 25%, transparent 25%),
    linear-gradient(-45deg, var(--bg-3) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, var(--bg-3) 75%),
    linear-gradient(-45deg, transparent 75%, var(--bg-3) 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

#canvas {
  background: #ffffff;
  box-shadow: 0 4px 32px rgba(0, 0, 0, 0.5);
  border-radius: 2px;
  max-width: 100%;
  max-height: 100%;
  cursor: crosshair;
}

/* ---------- right layers panel ---------- */

.layers {
  width: var(--layers-w);
  flex-shrink: 0;
  background: var(--bg-1);
  border-left: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.lh {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px;
  font-size: 11.5px;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
  border-bottom: 1px solid var(--border-soft);
}

.lh b {
  font-weight: 600;
  color: var(--text-1);
}

#addLayer {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-1);
  font-size: 14px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  padding: 0;
  line-height: 1;
}

#addLayer:hover {
  background: var(--amber-soft);
  border-color: var(--amber);
  color: var(--amber);
}

#layerList {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.layer {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 8px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s;
}

.layer:hover {
  background: var(--bg-2);
}

.layer.selected {
  background: var(--amber-soft);
  border: 1px solid rgba(232, 163, 61, 0.25);
}

.layer button {
  background: none;
  border: none;
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  transition: color 0.12s;
  flex-shrink: 0;
  width: 20px;
  text-align: center;
}

.layer button:hover {
  color: var(--text-0);
}

.layer .layerName {
  flex: 1;
  font-size: 13px;
  color: var(--text-1);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: none;
}

.layer.selected .layerName {
  color: var(--amber);
}

/* ---------- owner modal ---------- */

#ownerModal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

#ownerModal > div {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 340px;
  max-width: 90vw;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

#ownerModal h2 {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-0);
  margin-bottom: 16px;
}

#ownerForm {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#ownerForm input[type="password"] {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-0);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 0.12s;
  width: 100%;
}

#ownerForm input[type="password"]:focus {
  border-color: var(--amber);
}

#ownerForm input[type="password"]::placeholder {
  color: var(--text-3);
}

#ownerForm .form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 4px;
}

#cancelOwner {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-1);
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

#cancelOwner:hover {
  background: var(--bg-3);
  color: var(--text-0);
}

#claimOwner {
  background: var(--amber-solid);
  border: 1px solid var(--amber-solid);
  color: #241a08;
  padding: 8px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s;
}

#claimOwner:hover {
  background: #f0ac48;
}

#claimOwner:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ---------- hidden utility ---------- */

.hidden {
  display: none !important;
}

/* ---------- viewer / owner mode ---------- */

body.viewer-mode .toolbar,
body.viewer-mode .layers,
body.viewer-mode .actions {
  display: none !important;
}

body.viewer-mode header {
  justify-content: center;
}

body.viewer-mode .brand {
  display: none;
}

body.viewer-mode main {
  display: block;
}

body.viewer-mode .stage {
  width: 100%;
  height: calc(100vh - 58px);
}

body.owner-mode .stage {
  min-width: 0;
}

body.owner-mode .actions {
  display: flex;
}

/* ---------- responsive ---------- */

@media (max-width: 760px) {
  .toolbar {
    width: 56px;
    padding: 8px 6px;
    gap: 4px;
  }
  .toolbar .tool {
    font-size: 0;
    padding: 10px 6px;
  }
  .toolbar .tool::after {
    content: attr(data-tool);
    font-size: 10px;
  }
  .toolbar label {
    font-size: 0;
  }
  #sizeValue { display: none; }
  #wheel { max-width: 40px; }
  #color { height: 28px; }
  #clear { font-size: 0; padding: 8px; }
  #clear::after { content: '\2715'; font-size: 14px; }
  .layers {
    width: 160px;
  }
  .stage {
    padding: 12px;
  }
}
