﻿:root {
  color-scheme: light;
  --bg: #f3f0e8;
  --panel: rgba(255, 252, 246, 0.92);
  --line: #d7cfbe;
  --text: #1d1a16;
  --muted: #6f675a;
  --accent: #c96f3b;
  --shadow: 0 18px 50px rgba(65, 47, 26, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", "Yu Gothic UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.72), transparent 35%),
    linear-gradient(180deg, #efe8d8 0%, #f7f2e8 48%, #efe7db 100%);
}

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

.hero,
.controls,
.preview-card,
.result-header {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.hero {
  padding: 28px;
}

.hero h1,
.preview-card h2,
.result-header h2 {
  margin: 0 0 8px;
}

.hero p,
.result-header p {
  margin: 0;
  color: var(--muted);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  margin-top: 20px;
  padding: 20px 24px;
}

.file-input {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  cursor: pointer;
}

.file-input span {
  font-weight: 600;
}

.file-input input {
  max-width: 220px;
}

.grid-options {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 0;
  padding: 0;
  border: none;
}

.grid-options legend {
  margin-right: 8px;
  font-weight: 600;
}

.grid-options label {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  padding: 10px 14px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  cursor: pointer;
}

.action-button {
  min-height: 44px;
  padding: 12px 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.18s ease, opacity 0.18s ease;
}

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

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

.secondary-action {
  background: #fff;
  color: var(--text);
  border-color: var(--line);
}

.threshold-control {
  display: grid;
  grid-template-columns: auto minmax(180px, 220px) auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-radius: 18px;
  background: #fff;
  border: 1px solid var(--line);
}

.threshold-control span {
  font-weight: 600;
}

.threshold-control input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.threshold-control strong {
  min-width: 2.5ch;
  text-align: right;
}

.mode-toggle {
  display: grid;
  grid-template-columns: auto auto auto;
  gap: 12px;
  align-items: center;
  padding: 10px 14px;
  border-radius: 18px;
  background: #fff;
  border: 1px solid var(--line);
}

.mode-toggle span,
.mode-toggle strong {
  font-weight: 600;
}

.mode-toggle input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.preview {
  margin-top: 20px;
}

.preview-card {
  padding: 24px;
}

.preview-stage {
  position: relative;
  display: inline-block;
  max-width: min(100%, 520px);
}

#sourcePreview {
  display: block;
  width: 100%;
  max-height: 360px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
}

.grid-overlay {
  position: absolute;
  inset: 0;
  border-radius: 14px;
  overflow: hidden;
  touch-action: none;
}

.grid-line {
  position: absolute;
  touch-action: none;
}

.grid-line.vertical {
  top: 0;
  bottom: 0;
  width: 20px;
  margin-left: -10px;
  cursor: ew-resize;
}

.grid-line.horizontal {
  left: 0;
  right: 0;
  height: 20px;
  margin-top: -10px;
  cursor: ns-resize;
}

.grid-line::before {
  content: "";
  position: absolute;
  inset: 0;
}

.grid-line::after {
  content: "";
  position: absolute;
  background: rgba(201, 111, 59, 0.9);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.75);
  border-radius: 999px;
}

.grid-line.vertical::after {
  top: 0;
  bottom: 0;
  width: 2px;
  left: 50%;
  transform: translateX(-50%);
}

.grid-line.horizontal::after {
  left: 0;
  right: 0;
  height: 2px;
  top: 50%;
  transform: translateY(-50%);
}

.grid-line.active::after {
  background: rgba(36, 116, 255, 0.95);
}

.placeholder {
  margin: 0;
  color: var(--muted);
}

.result-header {
  margin-top: 20px;
  padding: 20px 24px;
}

.canvas-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.tile-header {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: var(--muted);
}

.tile-meta {
  margin: 0 0 12px;
  font-size: 0.82rem;
  color: var(--muted);
}

.tile-previews {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.tile-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.tile-download {
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.canvas-pane {
  display: grid;
  gap: 8px;
}

.canvas-pane span {
  font-size: 0.8rem;
  color: var(--muted);
}

.tile canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--line);
}

.transparent-preview {
  background:
    linear-gradient(45deg, #e6dece 25%, transparent 25%, transparent 75%, #e6dece 75%, #e6dece),
    linear-gradient(45deg, #e6dece 25%, transparent 25%, transparent 75%, #e6dece 75%, #e6dece);
  background-position: 0 0, 10px 10px;
  background-size: 20px 20px;
  background-color: #fffdf8;
}

@media (max-width: 720px) {
  .app {
    width: min(100% - 20px, 1120px);
    padding-top: 20px;
  }

  .controls {
    align-items: stretch;
  }

  .file-input,
  .grid-options label,
  .threshold-control,
  .mode-toggle,
  .action-button {
    width: 100%;
    justify-content: center;
  }

  .grid-options {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .threshold-control {
    grid-template-columns: 1fr;
  }

  .mode-toggle {
    grid-template-columns: 1fr auto auto;
  }

  .tile-previews {
    grid-template-columns: 1fr;
  }
}
