/**
 * わーきんぐめもりーとれーにんぐしすてむ
 * でぃすれくしあじどうむけ すたいるしーと
 * ぜんたすくたいおう かんぜんばん
 */

/* ========================================
   1. きほんせってい
======================================== */

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

:root {
    --bg-primary: #FEFCF4;
    --bg-secondary: #F5F3E8;
    --bg-card: #FFFFFF;
    --text-primary: #2C2C2C;
    --text-secondary: #606060;
    --color-primary: #0075C2;
    --color-success: #00B06B;
    --color-warning: #F39800;
    --color-danger: #E60012;
    --color-highlight: #FFF100;
    --font-huge: 128px;
    --font-xlarge: 48px;
    --font-large: 32px;
    --font-base: 28px;
    --font-small: 24px;
    --space-xs: 8px;
    --space-sm: 12px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-xxl: 48px;
    --tap-target: 60px;
    --button-height: 72px;
}

html {
    font-size: var(--font-base);
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * { animation: none !important; transition: none !important; }
}

body {
    font-family: "UD デジタル教科書体 N-R", "Noto Sans JP", -apple-system, sans-serif;
    line-height: 2.0;
    letter-spacing: 0.12em;
    color: var(--text-primary);
    background: var(--bg-primary);
    min-height: 100vh;
}

/* ========================================
   2. すきっぷりんく
======================================== */

.skip-link {
    position: absolute;
    top: -200px;
    left: var(--space-lg);
    background: var(--color-primary);
    color: white;
    padding: var(--space-md) var(--space-lg);
    font-size: var(--font-base);
    font-weight: bold;
    text-decoration: none;
    border-radius: 8px;
    z-index: 10000;
}

.skip-link:focus {
    top: var(--space-lg);
    outline: 4px solid var(--color-highlight);
}

/* ========================================
   3. ふぉーかす
======================================== */

*:focus {
    outline: 4px solid var(--color-primary);
    outline-offset: 4px;
}

*:focus:not(:focus-visible) {
    outline: none;
}

*:focus-visible {
    outline: 4px solid var(--color-primary);
    outline-offset: 4px;
}

/* ========================================
   4. ぼたん
======================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    min-height: var(--button-height);
    min-width: var(--tap-target);
    padding: var(--space-lg) var(--space-xl);
    border: none;
    border-radius: 12px;
    font-size: var(--font-base);
    font-weight: bold;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    background: var(--color-primary);
    color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

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

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary { background: var(--color-primary); }
.btn-secondary { background: var(--text-secondary); }
.btn-success { background: var(--color-success); }
.btn-warning { background: var(--color-warning); }
.btn-danger { background: var(--color-danger); }

.btn-large {
    min-height: 84px;
    font-size: var(--font-large);
    padding: var(--space-xl) var(--space-xxl);
}

.btn-huge {
    min-height: 60px;
    font-size: 28px;
    padding: 12px 24px;
}

.btn-icon { font-size: 1.5em; }
.btn-text { line-height: 1.4; }

/* ========================================
   5. ろぐいんがめん
======================================== */

.login-page, .register-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: var(--space-lg);
}

.login-container, .register-container {
    width: 100%;
    max-width: 600px;
}

.login-card, .register-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: var(--space-xxl);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

.login-header, .register-header {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.system-icon {
    font-size: 80px;
    display: block;
    margin-bottom: var(--space-lg);
}

.login-header h1, .register-header h1 {
    font-size: var(--font-xlarge);
    margin-bottom: var(--space-md);
}

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

.error-message, .success-message {
    padding: var(--space-lg);
    margin-bottom: var(--space-xl);
    border-radius: 8px;
    text-align: center;
}

.error-message {
    background: #FFEBE6;
    border: 3px solid var(--color-danger);
}

.success-message {
    background: #E6F4EA;
    border: 3px solid var(--color-success);
}

.error-icon, .success-icon {
    font-size: 48px;
    display: block;
    margin-bottom: var(--space-md);
}

/* ========================================
   6. ふぉーむ
======================================== */

.login-form, .register-form {
    margin-bottom: var(--space-xl);
}

.form-group {
    margin-bottom: var(--space-xl);
}

.form-group label {
    display: block;
    font-size: var(--font-large);
    font-weight: bold;
    margin-bottom: var(--space-md);
}

.field-help {
    font-size: var(--font-small);
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.form-group input, .form-group select {
    width: 100%;
    min-height: var(--button-height);
    padding: var(--space-lg);
    font-size: var(--font-base);
    font-family: inherit;
    letter-spacing: 0.08em;
    border: 3px solid var(--text-secondary);
    border-radius: 8px;
    background: white;
}

.form-group input:focus, .form-group select:focus {
    border-color: var(--color-primary);
}

.register-link, .back-link {
    text-align: center;
    margin-top: var(--space-xl);
}

.register-link p {
    font-size: var(--font-base);
    margin-bottom: var(--space-lg);
}

/* ========================================
   7. とれーにんぐせんたくがめん
======================================== */

.training-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.main-header {
    background: var(--bg-card);
    border-bottom: 3px solid var(--bg-secondary);
    padding: var(--space-lg) var(--space-xl);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-lg);
    max-width: 1200px;
    margin: 0 auto;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.header-left .system-icon {
    font-size: 48px;
}

.header-left h1 {
    font-size: var(--font-large);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.user-name {
    font-size: var(--font-base);
    font-weight: bold;
}

.btn-logout {
    min-width: auto;
}

.main-content {
    flex: 1;
    padding: var(--space-xxl) var(--space-lg);
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.greeting-section {
    text-align: center;
    margin-bottom: var(--space-xxl);
}

.greeting-section h2 {
    font-size: var(--font-xlarge);
    margin-bottom: var(--space-lg);
}

.greeting-text {
    font-size: var(--font-base);
    color: var(--text-secondary);
}

.stats-section {
    margin-bottom: var(--space-xxl);
}

.stats-section h3 {
    font-size: var(--font-large);
    margin-bottom: var(--space-xl);
    text-align: center;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-lg);
}

.stat-card {
    background: var(--bg-card);
    border: 3px solid var(--bg-secondary);
    border-radius: 12px;
    padding: var(--space-lg);
    text-align: center;
}

.stat-icon {
    font-size: 48px;
    margin-bottom: var(--space-md);
}

.stat-label {
    display: block;
    font-size: var(--font-small);
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.stat-value {
    display: block;
    font-size: var(--font-xlarge);
    font-weight: bold;
    color: var(--color-primary);
}

.task-selection h3 {
    font-size: var(--font-large);
    margin-bottom: var(--space-xl);
    text-align: center;
}

.task-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-xl);
}

.task-card {
    background: var(--bg-card);
    border: 4px solid var(--bg-secondary);
    border-radius: 16px;
    padding: var(--space-xl);
    text-decoration: none;
    color: inherit;
    transition: all 0.3s;
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.task-card:hover {
    border-color: var(--color-primary);
    transform: translateY(-4px);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
}

.task-icon {
    font-size: 80px;
    text-align: center;
}

.task-name {
    font-size: var(--font-large);
    font-weight: bold;
    text-align: center;
}

.task-description {
    font-size: var(--font-small);
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.8;
}

.task-action {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-md);
    font-size: var(--font-base);
    font-weight: bold;
    color: var(--color-primary);
    margin-top: auto;
}

.btn-arrow {
    font-size: 1.5em;
}

.main-footer {
    background: var(--bg-secondary);
    padding: var(--space-lg);
    text-align: center;
    font-size: var(--font-small);
    color: var(--text-secondary);
}

/* ========================================
   8. たすくじっこうがめん（14いんち たいおう）
======================================== */

.task-page {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    overflow: hidden;
}

.task-container {
    width: 100%;
    max-width: 100vw;
    height: 100vh;
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.task-info-bar {
    background: var(--bg-secondary);
    padding: 8px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 2px solid var(--bg-primary);
    flex-shrink: 0;
}

.task-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

.task-title .task-icon {
    font-size: 28px;
}

.task-title .task-name {
    font-size: 20px;
    font-weight: bold;
}

.btn-exit {
    min-width: auto;
    min-height: 44px;
    padding: 8px 16px;
    font-size: 18px;
    background: var(--color-danger);
}

.task-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    overflow: hidden;
}

.task-screen {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.start-content, .question-content, .answer-content, .complete-content {
    text-align: center;
    max-width: 90%;
    width: 100%;
}

.start-icon, .complete-icon {
    font-size: 48px;
    margin-bottom: 8px;
}

.start-title, .complete-title {
    font-size: 24px;
    margin-bottom: 8px;
}

.start-description {
    font-size: 18px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    line-height: 1.5;
}

.task-status-bar {
    background: var(--bg-secondary);
    border-top: 2px solid var(--bg-primary);
    padding: 6px 8px;
    display: flex;
    justify-content: space-around;
    gap: 6px;
    flex-shrink: 0;
}

.status-item {
    text-align: center;
}

.status-label {
    display: block;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.status-value {
    display: block;
    font-size: 18px;
    font-weight: bold;
    color: var(--color-primary);
}

/* ========================================
   9. すうじひょうじ（こんぱくと）
======================================== */

.digit-display {
    width: 100%;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.large-digit {
    font-size: 72px;
    font-weight: 900;
    color: var(--color-primary);
    font-family: 'Courier New', monospace;
    animation: digitPulse 0.5s ease;
}

@keyframes digitPulse {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}

/* ========================================
   10. てんきー（14いんち たいおう、ひょうじゅん はいち）
======================================== */

.numpad-container {
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
}

.numpad-container h2 {
    font-size: 16px;
    margin-bottom: 6px;
}

.numpad-display {
    background: var(--bg-secondary);
    border: 2px solid var(--text-secondary);
    border-radius: 6px;
    padding: 6px;
    margin-bottom: 6px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.numpad-value {
    font-size: 24px;
    font-weight: bold;
    font-family: 'Courier New', monospace;
    min-height: 28px;
}

.numpad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    margin-bottom: 5px;
}

.numpad-button {
    min-height: 45px;
    font-size: 22px;
    font-weight: bold;
    border: 2px solid var(--color-primary);
    border-radius: 5px;
    background: white;
    color: var(--color-primary);
    cursor: pointer;
    transition: all 0.2s;
}

.numpad-button:hover {
    background: var(--color-primary);
    color: white;
    transform: scale(1.05);
}

.numpad-button:active {
    transform: scale(0.95);
}

.numpad-button.clear {
    background: var(--color-danger);
    border-color: var(--color-danger);
    color: white;
    font-size: 16px;
}

.numpad-button.zero {
    /* 0は ちゅうおう はいち、ひょうじゅん さいず */
}

.btn-large {
    min-height: 42px;
    font-size: 18px;
    padding: 8px 16px;
}

/* ========================================
   11. ばしょきおく（14いんち たいおう）
======================================== */

.spatial-container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
}

.spatial-container h2 {
    font-size: 16px;
    margin-bottom: 6px;
    text-align: center;
}

.spatial-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    margin: 6px auto;
    max-width: 280px;
}

.spatial-cell {
    aspect-ratio: 1;
    min-height: 60px;
    background: white;
    border: 2px solid var(--color-primary);
    border-radius: 5px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: bold;
}

.spatial-cell:hover {
    background: var(--bg-secondary);
    border-width: 3px;
}

.spatial-cell.highlighted {
    background: var(--color-highlight);
    border-color: var(--color-highlight);
    box-shadow: 0 0 15px rgba(255, 241, 0, 0.8);
    animation: highlight 0.8s ease;
}

.spatial-cell.selected {
    background: var(--color-success);
    border-color: var(--color-success);
    color: white;
}

@keyframes highlight {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.answer-feedback {
    text-align: center;
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 6px;
    color: var(--color-primary);
}

/* ========================================
   12. かたちきおく（かへん せんたくし）
======================================== */

.pattern-container {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
}

.pattern-container h2 {
    font-size: 16px;
    margin-bottom: 6px;
    text-align: center;
}

.pattern-display {
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pattern-item {
    animation: patternShow 0.5s ease;
}

@keyframes patternShow {
    0% { transform: scale(0) rotate(0deg); opacity: 0; }
    50% { transform: scale(1.2) rotate(180deg); }
    100% { transform: scale(1) rotate(360deg); opacity: 1; }
}

.pattern-choices {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(80px, 1fr));
    gap: 12px;
    margin: 12px auto;
    max-width: 400px;
    justify-content: center;
}

.pattern-choice {
    aspect-ratio: 1;
    min-height: 80px;
    border: 4px solid var(--text-secondary);
    border-radius: 8px;
    background: white;
    font-size: 56px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.pattern-choice:hover {
    border-color: var(--color-primary);
    border-width: 5px;
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.pattern-choice:active {
    transform: scale(0.9);
}

.pattern-choice.selected {
    background: var(--bg-secondary);
    border-color: var(--color-success);
    border-width: 5px;
    animation: selectPulse 0.3s ease;
}

@keyframes selectPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* ========================================
   13. ふぃーどばっく
======================================== */

.feedback-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: fadeIn 0.3s;
}

.feedback-overlay.correct {
    background: rgba(0, 176, 107, 0.95);
}

.feedback-overlay.incorrect {
    background: rgba(230, 0, 18, 0.95);
}

.feedback-content {
    text-align: center;
    color: white;
    animation: bounceIn 0.5s;
}

.feedback-icon {
    font-size: 150px;
    margin-bottom: var(--space-xl);
}

.feedback-message {
    font-size: var(--font-xlarge);
    font-weight: bold;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes bounceIn {
    0% { transform: scale(0); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* ========================================
   14. かんりょうがめん（14いんち たいおう）
======================================== */

.final-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 8px;
    margin: 12px 0;
}

.final-stat {
    background: var(--bg-secondary);
    border-radius: 6px;
    padding: 8px;
}

.final-stat-label {
    display: block;
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 3px;
}

.final-stat-value {
    display: block;
    font-size: 22px;
    font-weight: bold;
    color: var(--color-primary);
}

.complete-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
    margin-top: 10px;
}

/* ========================================
   15. れすぽんしぶ（14いんち たいおう）
======================================== */

/* 14いんち もにたー たいおう */
@media (max-width: 1400px) {
    .large-digit {
        font-size: 64px;
    }
    
    .start-icon, .complete-icon {
        font-size: 56px;
    }
    
    .numpad-button {
        min-height: 48px;
        font-size: 22px;
    }
}

/* たぶれっと・すまーとふぉん */
@media (max-width: 768px) {
    :root {
        --font-xlarge: 32px;
        --font-large: 24px;
        --font-base: 20px;
        --font-small: 18px;
    }
    
    .task-container {
        height: 100vh;
        max-height: none;
        border-radius: 0;
    }
    
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .task-grid {
        grid-template-columns: 1fr;
    }
    
    .pattern-choices {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .large-digit {
        font-size: 56px;
    }
}

@media print {
    .main-header, .main-footer, .btn, .task-info-bar, .task-status-bar {
        display: none;
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #2C2C2C;
        --bg-secondary: #3C3C3C;
        --bg-card: #4C4C4C;
        --text-primary: #F5F5F5;
        --text-secondary: #B0B0B0;
    }
}

@media (prefers-contrast: high) {
    :root {
        --color-primary: #0000FF;
        --text-primary: #000000;
    }
    
    .btn, .form-group input, .numpad-button, .task-card, .spatial-cell, .pattern-choice {
        border-width: 4px;
    }
}