:root {
  --bg-top: #f4eadf;
  --bg-bottom: #d8e0d1;
  --panel: rgba(250, 247, 242, 0.9);
  --panel-border: rgba(71, 58, 45, 0.14);
  --text-main: #2f261f;
  --text-soft: #66584c;
  --accent: #486c72;
  --accent-soft: rgba(72, 108, 114, 0.12);
  --guide-info: #2e5f78;
  --guide-info-shadow: rgba(46, 95, 120, 0.22);
  --guide-active: #b54a2c;
  --guide-active-shadow: rgba(181, 74, 44, 0.28);
  --guide-done: #4b6b43;
  --guide-done-shadow: rgba(75, 107, 67, 0.24);
  --shadow: 0 18px 40px rgba(58, 46, 32, 0.16);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.6), transparent 28%),
    linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 20px 0 32px;
}

.hero {
  margin-bottom: 14px;
}

.hero-copy {
  max-width: 760px;
}

.eyebrow {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
}

h1,
h2 {
  font-family: Georgia, "Times New Roman", serif;
}

h1 {
  margin: 0;
  font-size: clamp(1.8rem, 3vw, 2.8rem);
  line-height: 1.02;
  max-width: none;
}

.intro {
  margin: 8px 0 0;
  max-width: 48ch;
  font-size: 0.98rem;
  line-height: 1.45;
  color: var(--text-soft);
}

.workflow-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.workflow-button {
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid rgba(76, 54, 43, 0.16);
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.72);
  color: var(--text-main);
  cursor: pointer;
  transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.workflow-button.active {
  background: var(--accent);
  border-color: rgba(72, 108, 114, 0.55);
  color: #fff8f5;
}

.workflow-button:hover {
  transform: translateY(-1px);
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.controls-panel {
  display: grid;
  gap: 16px;
}

.panel-card,
.canvas-frame {
  background: var(--panel);
  backdrop-filter: blur(16px);
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  box-shadow: var(--shadow);
}

.panel-card {
  padding: 20px;
}

.panel-card h2 {
  margin: 0 0 16px;
  font-size: 1.35rem;
}

.subheading {
  margin: 0 0 12px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.05rem;
}

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

.control-group + .control-group {
  margin-top: 14px;
}

.grid-custom-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.comparison-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.grid-tools-divider {
  height: 1px;
  margin: 18px 0 16px;
  background: rgba(76, 54, 43, 0.12);
}

.comparison-toggle {
  margin-top: 16px;
}

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

.advanced-details {
  margin-top: 14px;
  border-top: 1px solid rgba(76, 54, 43, 0.12);
  padding-top: 12px;
}

.advanced-details summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--text-main);
  list-style: none;
}

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

.advanced-details summary::after {
  content: " +";
  color: var(--accent);
}

.advanced-details[open] summary::after {
  content: " -";
}

.advanced-group {
  margin-top: 14px;
}

label {
  font-weight: 700;
}

input[type="file"] {
  display: none;
}

.upload-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid rgba(76, 54, 43, 0.16);
  cursor: pointer;
  transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease;
}

.upload-button {
  background: var(--accent);
  color: #fff8f5;
  font-weight: 700;
}

.empty-upload-button {
  margin-top: 18px;
}

.secondary-upload {
  background: #fffaf4;
  color: var(--text-main);
}

.secondary-button {
  width: 100%;
  background: #fffaf4;
  color: var(--text-main);
}

.secondary-button + .secondary-button {
  margin-top: 10px;
}

.refine-undo {
  margin-top: 10px;
}

.inline-grid-button {
  margin-top: 14px;
}

.mode-buttons {
  display: grid;
  gap: 10px;
}

.mode-button {
  width: 100%;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 14px;
  border: 1px solid rgba(76, 54, 43, 0.16);
  background: #fffaf4;
  color: var(--text-main);
  cursor: pointer;
  transition: transform 150ms ease, background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.mode-button.active {
  background: var(--accent);
  border-color: rgba(72, 108, 114, 0.55);
  color: #fff8f5;
}

.upload-button:hover,
.secondary-button:hover,
.mode-button:hover {
  transform: translateY(-1px);
}

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

select,
input[type="number"] {
  min-height: 42px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(76, 54, 43, 0.16);
  background: #fffdfa;
  color: var(--text-main);
}

input[type="range"] {
  accent-color: var(--accent);
}

input[type="checkbox"] {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.meta-text {
  margin: 14px 0 0;
  color: var(--text-soft);
  line-height: 1.5;
}

.compact-meta {
  margin-top: 8px;
}

.canvas-panel {
  min-width: 0;
}

.canvas-guide-dock {
  margin-bottom: 10px;
}

.canvas-actions {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.canvas-action-button {
  width: auto;
  min-width: 180px;
}

.mobile-upload-button,
.mobile-grid-button {
  display: none;
}

.canvas-frame {
  min-height: 640px;
  padding: 18px;
  transition: transform 150ms ease, border-color 150ms ease, box-shadow 150ms ease;
}

.canvas-frame.drag-active {
  transform: scale(1.005);
  border-color: rgba(191, 46, 46, 0.4);
  box-shadow: 0 24px 52px rgba(191, 46, 46, 0.12);
}

.empty-state,
.image-stage {
  border-radius: 18px;
  overflow: hidden;
}

.empty-state {
  min-height: 604px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 32px;
  border: 2px dashed rgba(76, 54, 43, 0.16);
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.18)),
    repeating-linear-gradient(
      45deg,
      rgba(191, 46, 46, 0.05) 0,
      rgba(191, 46, 46, 0.05) 10px,
      transparent 10px,
      transparent 20px
    );
}

.empty-state h2 {
  margin: 0 0 8px;
  font-size: 2rem;
}

.empty-state p {
  margin: 0;
  max-width: 34ch;
  color: var(--text-soft);
  line-height: 1.5;
}

.image-stage {
  position: relative;
  display: inline-block;
  max-width: 100%;
  cursor: crosshair;
}

.canvas-guide {
  position: static;
  padding: 12px 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--guide-info), #244b5e);
  color: #fff8f5;
  font-size: 0.95rem;
  line-height: 1.4;
  box-shadow: 0 12px 28px var(--guide-info-shadow);
  border: 1px solid rgba(255, 248, 245, 0.2);
}

@media (min-width: 761px) {
  .canvas-guide-dock {
    position: sticky;
    top: 14px;
    z-index: 12;
    margin-bottom: 14px;
  }

  .canvas-guide {
    padding: 14px 18px;
    border-radius: 18px;
  }

  .guide-header {
    margin-bottom: 8px;
  }

  .guide-badge,
  .guide-progress {
    min-height: 30px;
    padding: 0 12px;
    font-size: 0.86rem;
  }

  .guide-text {
    font-size: 1.05rem;
  }
}

.canvas-guide.attention {
  animation: guidePulse 1.4s ease-in-out infinite;
}

.canvas-guide.guide-active {
  background: linear-gradient(135deg, var(--guide-active), #8f3922);
  box-shadow: 0 12px 28px var(--guide-active-shadow);
}

.canvas-guide.guide-done {
  background: linear-gradient(135deg, var(--guide-done), #3c5735);
  box-shadow: 0 12px 28px var(--guide-done-shadow);
}

.guide-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.guide-badge,
.guide-progress {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(255, 248, 245, 0.16);
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.guide-badge {
  text-transform: uppercase;
}

.guide-text {
  font-size: 1rem;
  font-weight: 600;
}

@keyframes guidePulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 12px 28px rgba(120, 20, 20, 0.26);
  }

  50% {
    transform: scale(1.01);
    box-shadow: 0 16px 34px rgba(120, 20, 20, 0.34);
  }
}

.corner-action-bar {
  position: absolute;
  left: 50%;
  bottom: 16px;
  z-index: 6;
  transform: translateX(-50%);
}

.corner-action-button {
  width: auto;
  min-width: 220px;
  background: #fff3eb;
  border-color: rgba(181, 74, 44, 0.28);
  color: #7b2f1d;
  box-shadow: 0 10px 24px rgba(181, 74, 44, 0.18);
}

.corner-action-button.ready {
  background: linear-gradient(135deg, var(--guide-active), #8f3922);
  border-color: rgba(255, 248, 245, 0.28);
  color: #fff8f5;
  box-shadow: 0 14px 30px rgba(181, 74, 44, 0.34);
  animation: applyPulse 1.25s ease-in-out infinite;
}

@keyframes applyPulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 14px 30px rgba(181, 74, 44, 0.34);
  }

  50% {
    transform: scale(1.02);
    box-shadow: 0 18px 34px rgba(181, 74, 44, 0.42);
  }
}

.image-stage canvas {
  display: block;
  max-width: 100%;
  height: auto;
}

.image-stage #gridCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.image-stage #overlayCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.hidden {
  display: none;
}

body.fullscreen-active,
body.focus-mode {
  overflow: hidden;
}

body.fullscreen-active .app-shell,
body.focus-mode .app-shell {
  width: calc(100% - 24px);
  padding-top: 12px;
  padding-bottom: 12px;
}

body.fullscreen-active .hero,
body.fullscreen-active .controls-panel,
body.focus-mode .hero,
body.focus-mode .controls-panel {
  display: none;
}

body.fullscreen-active .workspace,
body.focus-mode .workspace {
  grid-template-columns: 1fr;
}

body.fullscreen-active .canvas-frame,
body.focus-mode .canvas-frame {
  min-height: calc(100vh - 24px);
  display: grid;
  place-items: center;
}

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

  .canvas-frame {
    min-height: 420px;
  }

  .empty-state {
    min-height: 384px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100%, calc(100% - 20px));
    padding: 12px 0 24px;
  }

  .hero {
    margin-bottom: 10px;
  }

  .intro,
  .meta-text.compact-meta,
  #modeDescription {
    font-size: 0.92rem;
  }

  .workspace {
    gap: 14px;
  }

  .workflow-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
  }

  .workflow-button {
    min-height: 48px;
    padding: 0 10px;
    font-size: 0.95rem;
  }

  .canvas-panel {
    order: -1;
  }

  .canvas-frame {
    min-height: 260px;
    padding: 10px;
    border-radius: 18px;
  }

  .empty-state {
    min-height: 240px;
    padding: 20px;
  }

  .controls-panel {
    gap: 12px;
  }

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

  .panel-card h2 {
    margin-bottom: 12px;
    font-size: 1.2rem;
  }

  .control-group + .control-group {
    margin-top: 12px;
  }

  select,
  input[type="number"] {
    min-height: 46px;
    font-size: 1rem;
  }

  input[type="range"] {
    min-height: 28px;
  }

  .upload-button,
  .secondary-button,
  .mode-button {
    min-height: 48px;
  }

  .mode-buttons {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .mode-button {
    padding: 0 10px;
    font-size: 0.92rem;
  }

  .canvas-actions {
    position: sticky;
    bottom: 10px;
    z-index: 20;
    justify-content: stretch;
    gap: 8px;
    padding: 10px;
    border-radius: 16px;
    background: rgba(250, 247, 242, 0.92);
    backdrop-filter: blur(10px);
    box-shadow: 0 12px 26px rgba(58, 46, 32, 0.14);
  }

  .canvas-action-button {
    flex: 1 1 0;
    min-width: 0;
    padding: 0 10px;
    font-size: 0.95rem;
  }

  .mobile-upload-button,
  .mobile-grid-button {
    display: inline-flex;
  }

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

  .canvas-guide {
    padding: 10px 12px;
    font-size: 0.9rem;
  }

  .guide-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }

  .guide-text {
    font-size: 0.95rem;
  }

  .corner-action-bar {
    left: 8px;
    right: 8px;
    bottom: 76px;
    transform: none;
  }

  .corner-action-button {
    width: 100%;
    min-width: 0;
  }

  body.focus-mode .app-shell {
    width: 100%;
    padding: 0;
    margin: 0;
  }

  body.focus-mode .workspace {
    gap: 0;
  }

  body.focus-mode .canvas-panel {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: #0e0b09;
    display: grid;
    grid-template-rows: 1fr auto;
    padding: 0;
  }

  body.focus-mode .canvas-frame {
    min-height: 100vh;
    border-radius: 0;
    border: 0;
    box-shadow: none;
    background: #0e0b09;
    padding: 0;
    display: grid;
    place-items: center;
  }

  body.focus-mode .image-stage,
  body.focus-mode .empty-state {
    border-radius: 0;
    width: 100%;
  }

  body.focus-mode .canvas-actions {
    position: fixed;
    left: 8px;
    right: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    z-index: 1001;
    margin-top: 0;
  }
}
