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

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-card: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666666;
    --border-color: #e0e0e0;
    --accent: #000000;
    --accent-hover: #333333;
    --shadow: rgba(0, 0, 0, 0.1);
    --shadow-hover: rgba(0, 0, 0, 0.15);
    --stat-primary: #000000;
    --stat-bg: #f5f5f5;
    --progress-bg: #e0e0e0;
    --progress-fill: #000000;
    --success: #4caf50;
    --warning: #ff9800;
    --danger: #f44336;
}

[data-theme="dark"] {
    --bg-primary: #1a1a1a;
    --bg-secondary: #242424;
    --bg-card: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #b0b0b0;
    --border-color: #404040;
    --accent: #ffffff;
    --accent-hover: #e0e0e0;
    --shadow: rgba(0, 0, 0, 0.3);
    --shadow-hover: rgba(0, 0, 0, 0.4);
    --stat-primary: #ffffff;
    --stat-bg: #333333;
    --progress-bg: #404040;
    --progress-fill: #ffffff;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', 'Meiryo', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

header {
    text-align: center;
    margin-bottom: 3rem;
    animation: fadeInDown 0.6s ease;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

header .icon {
    font-size: 2.5rem;
    animation: bounce 2s infinite;
}

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

.main-content {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.input-section {
    animation: fadeInUp 0.6s ease 0.2s both;
}

.textarea-wrapper {
    position: relative;
}

#textInput {
    width: 100%;
    min-height: 300px;
    padding: 1.5rem;
    font-size: 1rem;
    font-family: inherit;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-card);
    color: var(--text-primary);
    resize: vertical;
    transition: all 0.3s ease;
    outline: none;
}

#textInput:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] #textInput:focus {
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
}

.textarea-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    justify-content: flex-end;
}

.btn {
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
}

.btn:hover {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px var(--shadow);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
}

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

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    animation: fadeInUp 0.6s ease 0.3s both;
}

.stat-card {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--accent);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px var(--shadow-hover);
    border-color: var(--accent);
}

.stat-card:hover::before {
    transform: scaleX(1);
}

.stat-card.primary {
    background: var(--stat-bg);
    border-color: var(--accent);
}

.stat-card.primary::before {
    transform: scaleX(1);
}

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

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--stat-primary);
    line-height: 1;
    margin-bottom: 0.25rem;
    transition: transform 0.3s ease;
}

.stat-card:hover .stat-value {
    transform: scale(1.1);
}

.stat-unit {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.detailed-stats,
.limit-section,
.export-section {
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 2rem;
    animation: fadeInUp 0.6s ease 0.4s both;
}

.section-title {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-primary);
}

.icon-small {
    font-size: 1.3rem;
}

.detailed-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.detail-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    transition: all 0.3s ease;
}

.detail-item:hover {
    background: var(--stat-bg);
    transform: translateX(4px);
}

.detail-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.detail-value {
    font-weight: 700;
    color: var(--text-primary);
    font-size: 1.1rem;
}

.preset-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.preset-btn {
    padding: 0.6rem 1.2rem;
    font-size: 0.85rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.preset-btn:hover {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
    transform: translateY(-2px);
}

.preset-btn.active {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
}

.custom-limit {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

#customLimit {
    flex: 1;
    padding: 0.75rem 1rem;
    font-size: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    outline: none;
    transition: all 0.3s ease;
}

#customLimit:focus {
    border-color: var(--accent);
    background: var(--bg-card);
}

.limit-progress {
    margin-top: 1.5rem;
}

.progress-bar-wrapper {
    width: 100%;
    height: 24px;
    background: var(--progress-bg);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.progress-bar {
    height: 100%;
    background: var(--progress-fill);
    border-radius: 12px;
    transition: width 0.3s ease;
    position: relative;
    overflow: hidden;
}

.progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shimmer 2s infinite;
}

.progress-bar.warning {
    background: var(--warning);
}

.progress-bar.danger {
    background: var(--danger);
}

.progress-text {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.remaining {
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 400;
}

.remaining.negative {
    color: var(--danger);
    font-weight: 600;
}

.export-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

footer {
    text-align: center;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 2px solid var(--border-color);
    position: relative;
}

.theme-toggle {
    position: absolute;
    top: 0;
    right: 0;
    width: 48px;
    height: 48px;
    border: 2px solid var(--border-color);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    font-size: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.theme-toggle:hover {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
    transform: rotate(15deg) scale(1.1);
}

.footer-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes bounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-10px);
    }
}

@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }
    100% {
        transform: translateX(100%);
    }
}

@media (max-width: 768px) {
    header h1 {
        font-size: 2rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .detailed-grid {
        grid-template-columns: 1fr;
    }

    .preset-buttons {
        grid-template-columns: repeat(2, 1fr);
    }

    .custom-limit {
        flex-direction: column;
    }

    .export-buttons {
        flex-direction: column;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 1rem 0.5rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-value {
        font-size: 2rem;
    }
}
