/* Import Google Handwriting Fonts */
@import url('https://fonts.googleapis.com/css2?family=Caveat:wght@400..700&family=Dancing+Script:wght@400..700&family=Indie+Flower&family=Shadows+Into+Light&family=Pacifico&display=swap');

#tth-wrapper {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    margin: 20px 0;
    box-sizing: border-box;
}

#tth-wrapper * {
    box-sizing: border-box;
}

/* Header */
.tth-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #eaeaea;
}

.tth-header h2 {
    margin: 0;
    font-size: 24px;
}

/* Main Layout Grid */
.tth-container {
    display: flex;
    flex-wrap: wrap;
    gap: 30px;
}

.tth-controls {
    flex: 1;
    min-width: 300px;
    background: #f8f9fa;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.05);
}

.tth-preview-area {
    flex: 1.5;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Form Controls */
.tth-control-group {
    margin-bottom: 15px;
    width: 100%;
}

.tth-control-row {
    display: flex;
    gap: 15px;
}

.tth-control-row .tth-control-group {
    flex: 1;
}

.tth-controls label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 14px;
}

.tth-controls input[type="text"],
.tth-controls input[type="number"],
.tth-controls select,
.tth-controls textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.3s ease;
}

.tth-controls textarea {
    resize: vertical;
}

.tth-controls input[type="file"] {
    font-size: 13px;
}

.tth-controls input[type="range"] {
    width: 100%;
    margin-top: 8px;
}

.tth-word-count-wrap {
    text-align: right;
    font-size: 12px;
    color: #666;
    margin-top: 5px;
}

/* Buttons */
.tth-action-buttons, .tth-export-buttons {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    flex-wrap: wrap;
}

button[id^="tth-"] {
    padding: 10px 15px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.1s ease, opacity 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

button[id^="tth-"]:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button[id^="tth-"]:not(:disabled):hover {
    transform: translateY(-2px);
    opacity: 0.9;
}

.tth-btn-primary { background: #0d6efd; color: white; }
.tth-btn-secondary { background: #6c757d; color: white; }
.tth-btn-danger { background: #dc3545; color: white; }
.tth-btn-success { background: #198754; color: white; flex: 1; justify-content: center; }

/* Paper Preview Container */
#tth-paper-container {
    background: #e0e0e0;
    padding: 20px;
    border-radius: 8px;
    overflow-x: auto;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.1);
}

/* Base Paper Styles */
#tth-paper {
    min-height: 500px;
    width: 100%;
    max-width: 800px; /* A4 aspect constraint representation */
    margin: 0 auto;
    background-color: white;
    box-shadow: 2px 4px 15px rgba(0,0,0,0.2);
    position: relative;
    word-wrap: break-word;
    white-space: pre-wrap;
    transition: background 0.3s ease;
}

/* Background Types */
.paper-white {
    background: #ffffff;
}

.paper-ruled {
    background: linear-gradient(transparent, transparent 28px, #91D1D3 28px);
    background-size: 30px 30px;
}

.paper-notebook {
    background: linear-gradient(transparent, transparent 28px, #91D1D3 28px);
    background-size: 30px 30px;
    position: relative;
}

.paper-notebook::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 40px; /* Red margin line */
    width: 2px;
    background: #ffaaaa;
    z-index: 0;
}

#tth-output-text {
    position: relative;
    z-index: 1; /* Keep text above notebook margin line */
}

/* Loading overlay */
#tth-loading {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 5px 15px;
    border-radius: 20px;
    font-size: 14px;
    z-index: 10;
}

/* Dark Mode Theme */
.tth-dark-mode .tth-controls {
    background: #212529;
    color: #f8f9fa;
    box-shadow: 0 4px 6px rgba(255,255,255,0.05);
}

.tth-dark-mode .tth-controls input[type="text"],
.tth-dark-mode .tth-controls input[type="number"],
.tth-dark-mode .tth-controls select,
.tth-dark-mode .tth-controls textarea {
    background: #343a40;
    color: white;
    border-color: #495057;
}

.tth-dark-mode .tth-word-count-wrap {
    color: #adb5bd;
}

.tth-dark-mode .tth-header {
    border-bottom-color: #495057;
    color: #fff;
}

/* Responsive */
@media (max-width: 768px) {
    .tth-control-row {
        flex-direction: column;
        gap: 0;
    }
    .tth-preview-area {
        margin-top: 20px;
    }
}