:root {
  --bg: #f5f4f1;
  --paper: #fff;
  --ink: #242321;
  --muted: #77736d;
  --line: #ddd9d2;
  --line-dark: #c8c2b8;
  --accent: #292826;
  --accent-soft: #efede8;
  --danger: #a84646;
  --shadow: 0 12px 34px rgba(38, 35, 31, .07);
  font-family: "LINE Seed JP", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); }
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

#app { min-height: 100vh; }
.header { padding: 24px 30px 18px; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.72); backdrop-filter: blur(16px); }
.nav { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-name { font-size: 24px; font-weight: 800; letter-spacing: -.04em; }
.brand-separator { width: 1px; height: 22px; background: var(--line-dark); }
.brand-tool { font-size: 14px; font-weight: 600; color: var(--muted); }
.nav-links { display: flex; gap: 16px; margin: 0; padding: 0; list-style: none; font-size: 12px; }
.nav-links a { text-decoration: none; color: var(--muted); }
.nav-links a:hover { color: var(--ink); }
.app-subtitle { margin: 10px 0 0; color: var(--muted); font-size: 13px; }

.app-body { display: grid; grid-template-columns: 300px minmax(0, 1fr); min-height: calc(100vh - 170px); }
.sidebar { border-right: 1px solid var(--line); background: rgba(255,255,255,.55); padding: 18px; }
.sidebar-section { padding: 18px 0; border-bottom: 1px solid var(--line); }
.sidebar-section:last-child { border-bottom: 0; }
.section-title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
h2 { margin: 0; font-size: 14px; }
.section-hint, .custom-aspect-hint, .crop-hint, .local-note, .legal-note { color: var(--muted); font-size: 11px; line-height: 1.6; }
.section-hint { margin: 8px 0 12px; }

.dropzone { border: 1px dashed var(--line-dark); border-radius: 12px; background: rgba(255,255,255,.66); transition: .18s ease; }
.dropzone.dragging { border-color: var(--ink); background: #fff; transform: translateY(-1px); }
.dropzone-inner { padding: 26px 14px; text-align: center; }
.dropzone-icon { width: 40px; height: 40px; margin: 0 auto 10px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 50%; font-size: 21px; background: #fff; }
.dropzone p { margin: 0 0 12px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.source-meta { display: grid; gap: 4px; min-width: 0; }
.source-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 700; }
.source-meta small { color: var(--muted); }

.btn { min-height: 38px; padding: 0 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font-weight: 700; transition: .15s ease; }
.btn:hover:not(:disabled) { border-color: var(--line-dark); background: #faf9f7; }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-small { min-height: 32px; padding: 0 11px; font-size: 11px; }
.btn-text { min-height: auto; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 11px; }
.btn-primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #111; border-color: #111; }
.btn-danger { color: var(--danger); }
.btn-block { width: 100%; }

.count-badge { min-width: 26px; height: 24px; padding: 0 8px; display: inline-grid; place-items: center; border-radius: 999px; background: var(--accent-soft); color: var(--muted); font-size: 10px; font-weight: 700; }
.crop-list { display: grid; gap: 7px; max-height: 390px; overflow: auto; }
.empty-list { margin: 8px 0; color: var(--muted); font-size: 11px; }
.crop-list-item { display: grid; grid-template-columns: 28px minmax(0,1fr) auto; align-items: center; gap: 9px; width: 100%; padding: 9px; border: 1px solid var(--line); border-radius: 9px; background: #fff; text-align: left; }
.crop-list-item:hover, .crop-list-item.selected { border-color: var(--ink); }
.crop-list-item.selected { box-shadow: inset 3px 0 0 var(--ink); }
.crop-number { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 7px; background: var(--accent-soft); font-size: 10px; font-weight: 800; }
.crop-list-meta { min-width: 0; }
.crop-list-meta strong, .crop-list-meta small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crop-list-meta strong { font-size: 11px; }
.crop-list-meta small { margin-top: 2px; color: var(--muted); font-size: 9px; }
.crop-ratio { color: var(--muted); font-size: 9px; }

.editor { min-width: 0; }
.editor-empty { min-height: 650px; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.editor-content { display: grid; grid-template-columns: minmax(0, 1fr) 320px; min-height: 650px; }
.editor-main { min-width: 0; padding: 18px; }
.editor-controls { border-left: 1px solid var(--line); padding: 18px; background: rgba(255,255,255,.42); }
.canvas-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 10px; }
.toolbar-left { min-width: 0; display: grid; gap: 3px; }
.toolbar-left strong { font-size: 13px; }
.toolbar-left span { color: var(--muted); font-size: 10px; }
.toolbar-actions { display: flex; gap: 6px; }
.canvas-wrap { position: relative; width: 100%; min-height: 560px; display: grid; place-items: center; overflow: auto; border: 1px solid var(--line); border-radius: 12px; background-color: #e9e7e3; background-image: linear-gradient(45deg,#d9d6d0 25%,transparent 25%),linear-gradient(-45deg,#d9d6d0 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#d9d6d0 75%),linear-gradient(-45deg,transparent 75%,#d9d6d0 75%); background-size: 20px 20px; background-position: 0 0,0 10px,10px -10px,-10px 0; }
#editorCanvas { display: block; max-width: 100%; max-height: 74vh; touch-action: none; user-select: none; }
.crop-hint { margin: 9px 2px 0; }

.control-group { padding: 16px 0; border-bottom: 1px solid var(--line); }
.control-group:first-child { padding-top: 0; }
.control-group:last-child { border-bottom: 0; }
.control-group > h2 { margin-bottom: 12px; }
.switch-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px; border: 1px solid var(--line); border-radius: 9px; background: rgba(255,255,255,.75); }
.switch-row span { display: grid; gap: 2px; }
.switch-row strong { font-size: 11px; }
.switch-row small { color: var(--muted); font-size: 9px; }
.switch-row input { width: 19px; height: 19px; accent-color: var(--accent); }
.pixel-grid { display: grid; grid-template-columns: 1fr 18px 1fr; align-items: end; gap: 6px; margin-top: 12px; }
.pixel-grid > span { padding-bottom: 11px; text-align: center; color: var(--muted); }
.field-label, .pixel-grid label { display: grid; gap: 5px; color: var(--muted); font-size: 10px; font-weight: 600; }
input[type="number"], input[type="text"], select { width: 100%; height: 38px; padding: 0 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); outline: none; }
input:focus, select:focus { border-color: var(--ink); box-shadow: 0 0 0 2px rgba(36,35,33,.08); }
.aspect-buttons { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.aspect-btn { min-height: 32px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--muted); font-size: 10px; font-weight: 700; }
.aspect-btn:hover, .aspect-btn.active { border-color: var(--ink); color: var(--ink); background: #f8f7f4; }
.control-empty { padding: 12px; border-radius: 8px; background: var(--accent-soft); color: var(--muted); font-size: 10px; }
.custom-aspect-hint { margin: 8px 0 0; }
.quality-row { display: grid; gap: 7px; margin-top: 12px; }
.quality-row label { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.quality-row input { width: 100%; accent-color: var(--accent); }
.background-row { display: grid; grid-template-columns: minmax(0,1fr) 40px; gap: 8px; align-items: end; margin-top: 12px; }
#backgroundColor { width: 40px; height: 38px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.download-actions { display: grid; gap: 7px; margin-top: 14px; }

.app-footer { display: flex; justify-content: space-between; gap: 20px; padding: 13px 30px; border-top: 1px solid var(--line); background: #fff; font-size: 11px; }
.footer-status { font-weight: 600; }
.legal-footer { padding: 20px 30px 30px; text-align: center; }
.legal-note { margin: 0 0 10px; }
.footer-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 14px; }
.footer-link { color: var(--muted); font-size: 10px; text-decoration: none; }
.copyright { margin: 12px 0 0; color: var(--muted); font-size: 9px; }

.toast-stack { position: fixed; right: 18px; bottom: 18px; z-index: 30; display: grid; gap: 8px; }
.toast { min-width: 220px; padding: 11px 13px; border-radius: 8px; background: #242321; color: #fff; font-size: 11px; opacity: 0; transform: translateY(8px); transition: .18s ease; box-shadow: var(--shadow); }
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1100px) {
  .app-body { grid-template-columns: 250px minmax(0,1fr); }
  .editor-content { grid-template-columns: 1fr; }
  .editor-controls { border-left: 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 18px; }
  .control-group { border-bottom: 0; padding: 0; }
}

@media (max-width: 760px) {
  .header { padding: 18px 16px 14px; }
  .nav { align-items: flex-start; }
  .nav-links { display: none; }
  .brand-tool { font-size: 12px; }
  .app-body { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .editor-content { grid-template-columns: 1fr; }
  .editor-controls { grid-template-columns: 1fr; }
  .canvas-wrap { min-height: 380px; }
  .canvas-toolbar { align-items: flex-start; flex-direction: column; }
  .app-footer { padding: 12px 16px; flex-direction: column; gap: 4px; }
}
