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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f0f2f5;
    color: #1a1a2e;
    line-height: 1.6;
}

/* ── Header ─────────────────────────────────────────────────────── */

header {
    background: #1a1a2e;
    color: #fff;
    padding: 16px 0;
    text-align: center;
}

header h1 {
    font-size: 1.4rem;
    font-weight: 600;
}

/* ── Card grid ──────────────────────────────────────────────────── */

.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
    max-width: 1200px;
    margin: 20px auto;
    padding: 0 16px;
}

.tool-card {
    background: #fff;
    border-radius: 10px;
    padding: 18px 20px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.07);
    display: flex;
    flex-direction: column;
}

.tool-card--wide {
    grid-column: span 2;
}

.tool-card h2 {
    font-size: 1.05rem;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #e8e8ee;
}

/* ── DateTime rows ──────────────────────────────────────────────── */

.datetime-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.datetime-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 10px;
    background: #f7f8fa;
    border-radius: 6px;
    font-size: 0.85rem;
}

.datetime-row .label {
    min-width: 130px;
    font-weight: 500;
    color: #555;
}

.datetime-row .value {
    flex: 1;
    word-break: break-all;
}

.datetime-row .value.mono,
.mono {
    font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
}

.btn-copy {
    background: none;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 2px 6px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.15s;
    flex-shrink: 0;
}

.btn-copy:hover {
    background: #e8e8ee;
}

.btn-copy.copied {
    background: #d4edda;
    border-color: #a3d9b1;
}

/* ── Common form elements ───────────────────────────────────────── */

.calc-section h3 {
    font-size: 0.9rem;
    margin-bottom: 8px;
    color: #333;
}

.calc-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 110px;
}

.field.small {
    min-width: 60px;
    flex: 0 1 80px;
}

.field label {
    font-size: 0.75rem;
    color: #666;
    font-weight: 500;
}

.field input,
.field select,
.textarea {
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 0.85rem;
    font-family: inherit;
    resize: vertical;
}

.field input:focus,
.field select:focus,
.textarea:focus {
    outline: none;
    border-color: #5a67d8;
    box-shadow: 0 0 0 2px rgba(90, 103, 216, 0.15);
}

.btn-calc {
    padding: 6px 16px;
    background: #1a1a2e;
    color: #fff;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    transition: background 0.15s;
    align-self: flex-end;
    white-space: nowrap;
}

.btn-calc:hover {
    background: #2d2d4e;
}

.result {
    margin-top: 6px;
    padding: 8px 12px;
    background: #f0f4ff;
    border-radius: 6px;
    font-size: 0.85rem;
    display: none;
}

.result.visible {
    display: block;
}

hr {
    border: none;
    border-top: 1px solid #e8e8ee;
    margin: 12px 0;
}

/* ── Time calculator rows ───────────────────────────────────────── */

.time-calc-entries {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.time-calc-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.time-calc-op {
    width: 44px;
    padding: 5px 2px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 0.85rem;
    font-family: inherit;
    text-align: center;
}

.time-calc-h,
.time-calc-m,
.time-calc-s {
    width: 52px;
    padding: 5px 6px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 0.85rem;
    font-family: inherit;
    text-align: center;
}

.time-calc-sep {
    font-size: 0.75rem;
    color: #888;
    font-weight: 500;
}

.time-calc-remove {
    background: none;
    border: 1px solid #ddd;
    border-radius: 5px;
    padding: 4px 7px;
    cursor: pointer;
    font-size: 0.75rem;
    color: #999;
    margin-left: 2px;
    transition: color 0.15s, border-color 0.15s;
}

.time-calc-remove:hover {
    color: #e53e3e;
    border-color: #e53e3e;
}

/* ── Color converter ────────────────────────────────────────────── */

.color-top-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

#color-picker {
    width: 42px;
    height: 36px;
    border: 1px solid #ccc;
    border-radius: 5px;
    cursor: pointer;
    padding: 2px;
}

.color-preview {
    flex: 1;
    height: 36px;
    border-radius: 5px;
    border: 1px solid #ddd;
    transition: background 0.15s;
}

.color-fields {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.color-fields .field {
    min-width: 100px;
}

/* ── File drop zone ─────────────────────────────────────────────── */

.file-drop {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 70px;
    border: 2px dashed #ccc;
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    text-align: center;
    padding: 12px;
}

.file-drop:hover,
.file-drop.dragover {
    border-color: #5a67d8;
    background: #f0f4ff;
}

.file-drop-text {
    font-size: 0.85rem;
    color: #888;
}

.img-b64-info {
    font-size: 0.8rem;
    color: #555;
    margin-top: 6px;
}

/* ── Mojibake fixer ─────────────────────────────────────────────── */

.mojibake-results {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 420px;
    overflow-y: auto;
}

.mojibake-row {
    background: #f7f8fa;
    border: 1px solid #e8e8ee;
    border-radius: 6px;
    padding: 8px 12px;
}

.mojibake-row--best {
    background: #e8f5e9;
    border-color: #a5d6a7;
}

.mojibake-row-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.mojibake-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #666;
    font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
}

.mojibake-text {
    font-size: 0.9rem;
    line-height: 1.5;
    word-break: break-word;
    white-space: pre-wrap;
}

.mojibake-empty {
    font-size: 0.85rem;
    color: #888;
    padding: 12px;
    text-align: center;
}

/* ── String Analyzer ───────────────────────────────────────────── */

.str-analyze-stats {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.str-stat {
    background: #f0f4ff;
    border-radius: 6px;
    padding: 6px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 90px;
}

.str-stat--warn {
    background: #fff3cd;
}

.str-stat-label {
    font-size: 0.7rem;
    color: #666;
    font-weight: 500;
}

.str-stat-value {
    font-size: 1.1rem;
    font-weight: 700;
    font-family: "Cascadia Code", "Fira Code", Consolas, monospace;
}

.str-analyze-table-wrap {
    overflow-x: auto;
    margin-top: 4px;
}

.str-analyze-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.str-analyze-table th,
.str-analyze-table td {
    padding: 4px 8px;
    border: 1px solid #e8e8ee;
    text-align: left;
    white-space: nowrap;
}

.str-analyze-table th {
    background: #f7f8fa;
    font-weight: 600;
    font-size: 0.75rem;
    color: #555;
}

.str-char-cell {
    font-size: 1rem;
    text-align: center !important;
    min-width: 32px;
}

.str-row-invisible {
    background: #fff3cd;
}

/* ── Responsive ─────────────────────────────────────────────────── */

@media (max-width: 740px) {
    .tools-grid {
        grid-template-columns: 1fr;
    }
    .tool-card--wide {
        grid-column: span 1;
    }
    .datetime-row {
        flex-wrap: wrap;
    }
    .datetime-row .label {
        min-width: 100%;
    }
    .calc-row {
        flex-direction: column;
    }
    .field,
    .field.small {
        min-width: 100%;
    }
    .color-fields {
        flex-direction: column;
    }
}
