/* PAN Card Resizer — styles */

:root {
    --primary: #1f3a8a;
    --primary-hover: #1e40af;
    --accent: #3b82f6;
    --accent-soft: #eff6ff;
    --text: #374151;
    --text-muted: #6b7280;
    --text-light: #9ca3af;
    --border: #e5e7eb;
    --surface: #ffffff;
    --success: #10b981;
    --success-hover: #059669;
    --danger: #ef4444;
    --radius: 12px;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* The HTML `hidden` attribute must always win over component styles. */
[hidden] {
    display: none !important;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #764ba2;
    background-image: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    background-attachment: fixed;
    min-height: 100vh;
    padding: 20px 16px;
    color: var(--text);
    line-height: 1.6;
}

:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}

.container {
    max-width: 1000px;
    margin: 0 auto;
}

.card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 30px;
    box-shadow: var(--shadow);
}

h1,
h2,
h3 {
    color: var(--primary);
}

h2 {
    font-size: 22px;
    margin-bottom: 20px;
}

/* ---------- Header / footer ---------- */

.site-header {
    margin-bottom: 30px;
    padding: 30px 20px;
}

.logo {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 10px;
}

.tagline {
    color: var(--text-muted);
    font-size: 16px;
}

.site-footer {
    margin-top: 30px;
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.site-footer a {
    color: var(--accent);
    text-decoration: none;
}

.site-footer a:hover {
    text-decoration: underline;
}

.small {
    font-size: 12px;
    margin-top: 8px;
}

/* ---------- Layout ---------- */

.main-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    margin-bottom: 30px;
    align-items: start;
}

.features {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.feature {
    background: var(--surface);
    padding: 20px;
    border-radius: var(--radius);
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.feature-icon {
    font-size: 32px;
    margin-bottom: 10px;
}

.feature-title {
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 8px;
    font-size: 15px;
}

.feature-desc {
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1.5;
}

/* ---------- Upload ---------- */

.upload-area {
    border: 3px dashed var(--accent);
    border-radius: var(--radius);
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    transition: background 0.3s ease, border-color 0.3s ease;
    background: #f0f4ff;
}

.upload-area:hover {
    background: #e0e7ff;
}

.upload-area.dragover {
    background: #dbeafe;
    border-color: var(--primary);
}

.upload-icon {
    font-size: 48px;
    margin-bottom: 15px;
}

.upload-text {
    color: var(--text-muted);
    margin-bottom: 10px;
    font-weight: 600;
}

.upload-hint {
    color: var(--text-light);
    font-size: 14px;
}

.preview-section {
    margin-top: 20px;
    position: relative;
}

#imageCanvas {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 400px;
    margin: 0 auto;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
}

.crop-container {
    border: 2px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

#cropImage {
    display: block;
    max-width: 100%;
    /* Cropper.js needs a sized image; a display:none image cannot be measured. */
}

.loading {
    text-align: center;
    padding: 20px;
}

.spinner {
    border: 4px solid #f3f4f6;
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 10px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- Messages ---------- */

.message {
    padding: 12px 15px;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 13px;
}

.error-message {
    background: #fee2e2;
    border-left: 4px solid var(--danger);
    color: #991b1b;
}

.success-message {
    background: #dcfce7;
    border-left: 4px solid var(--success);
    color: #166534;
}

.field-hint {
    color: #991b1b;
    font-size: 13px;
    margin-top: 8px;
}

/* ---------- Settings ---------- */

.settings-group {
    margin-bottom: 25px;
    border: 0;
    min-width: 0;
}

.setting-label {
    display: block;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 8px;
    font-size: 14px;
}

legend.setting-label {
    padding: 0;
}

.size-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

button.size-box {
    display: block;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    font-weight: 400;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.3s ease, background 0.3s ease;
}

button.size-box small {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
}

button.size-box:hover {
    border-color: var(--accent);
}

button.size-box.selected {
    background: var(--accent-soft);
    border-color: var(--primary);
    font-weight: 600;
    color: var(--primary);
}

.custom-size {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: var(--text-muted);
}

input[type="number"] {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    font-size: 14px;
    color: var(--text);
}

.format-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.option {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    cursor: pointer;
}

input[type="range"] {
    width: 100%;
    cursor: pointer;
}

.range-value {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 5px;
}

/* ---------- Buttons ---------- */

button {
    font: inherit;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background 0.3s ease, opacity 0.3s ease;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-secondary {
    background: #f3f4f6;
    color: var(--text-muted);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border);
}

.btn-success {
    background: var(--success);
    color: #ffffff;
}

.btn-success:hover:not(:disabled) {
    background: var(--success-hover);
}

.full-width {
    width: 100%;
}

.controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.crop-info {
    background: var(--accent-soft);
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
}

/* ---------- Info section ---------- */

.info-section {
    margin-bottom: 30px;
    color: #374151;
    line-height: 1.6;
}

.info-section h2 {
    margin-top: 25px;
}

.info-section h2:first-child {
    margin-top: 0;
}

.info-section h3 {
    font-size: 16px;
    margin: 18px 0 6px;
}

.info-section p {
    margin-bottom: 10px;
}

.info-section ul {
    padding-left: 22px;
    margin-bottom: 10px;
}

.info-section li {
    margin: 6px 0;
}

.info-section a {
    color: var(--accent);
}

/* ---------- Responsive ---------- */

@media (max-width: 768px) {
    .main-content {
        grid-template-columns: 1fr;
    }

    .size-options,
    .controls {
        grid-template-columns: 1fr;
    }

    .card {
        padding: 20px;
    }

    .site-header {
        padding: 20px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}