:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --panel-alt: #f7f9fc;
  --text: #0f172a;
  --muted: #4b5563;
  --border: #dbe2ea;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --warning: #f59e0b;
  --danger: #dc2626;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top right, #d9e7ff 0, rgba(217, 231, 255, 0) 48%),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
  color: var(--text);
  font-family: "Segoe UI", "SF Pro Text", "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
  padding: 24px;
}

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  padding: 22px 24px;
}

.hero h1 {
  margin: 0 0 8px;
  font-size: clamp(1.6rem, 2.2vw, 2rem);
  letter-spacing: -0.02em;
}

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

.workspace {
  padding: 16px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.file-input {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  background: var(--panel-alt);
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 600;
  color: var(--text);
}

.file-input input {
  font-weight: 500;
  color: var(--muted);
  max-width: 250px;
}

.tool-buttons {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 8px;
}

button {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
  font-weight: 600;
  padding: 9px 14px;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

button:hover:not(:disabled) {
  background: #f3f6fb;
  border-color: #c8d4e1;
}

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

button:focus-visible,
.file-input input:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.25);
  outline-offset: 1px;
}

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

#lockBtn.is-active {
  background: #edf3ff;
  border-color: #bbd3ff;
  color: var(--primary-strong);
}

.canvas-wrap {
  position: relative;
  border-radius: 12px;
  border: 1px solid var(--border);
  background:
    linear-gradient(45deg, #eef2f8 25%, transparent 25%) 0 0 / 24px 24px,
    linear-gradient(-45deg, #eef2f8 25%, transparent 25%) 0 0 / 24px 24px,
    linear-gradient(45deg, transparent 75%, #eef2f8 75%) 0 0 / 24px 24px,
    linear-gradient(-45deg, transparent 75%, #eef2f8 75%) 0 0 / 24px 24px,
    #f8fafd;
  overflow: hidden;
}

canvas {
  display: block;
  width: 100%;
  max-height: 72vh;
  height: auto;
  background: #ffffff;
  touch-action: none;
}

.canvas-help {
  margin: 10px 2px 0;
  font-size: 0.95rem;
  color: var(--muted);
}

.result-card {
  padding: 18px;
}

.result-card h2 {
  margin: 0 0 10px;
  font-size: 1.2rem;
}

.metrics {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
}

.metric {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--panel-alt);
  padding: 12px;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.metric-value {
  display: block;
  margin-top: 4px;
  color: var(--primary-strong);
  font-size: 1.5rem;
  font-weight: 700;
}

.result-message {
  margin: 10px 0 0;
  color: var(--muted);
}

.result-message.is-error {
  color: var(--danger);
}

.info-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1.4fr 1fr;
}

.instructions,
.example {
  padding: 18px;
}

.instructions h2,
.example h3 {
  margin: 0 0 10px;
}

.instructions ol {
  margin: 0 0 10px;
  padding-left: 20px;
  color: #1f2937;
}

.instructions li + li {
  margin-top: 8px;
}

.note {
  margin: 0;
  color: #b45309;
  font-style: italic;
}

.example img {
  display: block;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
}

@media (max-width: 860px) {
  body {
    padding: 16px;
  }

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

  .file-input {
    width: 100%;
    justify-content: space-between;
  }
}
