:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #11110f;
  color: #f3f0e8;
  font-synthesis: none;
  --accent: #f06449;
  --surface: #1b1b18;
  --surface-hover: #252521;
  --border: rgb(243 240 232 / 18%);
  --muted: #aaa89f;
}

* {
  box-sizing: border-box;
}

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

body {
  background: #11110f;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: grid;
  grid-template-rows: 64px minmax(0, 1fr);
  width: 100%;
  height: 100%;
  min-width: 320px;
  min-height: 420px;
}

.top-bar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-width: 0;
  padding: 0 20px;
  border-bottom: 1px solid rgb(243 240 232 / 10%);
  background: rgb(17 17 15 / 94%);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 22px;
  min-width: max-content;
}

.brand-name {
  font-size: 11px;
  font-weight: 720;
  letter-spacing: 0.15em;
}

.steps {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px;
  border: 1px solid rgb(243 240 232 / 10%);
  border-radius: 8px;
  background: #161613;
}

.step {
  padding: 7px 9px;
  border-radius: 5px;
  color: #77766f;
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.08em;
  transition: color 140ms ease, background-color 140ms ease;
}

.step.is-active {
  background: #292823;
  color: #f3f0e8;
}

.step.is-guided {
  box-shadow: inset 0 0 0 1px rgb(240 100 73 / 58%);
}

.controls {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
}

.export-size {
  max-width: 92px;
  overflow: hidden;
  color: #85837b;
  font-size: 8px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.export-size.is-limited {
  color: #ffab99;
}

#image-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 36px;
  height: 38px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 0 13px;
  background: transparent;
  color: #dedbd3;
  font-size: 9px;
  font-weight: 680;
  letter-spacing: 0.08em;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition:
    color 130ms ease,
    border-color 130ms ease,
    background-color 130ms ease,
    transform 90ms ease,
    opacity 130ms ease;
}

.button svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.button--primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #15120f;
}

.button--secondary,
.button--icon,
.button--zoom-value {
  border-color: var(--border);
  background: var(--surface);
}

.button--tertiary {
  color: #aaa89f;
}

.button--download {
  border-color: rgb(240 100 73 / 52%);
  color: #f6b4a6;
}

.button--download.has-artwork {
  border-color: var(--accent);
  background: rgb(240 100 73 / 13%);
  color: #ffd0c6;
}

.button--icon {
  width: 38px;
  padding: 0;
}

.button--zoom-value {
  min-width: 57px;
  padding: 0 8px;
  font-variant-numeric: tabular-nums;
}

.button--compact {
  padding-inline: 10px;
}

.button:hover:not(:disabled) {
  border-color: rgb(243 240 232 / 32%);
  background: var(--surface-hover);
  color: #fff;
}

.button--primary:hover:not(:disabled) {
  border-color: #ff8269;
  background: #fa7257;
  color: #11110f;
}

.button:active:not(:disabled) {
  transform: translateY(1px);
}

.button:focus-visible,
.popover button:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

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

.zoom-controls {
  display: flex;
  gap: 2px;
  padding: 2px;
  border-radius: 9px;
  background: #0e0e0c;
}

[data-tooltip]::after {
  position: absolute;
  z-index: 50;
  top: calc(100% + 10px);
  left: 50%;
  padding: 7px 9px;
  border: 1px solid rgb(243 240 232 / 14%);
  border-radius: 6px;
  background: #252521;
  box-shadow: 0 8px 24px rgb(0 0 0 / 32%);
  color: #f3f0e8;
  content: attr(data-tooltip);
  font-size: 9px;
  font-weight: 520;
  letter-spacing: 0;
  line-height: 1.2;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -3px);
  transition: opacity 100ms ease 500ms, transform 100ms ease 500ms;
}

[data-tooltip]:hover::after,
[data-tooltip]:focus-visible::after {
  opacity: 1;
  transform: translate(-50%, 0);
}

.workspace {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 46%, #1c1c18 0%, #11110f 70%);
  isolation: isolate;
}

#canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: default;
  touch-action: none;
}

#canvas:focus-visible {
  outline: 2px solid rgb(240 100 73 / 70%);
  outline-offset: -3px;
}

#canvas.cursor-pen {
  cursor:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M8 1v4M8 11v4M1 8h4M11 8h4' stroke='%23F3F0E8' stroke-width='1'/%3E%3Cpath d='m8 5 3 3-3 3-3-3Z' fill='%23111111' stroke='%23F06449' stroke-width='1'/%3E%3C/svg%3E")
      8 8,
    crosshair;
}

#canvas.cursor-move {
  cursor: move;
}

#canvas.cursor-grab {
  cursor: grab;
}

#canvas.cursor-grabbing {
  cursor: grabbing;
}

#canvas.cursor-invalid {
  cursor: not-allowed;
}

.context-panel {
  position: absolute;
  z-index: 5;
  top: 22px;
  left: 24px;
  max-width: min(390px, calc(100% - 48px));
  padding: 12px 14px;
  border: 1px solid rgb(243 240 232 / 11%);
  border-radius: 8px;
  background: rgb(17 17 15 / 78%);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.context-panel p {
  margin: 0;
  color: #f3f0e8;
  font-size: 13px;
  font-weight: 560;
  line-height: 1.35;
}

.context-panel small {
  display: block;
  margin-top: 5px;
  color: #b6b3aa;
  font-size: 10px;
  line-height: 1.4;
}

.context-panel .inline-message {
  margin-top: 8px;
  color: #ffab99;
  font-size: 10px;
}

.mobile-mode-label {
  display: none;
}

.mobile-reset-button {
  display: none;
}

.context-actions {
  position: absolute;
  z-index: 7;
  bottom: 22px;
  left: 50%;
  display: flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid rgb(243 240 232 / 12%);
  border-radius: 10px;
  background: rgb(17 17 15 / 88%);
  box-shadow: 0 12px 34px rgb(0 0 0 / 28%);
  backdrop-filter: blur(12px);
  transform: translateX(-50%);
}

.empty-state {
  position: absolute;
  z-index: 6;
  top: 50%;
  left: 50%;
  display: grid;
  justify-items: center;
  gap: 13px;
  transform: translate(-50%, -50%);
  text-align: center;
}

.empty-state > span {
  font-size: 12px;
  font-weight: 720;
  letter-spacing: 0.18em;
}

.empty-state p {
  margin: 0 0 5px;
  color: #c0bdb4;
  font-size: 13px;
}

.empty-state small {
  color: #77766f;
  font-size: 9px;
  letter-spacing: 0.1em;
}

.first-use-hint {
  position: absolute;
  z-index: 6;
  top: 96px;
  left: 24px;
  max-width: 320px;
  padding: 8px 10px;
  border-left: 2px solid var(--accent);
  background: rgb(17 17 15 / 82%);
  color: #e8e5dd;
  font-size: 10px;
  line-height: 1.35;
  pointer-events: none;
}

.popover {
  position: absolute;
  z-index: 60;
  top: calc(100% + 10px);
  right: 0;
  border: 1px solid rgb(243 240 232 / 16%);
  border-radius: 8px;
  background: #22221e;
  box-shadow: 0 14px 38px rgb(0 0 0 / 42%);
  color: #e7e4dc;
}

.reset-control {
  position: relative;
}

.reset-popover {
  display: grid;
  width: 220px;
  gap: 12px;
  padding: 13px;
  font-size: 11px;
}

.reset-popover div {
  display: flex;
  gap: 8px;
}

.reset-popover button {
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 9px;
  background: #171714;
  color: #ddd9d0;
  font-size: 8px;
  font-weight: 650;
  cursor: pointer;
}

.reset-popover button:first-child {
  border-color: rgb(240 100 73 / 58%);
  color: #ffad9c;
}

.shortcuts-popover {
  width: 270px;
  padding: 14px;
}

.shortcuts-popover strong {
  font-size: 9px;
  letter-spacing: 0.13em;
}

.shortcuts-popover dl {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
}

.shortcuts-popover dl div {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 8px;
}

.shortcuts-popover dt,
.shortcuts-popover dd {
  margin: 0;
  font-size: 9px;
  line-height: 1.25;
}

.shortcuts-popover dt {
  color: #aaa89f;
}

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

[hidden] {
  display: none !important;
}

@media (max-width: 1120px) {
  .brand {
    gap: 10px;
  }

  .brand-name {
    display: none;
  }

  .button--compact span,
  .button--tertiary span {
    display: none;
  }

  .button--compact,
  .button--tertiary {
    width: 38px;
    padding: 0;
  }
}

@media (max-width: 820px) {
  .app {
    grid-template-rows: calc(56px + env(safe-area-inset-top)) minmax(0, 1fr);
  }

  .top-bar {
    align-items: flex-end;
    justify-content: center;
    padding: env(safe-area-inset-top) 10px 6px;
  }

  .brand,
  .zoom-controls,
  .reset-control,
  #shortcuts-button,
  .shortcuts-popover,
  .button--secondary span,
  .button--download span {
    display: none;
  }

  .controls {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
  }

  .export-size {
    display: none;
  }

  .export-size.is-limited {
    position: absolute;
    top: calc(100% + 9px);
    right: 0;
    display: block;
    max-width: none;
    padding: 5px 7px;
    border: 1px solid rgb(240 100 73 / 34%);
    border-radius: 5px;
    background: rgb(17 17 15 / 88%);
    font-size: 8px;
  }

  .button,
  .button--icon,
  .button--secondary,
  .button--download {
    width: 44px;
    min-width: 44px;
    height: 44px;
    padding: 0;
  }

  .context-panel {
    top: 10px;
    left: 10px;
    max-width: calc(100% - 20px);
    padding: 9px 11px;
  }

  .mobile-mode-label {
    display: block;
    margin-bottom: 5px;
    color: #f29b88;
    font-size: 8px;
    letter-spacing: 0.1em;
  }

  .mobile-reset-button {
    position: absolute;
    top: 8px;
    right: 9px;
    display: block;
    min-width: 44px;
    min-height: 44px;
    border: 0;
    padding: 0 5px;
    background: transparent;
    color: #8f8d85;
    font-size: 7px;
    font-weight: 650;
    letter-spacing: 0.08em;
    pointer-events: auto;
  }

  .mobile-reset-button.is-confirming {
    color: #ffab99;
  }

  .context-panel p,
  .context-panel small,
  .mobile-mode-label {
    padding-right: 62px;
  }

  .context-panel p {
    font-size: 11px;
  }

  .context-panel small {
    margin-top: 3px;
    font-size: 9px;
  }

  .first-use-hint {
    top: 88px;
    left: 10px;
    max-width: 250px;
  }

  .context-actions {
    right: 10px;
    bottom: calc(8px + env(safe-area-inset-bottom));
    left: 10px;
    display: grid;
    grid-template-columns: minmax(96px, 0.72fr) minmax(150px, 1.28fr);
    gap: 8px;
    width: auto;
    padding: 6px;
    transform: none;
  }

  .context-actions .button {
    width: 100%;
    min-height: 48px;
    font-size: 9px;
  }

  .empty-state {
    width: min(320px, calc(100% - 32px));
  }

  .empty-state .button {
    width: auto;
    min-width: 178px;
    padding-inline: 18px;
  }
}

@media (max-width: 620px) {
  .top-bar {
    overflow: visible;
  }

  .controls {
    min-width: 0;
  }
}

@media (max-width: 360px) {
  .controls {
    gap: 4px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    transition-delay: 0ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
