:root {
  --ink: #1c2b33;
  --paper: #f6f7f8;
  --card: #ffffff;
  --line: #dde3e7;
  --accent: #1f6f5c;
  --accent-dark: #175646;
  --danger: #b23b3b;
  --muted: #6b7780;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
}

.wrap {
  max-width: 460px;
  margin: 8vh auto;
  padding: 0 20px;
}

.wrap.wide {
  max-width: 900px;
  margin: 4vh auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  margin-bottom: 20px;
}

h1 {
  font-size: 1.4rem;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 12px;
}

.muted { color: var(--muted); font-size: 0.92rem; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 18px;
  flex-wrap: wrap;
  gap: 8px;
}

form label {
  display: block;
  margin-bottom: 14px;
  font-size: 0.88rem;
  color: var(--muted);
}

input, select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 0.95rem;
  background: #fff;
  color: var(--ink);
}

input:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 0.92rem;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover { background: var(--accent-dark); }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #8f2e2e; }

.btn-small { padding: 5px 10px; font-size: 0.82rem; }

.error {
  color: var(--danger);
  font-size: 0.9rem;
  background: #fbeaea;
  border: 1px solid #f0caca;
  padding: 8px 12px;
  border-radius: 6px;
}

.notice {
  font-size: 0.9rem;
  background: #eef2f0;
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 6px;
}

.notice.ok { background: #e7f3ee; border-color: #bfe0d2; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--line);
}

.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.inline-form input, .inline-form select {
  width: auto;
  margin-top: 0;
}

.inline-form.small input {
  width: 140px;
}

code {
  background: #eef1f2;
  padding: 1px 5px;
  border-radius: 4px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.tool-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s ease;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.tool-card:hover {
  border-color: var(--accent);
}

.tool-card b {
  font-size: 0.95rem;
}

#panel-body label {
  margin-bottom: 14px;
}

#panel-body input[type="file"] {
  padding: 6px;
}

#status {
  min-height: 1.2em;
}

#cropStage {
  position: relative;
  display: inline-block;
  margin: 12px 0;
  max-width: 100%;
  touch-action: none;
}

#cropCanvas {
  display: block;
  max-width: 100%;
  border: 1px solid var(--line);
}

.crop-box {
  position: absolute;
  border: 2px solid var(--accent);
  background: rgba(31, 111, 92, 0.15);
  cursor: move;
  touch-action: none;
}

.crop-handle {
  position: absolute;
  width: 14px;
  height: 14px;
  background: #fff;
  border: 2px solid var(--accent);
  border-radius: 50%;
  touch-action: none;
}

.crop-handle[data-dir="nw"] { left: -8px; top: -8px; cursor: nwse-resize; }
.crop-handle[data-dir="ne"] { right: -8px; top: -8px; cursor: nesw-resize; }
.crop-handle[data-dir="sw"] { left: -8px; bottom: -8px; cursor: nesw-resize; }
.crop-handle[data-dir="se"] { right: -8px; bottom: -8px; cursor: nwse-resize; }
.crop-handle.edge-h { left: 50%; margin-left: -7px; }
.crop-handle[data-dir="n"] { top: -8px; cursor: ns-resize; }
.crop-handle[data-dir="s"] { bottom: -8px; cursor: ns-resize; }
.crop-handle.edge-v { top: 50%; margin-top: -7px; }
.crop-handle[data-dir="w"] { left: -8px; cursor: ew-resize; }
.crop-handle[data-dir="e"] { right: -8px; cursor: ew-resize; }
