/* Modern CSS Reset & Variables */
:root {
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --bg-color: #f8fafc;
    --surface-color: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --font-sans: 'Inter', 'Noto Sans JP', sans-serif;
    --font-mono: 'Roboto Mono', 'BIZ UDGothic', 'BIZ UDGothic', 'Menlo', 'Consolas', monospace;
    --transition: all 0.2s ease;
}

@media (prefers-color-scheme: dark) {
    :root {
        --primary-color: #60a5fa;
        --primary-hover: #3b82f6;
        --bg-color: #0f172a;
        --surface-color: #1e293b;
        --text-primary: #f8fafc;
        --text-secondary: #94a3b8;
        --border-color: #334155;
    }
}

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

body {
    font-family: var(--font-sans);
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Layout */
.app-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1rem;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    flex: 1;
}

/* Header */
.app-header {
    text-align: center;
}

.app-header h1 {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    letter-spacing: -0.025em;
}

.app-header p {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Main Content */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Input Section */
.input-section {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 1.5rem;
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

textarea {
    width: 100%;
    min-height: 60vh;
    /* Increased default height */
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    resize: vertical;
    outline: none;
    transition: var(--transition);
    font-family: inherit;
    margin-bottom: 1rem;
    line-height: 1.8;
    /* Slightly looser for readability */
}

/* Guide Mode (Manuscript Style) */
.textarea-guide-mode {
    font-family: var(--font-mono);
    /* New Japanese-friendly mono stack */
    /* background-image will be set by JS via linear-gradient */
    background-attachment: local;
    /* Scrolls with text */
    /* background-size set by JS to match line-height exactly */
    width: fit-content;
    /* Shrink to fit the char width */
    min-width: 50%;
    max-width: 100%;
    margin: 0 auto 1rem auto;
    /* Center it */
    overflow-x: auto;
    letter-spacing: 0;
    /* Ensure padding aligns with grid */
    padding-top: 1rem !important;
    /* Start text a bit lower to align first line */
    padding-bottom: 2rem !important;
    line-height: 2 !important;
    /* Strict line height for grid alignment */
    /* Use content-box so width defines the CONTENT width (text area), excluding padding */
    box-sizing: content-box !important;
}

textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.action-bar {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
}

.btn svg {
    width: 16px;
    height: 16px;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.btn-text {
    background-color: transparent;
    color: var(--text-secondary);
}

.btn-text:hover {
    color: var(--primary-color);
    background-color: rgba(59, 130, 246, 0.05);
}

/* Stats Section */
.stats-section {
    display: grid;
    gap: 1rem;
}

.stat-card {
    background: var(--surface-color);
    padding: 1.25rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.total-count .stat-value {
    font-size: 3rem;
    color: var(--primary-color);
}

.sub-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

@media (max-width: 600px) {
    .sub-stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Settings */
.settings-section {
    background: var(--surface-color);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
}

.settings-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.settings-group {
    display: flex;
    flex-wrap: wrap;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.settings-group:last-child {
    margin-bottom: 0;
}

.input-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.input-control input[type="number"],
.input-control select {
    width: 60px;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    background-color: var(--surface-color);
    /* Ensure bg is white/dark */
    color: var(--text-primary);
}

.toggle-control {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    user-select: none;
}

.toggle-control input {
    display: none;
}

.toggle-slider {
    width: 44px;
    height: 24px;
    background-color: var(--border-color);
    border-radius: 999px;
    position: relative;
    transition: var(--transition);
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background-color: white;
    border-radius: 50%;
    transition: var(--transition);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.toggle-control input:checked+.toggle-slider {
    background-color: var(--primary-color);
}

.toggle-control input:checked+.toggle-slider::after {
    transform: translateX(20px);
}

.toggle-label {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Footer */
.app-footer {
    margin-top: auto;
    text-align: center;
    padding-top: 1rem;
}

/* Animation classes */
.pop {
    animation: pop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pop {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}