/* リセットCSS */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* 基本スタイル */
body {
    font-family: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Yu Gothic', 'Meiryo', sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 15px;
    width: 100%;
}

/* ページ管理 */
.page {
    display: none;
    min-height: 100vh;
}

.page.active {
    display: block;
}

/* ヘッダー */
header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

/* フォームスタイル */
.letter-form {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.form-group {
    margin-bottom: 25px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #555;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-group textarea {
    min-height: 120px;
    resize: vertical;
}

/* ボタンスタイル */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f8f9fa;
    color: #6c757d;
    border: 2px solid #e9ecef;
}

.btn-secondary:hover {
    background: #e9ecef;
    border-color: #dee2e6;
}

.btn-line {
    background: #00c300;
    color: white;
}

.btn-line:hover {
    background: #00a300;
    transform: translateY(-2px);
}

.form-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    margin-top: 30px;
}

/* 成功ページ */
.success-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    text-align: center;
}

.url-display {
    display: flex;
    gap: 10px;
    margin-bottom: 25px;
}

.url-display input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid #e1e5e9;
    border-radius: 8px;
    font-size: 14px;
    background: #f8f9fa;
}

.share-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* 開封ページ */
.password-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.password-form {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    text-align: center;
    min-width: 300px;
}

.password-form .form-group {
    margin-bottom: 20px;
}

/* 手紙表示 */
.letter-display {
    min-height: 100vh;
    display: none;
}

.letter-display.active {
    display: block;
}

/* 開封ページでbodyの背景を無効化 */
.page#open-page {
    background: none;
}

.page#open-page body {
    background: none;
}

.letter-background {
    min-height: 100vh;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    z-index: 1;
}

.letter-background.sakura {
    background: linear-gradient(rgba(255,182,193,0.3), rgba(255,182,193,0.3)),
                url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="20" cy="20" r="2" fill="%23ffb6c1"/><circle cx="80" cy="30" r="1.5" fill="%23ffc0cb"/><circle cx="50" cy="70" r="1" fill="%23ffb6c1"/></svg>');
}

.letter-background.stars {
    background: linear-gradient(45deg, #1e3c72 0%, #2a5298 100%);
}

.letter-background.ocean {
    background: linear-gradient(180deg, #74b9ff 0%, #0984e3 100%);
}

.letter-background.forest {
    background: linear-gradient(135deg, #74b816 0%, #00b894 100%);
}

.letter-background.sunset {
    background: linear-gradient(135deg, #fd79a8 0%, #fdcb6e 100%);
}

.letter-paper {
    background: 
        linear-gradient(180deg, #cce7ff 0px, #cce7ff 1px, transparent 1px),
        #ffffff;
    background-size: 100% 32px, 100% 100%;
    background-position: 0px 0px, 0px 0px;
    padding: 40px 40px 50px 40px;
    border-radius: 3px;
    box-shadow: 
        0 1px 3px rgba(0,0,0,0.12),
        0 5px 15px rgba(0,0,0,0.15),
        inset 0 0 0 1px rgba(0,0,0,0.05);
    max-width: 700px;
    width: 100%;
    min-height: 400px;
    position: relative;
    margin: 20px auto;
    border-left: 3px solid #e85d75;
}

.letter-paper::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: transparent;
}



.letter-text {
    font-family: 'Hiragino Mincho ProN', 'Yu Mincho', 'YuMincho', 'HG Mincho E', 'MS Mincho', serif;
    font-size: 16px;
    line-height: 32px;
    color: #2c3e50;
    white-space: pre-wrap;
    position: relative;
    z-index: 1;
    margin: 0;
    padding: 0;
    min-width: 300px;
    min-height: 100px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

.reply-actions {
    text-align: center;
    margin-top: 30px;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.5s ease;
}

.reply-actions.show {
    opacity: 1;
    transform: translateY(0);
}

.action-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}



.delete-link-container {
    position: absolute;
    bottom: 15px;
    right: 15px;
}

.delete-link {
    font-size: 13px;
    color: #495057;
    text-decoration: none;
    opacity: 0.8;
    transition: all 0.3s ease;
    padding: 4px 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(4px);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.delete-link:hover {
    opacity: 1;
    color: #dc3545;
    background: rgba(255, 255, 255, 0.95);
    border-color: rgba(220, 53, 69, 0.3);
    transform: translateY(-1px);
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
    transform: translateY(-2px);
}

.fade-in {
    animation: fadeIn 2s ease-in-out;
}

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

.slide-up {
    animation: slideUp 1.5s ease-out;
}

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

.typewriter {
    /* タイプライター演出用のクラス - カーソルなし */
}

@keyframes blink-caret {
    from, to { border-color: transparent; }
    50% { border-color: #333; }
}

.unfold {
    animation: unfold 2s ease-in-out;
}

@keyframes unfold {
    0% {
        opacity: 0;
        transform: rotate(-45deg);
    }
    50% {
        opacity: 0.5;
        transform: rotate(-15deg);
    }
    100% {
        opacity: 1;
        transform: rotate(0deg);
    }
}

/* モーダル */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    margin: 20px;
    padding: 0;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    max-width: 800px;
    width: 100%;
    max-height: 90vh;
    overflow: auto;
}

.modal-header {
    padding: 20px 30px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    color: #333;
}

.close-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

.close-btn:hover {
    background-color: #f5f5f5;
}

.modal-body {
    padding: 30px;
}

.preview-display .letter-background {
    min-height: 400px;
}

/* ローディング */
.loading {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.7);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
}

.loading.active {
    display: flex;
}

.spinner {
    border: 4px solid rgba(255,255,255,0.3);
    border-top: 4px solid white;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin-bottom: 20px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* エラーメッセージ */
.error-message {
    display: none;
    position: fixed;
    z-index: 1002;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
}

.error-message.active {
    display: flex;
}

.error-content {
    background: white;
    padding: 30px;
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    max-width: 400px;
    width: 90%;
    text-align: center;
}

.error-content p {
    margin-bottom: 20px;
    color: #e74c3c;
    font-weight: 600;
}

/* 手紙開封アニメーション */
.envelope {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 320px;
    height: 220px;
    background: #f8f8f8;
    border: 2px solid #ddd;
    border-radius: 5px;
    z-index: 10;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    overflow: visible;
}

.envelope::before {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 10px;
    right: 10px;
    height: 20px;
    background: #f8f8f8;
    border-left: 2px solid #ddd;
    border-right: 2px solid #ddd;
    border-bottom: 2px solid #ddd;
    border-radius: 0 0 5px 5px;
    z-index: -1;
}

.envelope-flap {
    position: absolute;
    top: -1px;
    left: -1px;
    right: -1px;
    height: 120px;
    background: #f8f8f8;
    border: 2px solid #ddd;
    border-bottom: none;
    clip-path: polygon(0 0, 100% 0, 50% 85%);
    transform-origin: 50% 0%;
    transition: transform 1s ease-in-out;
    z-index: 11;
}

.envelope.opening .envelope-flap {
    transform: rotateX(180deg);
}

.envelope.fade-out {
    animation: fadeOutEnvelope 1s ease-in-out forwards;
}

@keyframes fadeOutEnvelope {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%);
    }
}

.folded-letter {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) translateY(20px);
    width: 280px;
    height: 180px;
    background: white;
    border: 1px solid #ccc;
    border-radius: 3px;
    z-index: 5;
    opacity: 0;
    transform-origin: 50% 0%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.folded-letter.sliding-out {
    animation: slideOut 1.5s ease-in-out forwards;
}

.folded-letter.fade-out {
    animation: fadeOutLetter 1s ease-in-out forwards;
}

@keyframes slideOut {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) translateY(20px);
    }
    30% {
        opacity: 1;
        transform: translate(-50%, -50%) translateY(0px);
    }
    70% {
        opacity: 1;
        transform: translate(-50%, -50%) translateY(-40px);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) translateY(-100px);
    }
}

@keyframes fadeOutLetter {
    0% {
        opacity: 1;
        transform: translate(-50%, -50%) translateY(-30px);
    }
    100% {
        opacity: 0;
        transform: translate(-50%, -50%) translateY(-30px);
    }
}

.letter-paper.opening {
    opacity: 0;
    transform: scale(1);
    animation: expandLetter 1s ease-in-out forwards;
}

@keyframes expandLetter {
    0% {
        opacity: 0;
        transform: scale(1);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.opening-animation {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    min-height: 100vh;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;
}

/* スマホファーストのレスポンシブデザイン */
@media (max-width: 480px) {
    .container {
        padding: 10px;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .letter-form {
        padding: 20px;
    }

    .letter-paper {
        padding: 40px 20px 40px 20px;
        background-position: 0px 0px, 0px 0px;
        min-height: 300px;
        max-width: 85vw;
        width: 85vw;
        margin: 20px auto;
        box-sizing: border-box;
    }

    .letter-text {
        font-size: 14px;
        line-height: 32px;
        max-width: 75vw !important;
        width: 75vw !important;
        min-width: 250px !important;
        box-sizing: border-box;
    }

    .btn {
        padding: 12px 20px;
        font-size: 16px;
        min-height: 44px;
    }

    .form-actions {
        flex-direction: column;
        gap: 12px;
    }

    .url-display {
        flex-direction: column;
        gap: 12px;
    }

    .success-content,
    .password-form {
        padding: 25px 20px;
        margin: 10px;
    }

    /* モバイル用の開封アニメーション調整 */
    .envelope {
        width: 280px;
        height: 180px;
    }

    .folded-letter {
        width: 240px;
        height: 140px;
    }
    
    .action-buttons {
        flex-direction: column;
        gap: 8px;
    }
    
    .delete-link-container {
        bottom: 10px;
        right: 10px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .container {
        padding: 15px;
    }

    header h1 {
        font-size: 2rem;
    }

    .letter-form {
        padding: 25px;
    }

    .letter-paper {
        padding: 50px 30px 45px 30px;
        background-position: 0px 0px, 0px 0px;
        min-height: 350px;
    }

    .letter-text {
        font-size: 15px;
        line-height: 32px;
    }

    .modal-content {
        margin: 15px;
        max-width: 90vw;
        width: 90vw;
        box-sizing: border-box;
    }
}

@media (min-width: 769px) {
    .letter-background {
        padding: 30px;
    }
}