* {
  box-sizing: border-box;
}

:root {
  color-scheme: dark;
  --bg: #0e0b09;
  --panel: #1b1511;
  --panel-2: #241b15;
  --line: #3a2b21;
  --text: #f6eee6;
  --muted: #baa99a;
  --accent: #d79b55;
  --accent-soft: #f0bf80;
  --danger: #d26464;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(circle at 50% -10%, #2d2119 0, transparent 38%),
    var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  min-height: 44px;
  border: 1px solid #765537;
  border-radius: 11px;
  background: var(--accent);
  color: #24160d;
  font-weight: 750;
  cursor: pointer;
}

button.secondary {
  background: #241b15;
  color: var(--text);
  border-color: #4c392c;
}

button:disabled {
  opacity: .42;
  cursor: default;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + env(safe-area-inset-top)) 14px 11px;
  background: rgba(17, 13, 10, .88);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}

.app-header h1 {
  margin: 0;
  font-size: 21px;
  letter-spacing: .2px;
}

.app-header p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.icon-button {
  width: 42px;
  min-height: 42px;
  padding: 0;
  border-radius: 50%;
  background: #241b15;
  color: var(--accent-soft);
}

.app-shell {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 9px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(38, 28, 21, .96), rgba(24, 18, 14, .98));
  box-shadow: 0 18px 55px rgba(0, 0, 0, .18);
}

.toolbar {
  display: grid;
  grid-template-columns: 1.35fr repeat(4, 1fr);
  gap: 8px;
  padding: 10px;
  margin-bottom: 9px;
}

.file-button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border: 1px dashed #8f6844;
  border-radius: 11px;
  background: rgba(215, 155, 85, .08);
  color: var(--accent-soft);
  font-weight: 750;
  cursor: pointer;
}

.file-button input {
  display: none;
}

.workspace-panel {
  padding: 7px;
}

.workspace {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  min-height: 330px;
  overflow: hidden;
  border-radius: 12px;
  background:
    linear-gradient(45deg, #0b0908 25%, transparent 25%),
    linear-gradient(-45deg, #0b0908 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #0b0908 75%),
    linear-gradient(-45deg, transparent 75%, #0b0908 75%),
    #11100f;
  background-size: 22px 22px;
  background-position: 0 0, 0 11px, 11px -11px, -11px 0;
  touch-action: none;
  user-select: none;
}

canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.empty-state {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 30px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.empty-state strong {
  color: var(--text);
  font-size: 18px;
}

.empty-state span {
  max-width: 300px;
  font-size: 13px;
  line-height: 1.45;
}

.empty-icon {
  font-size: 46px;
  color: var(--accent);
}

.crop-mask {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
}

.crop-mask::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, .46);
  -webkit-mask:
    linear-gradient(#000 0 0),
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
}

.crop-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  width: var(--crop-size, 86%);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(240, 191, 128, .98);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .45);
}

.crop-mask::before {
  display: none;
}

.corner {
  position: absolute;
  width: 24px;
  height: 24px;
  border-color: white;
  border-style: solid;
}

.corner.tl { left: -3px; top: -3px; border-width: 3px 0 0 3px; }
.corner.tr { right: -3px; top: -3px; border-width: 3px 3px 0 0; }
.corner.bl { left: -3px; bottom: -3px; border-width: 0 0 3px 3px; }
.corner.br { right: -3px; bottom: -3px; border-width: 0 3px 3px 0; }

.rule-v,
.rule-h {
  position: absolute;
  background: rgba(255, 255, 255, .28);
}

.rule-v {
  top: 0;
  bottom: 0;
  width: 1px;
}

.rule-h {
  left: 0;
  right: 0;
  height: 1px;
}

.rule-v.one { left: 33.333%; }
.rule-v.two { left: 66.666%; }
.rule-h.one { top: 33.333%; }
.rule-h.two { top: 66.666%; }

.workspace-badge {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 4;
  padding: 6px 9px;
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 999px;
  background: rgba(10, 8, 7, .72);
  color: var(--accent-soft);
  font-size: 12px;
  font-weight: 750;
  backdrop-filter: blur(8px);
}

.workspace-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 4px 4px;
}

.workspace-footer > div:first-child {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.workspace-footer strong {
  font-size: 13px;
}

.workspace-footer span {
  color: var(--muted);
  font-size: 11px;
}

.gesture-hint {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 9px;
}

.control-card {
  padding: 12px;
}

.control-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.control-row label {
  font-weight: 700;
}

.control-row output {
  color: var(--accent-soft);
  font-weight: 750;
}

input[type="range"] {
  width: 100%;
  margin: 14px 0 3px;
  accent-color: var(--accent);
}

.status-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  margin-top: 9px;
  padding: 12px 14px;
}

.status-panel > div:first-child {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.status-panel span {
  color: var(--muted);
  font-size: 12px;
}

.status-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 18px rgba(215, 155, 85, .8);
}

dialog {
  width: min(420px, calc(100% - 30px));
  border: 1px solid #58412f;
  border-radius: 16px;
  background: #1d1611;
  color: var(--text);
}

dialog::backdrop {
  background: rgba(0,0,0,.72);
}

dialog h2 {
  margin-top: 0;
}

dialog p {
  color: var(--muted);
  line-height: 1.55;
}

dialog button {
  width: 100%;
}

@media (max-width: 700px) {
  .toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .file-button {
    grid-column: 1 / -1;
  }

  .controls-grid {
    grid-template-columns: 1fr;
  }

  .workspace-footer {
    flex-direction: column;
  }

  .gesture-hint {
    justify-content: flex-start;
  }
}
