:root {
    --bg: #f5f8fd;
    --surface: #fff;
    --ink: #0b1530;
    --muted: #6b7280;
    --line: #e4e6eb;
    --accent: #0a6cf0;
    --accent-soft: #e8f1ff;
    --danger: #d92d20;
    --radius: 12px;
}

* { padding: 0; margin: 0; box-sizing: border-box; }

body {
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.55;
    font-size: 15px;
}

a { color: var(--accent); }
h2 { font-size: 1.1rem; font-weight: 600; }
h4 { font-size: .85rem; font-weight: 600; }
.muted { color: var(--muted); font-size: .88rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap { width: 100%; max-width: 1100px; margin: 0 auto; padding: 0 20px; }
main.wrap { display: flex; flex-direction: column; gap: 32px; padding-top: 28px; padding-bottom: 48px; }

/* header / footer */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; height: 58px; }
.brand { font-weight: 600; font-size: 1.05rem; color: var(--ink); text-decoration: none; }
.topbar nav { display: flex; gap: 22px; }
.topbar nav a { color: var(--muted); text-decoration: none; font-size: .92rem; padding: 4px 0; border-bottom: 2px solid transparent; }
.topbar nav a:hover, .topbar nav a.active { color: var(--ink); border-color: var(--accent); }
.footer { border-top: 1px solid var(--line); padding: 20px 0; color: var(--muted); font-size: .85rem; }

/* upload */
.file { height: 120px; }
.file input { display: none; }
.file label {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    width: 100%; height: 100%;
    background: var(--surface); border: 1.5px dashed #c9ced8; border-radius: var(--radius);
    color: var(--ink); cursor: pointer; transition: border-color .15s, background .15s;
}
.file label span { font-size: .82rem; color: var(--muted); }
.file label:hover, .file.dragover label { border-color: var(--accent); background: var(--accent-soft); }

/* cards */
#editorSection h2, .toolbar h2 { margin-bottom: 12px; }
.toolbar h2 { margin-bottom: 0; }
.editor { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.card {
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 12px; display: flex; flex-direction: column; gap: 12px;
}
.thumb {
    height: 190px; border-radius: 8px; display: flex; align-items: center; justify-content: center; overflow: hidden;
    background: repeating-conic-gradient(#f1f2f5 0 25%, #fff 0 50%) 0 0 / 14px 14px;
}
.thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .8rem; color: var(--muted); }
select {
    font: inherit; color: var(--ink); background: var(--surface);
    border: 1px solid var(--line); border-radius: 8px; padding: 7px 8px; width: 100%;
}
.repeat { display: flex; align-items: center; justify-content: space-between; border: 1px solid var(--line); border-radius: 8px; }
.repeat button { width: 40px; height: 34px; border: 0; background: none; font-size: 1.2rem; color: var(--ink); cursor: pointer; border-radius: 8px; }
.repeat button:hover { background: var(--bg); }
.repeat span { font-weight: 600; }
.action { display: flex; justify-content: flex-end; gap: 6px; }
.action img { width: 32px; padding: 4px; border-radius: 8px; cursor: pointer; }
.action img:hover { background: var(--bg); }
.action .rotate-btn.active { background: var(--accent-soft); }

/* buttons */
.btn {
    font: inherit; font-weight: 500; padding: 9px 16px; border: 1px solid transparent;
    border-radius: 8px; cursor: pointer; transition: background .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #0856c7; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover { background: var(--bg); }
.btn-accent { background: var(--accent-soft); color: var(--accent); width: 100%; }
.btn-accent:hover { background: #d4e5ff; }

/* preview */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.pages { display: flex; flex-direction: column; align-items: flex-start; gap: 24px; overflow-x: auto; padding-bottom: 8px; max-width: 100%; }
.page-wrap { display: flex; flex-direction: column; gap: 8px; flex: none; margin: 0 auto; }
.page-label { font-size: .8rem; color: var(--muted); }

.print-page {
    position: relative;
    width: 21cm; height: 29.7cm; overflow: hidden;
    background: #fff; border: 1px solid var(--line);
    box-shadow: 0 4px 20px rgba(16, 24, 40, .06);
}

.photo-frame { position: absolute; box-sizing: content-box; padding: 5px; border: 0.01mm solid #00000010; overflow: hidden; }
.photo.rot { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%) rotate(90deg); }
.photo { width: 100%; height: 100%; object-fit: scale-down; object-position: center; }

/* modal */
.modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 1000;
    background: rgba(17, 19, 24, .6); justify-content: center; align-items: center; padding: 16px;
}
.modal-box {
    background: var(--surface); border-radius: 16px; padding: 24px; width: 100%; max-width: 440px;
    max-height: 94vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
.modal-box > h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: 14px; }
#crop-wrapper { width: 300px; max-width: 100%; margin: 0 auto 12px; }
.rotate-row { display: flex; gap: 8px; margin-bottom: 8px; }
.rotate-row .btn { flex: 1; padding: 8px; font-size: .88rem; }

.bg, .filter { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; margin: 14px 0; width: 100%; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; list-style: none; }
.swatches li {
    width: 30px; height: 30px; border-radius: 50%; cursor: pointer;
    border: 1px solid rgba(0, 0, 0, .15); transition: transform .12s;
}
.swatches li:hover { transform: scale(1.12); }
.swatches .none { background: repeating-conic-gradient(#d9dce3 0 25%, #fff 0 50%) 0 0 / 10px 10px; }
.filter label { display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; font-size: .88rem; }
.filter input[type=range] { width: 60%; accent-color: var(--accent); }
.filter .check { justify-content: flex-start; }
.modal-buttons { display: flex; gap: 10px; margin-top: 8px; }
.modal-buttons .btn { flex: 1; }

/* loading */
.loading {
    display: none; position: fixed; inset: 0; z-index: 2000; flex-direction: column;
    justify-content: center; align-items: center; gap: 16px; background: rgba(17, 19, 24, .6);
}
.loading h3 { color: #fff; font-weight: 500; font-size: 1rem; }
.loader { width: 36px; height: 36px; border: 3px solid rgba(255, 255, 255, .3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* about */
.prose { max-width: 680px; display: flex; flex-direction: column; gap: 28px; }
.prose h1 { font-size: 1.6rem; font-weight: 600; letter-spacing: -.01em; }
.prose section { display: flex; flex-direction: column; gap: 10px; }
.prose ol, .prose ul { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
.prose table { border-collapse: collapse; width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; font-size: .9rem; }
.prose th, .prose td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.prose th { background: var(--bg); font-weight: 600; }

@media (max-width: 600px) {
    .toolbar { flex-wrap: wrap; }
}

/* print */
@page { size: A4; margin: 0; }
@media print {
    body { background: #fff; }
    .no-print { display: none !important; }
    main.wrap { padding: 0; max-width: none; display: block; }
    .wrap { padding: 0; }
    .pages { display: block; overflow: visible; padding: 0; }
    .page-wrap { margin: 0; }
    .print-page { border: none; box-shadow: none; break-after: page; page-break-after: always; }
    .page-wrap:last-child .print-page { break-after: auto; page-break-after: auto; }
}
