/* ===================================
   PrintPhoto - リセット & 基本スタイル
   =================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    font-family: 'M PLUS Rounded 1c', 'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
    font-weight: 400;
    color: #fff;
    background-color: #141414;
    overflow-x: hidden;
    min-height: 100vh;
    /* overscroll-behavior-y: none; を削除してスクロールを許可 */
}

/* ===================================
   ローディング画面
   =================================== */
#loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(20, 20, 20, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    transition: opacity 0.5s ease;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.2);
    border-top: 4px solid #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-text {
    margin-top: 20px;
    font-size: 1.2rem;
    font-weight: 700;
    animation: blink 1.5s steps(2, start) infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    25%, 75% { opacity: 0.2; }
}

/* ===================================
   メインコンテンツ
   =================================== */
#content {
    position: relative;
    z-index: 1;
    max-width: 900px;
    margin: 0 auto;
    padding: 1.5rem;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ===================================
   ヘッダー
   =================================== */
.page-header {
    text-align: center;
    margin-bottom: 1.5rem;
    padding-top: 0.5rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: rgba(255, 255, 255, 0.6);
    text-decoration: none;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    transition: color 0.3s ease;
}

.back-link:hover {
    color: #fff;
}

.page-title {
    font-size: 2.2rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    margin-bottom: 0.3rem;
}

.page-subtitle {
    font-size: 0.95rem;
    opacity: 0.6;
}

/* ===================================
   ガラスカード
   =================================== */
.glass-card {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 1rem;
    padding: 1.2rem;
    margin-bottom: 1rem;
    transition: border-color 0.3s ease;
}

.glass-card:hover {
    border-color: rgba(255, 255, 255, 0.2);
}

.warning-card {
    background: rgba(220, 53, 69, 0.2);
    border: 2px solid rgba(220, 53, 69, 0.8);
    color: #ff8a8a;
    font-size: 0.95rem;
    font-weight: 700;
    text-align: center;
    padding: 1rem;
    animation: pulse-border 2s infinite;
}

@keyframes pulse-border {
    0%, 100% { border-color: rgba(220, 53, 69, 0.8); box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.4); }
    50% { border-color: rgba(220, 53, 69, 1); box-shadow: 0 0 0 6px rgba(220, 53, 69, 0); }
}

.warning-card i {
    margin-right: 0.4rem;
}

#camera-permission-text {
    white-space: pre-wrap;
}

.section-title-small {
    font-size: 1rem;
    font-weight: 700;
    margin-bottom: 0.8rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    opacity: 0.9;
}

/* ===================================
   画面遷移
   =================================== */
.screen {
    display: none;
    animation: fadeIn 0.4s ease;
}

.screen.active {
    display: block;
}

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

/* ===================================
   トップ画面: アップロードエリア
   =================================== */
.upload-area {
    position: relative;
    text-align: center;
    padding: 2rem 1.5rem;
    cursor: pointer;
    overflow: hidden;
}

.hidden-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}

.upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    pointer-events: none;
}

.upload-icon {
    font-size: 2.5rem;
    opacity: 0.5;
}

.upload-text {
    font-size: 1.1rem;
    font-weight: 700;
}

.upload-hint {
    font-size: 0.8rem;
    opacity: 0.4;
}

.upload-preview {
    display: none;
    margin-top: 1rem;
    max-height: 200px;
    overflow: hidden;
    border-radius: 0.5rem;
}

.upload-preview img {
    max-width: 100%;
    max-height: 200px;
    object-fit: contain;
    border-radius: 0.5rem;
}

.upload-preview.active {
    display: block;
}

/* ===================================
   サムネイル履歴
   =================================== */
.thumbnail-section {
    padding: 1rem;
}

.thumbnail-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 0.5rem;
}

.empty-text {
    text-align: center;
    opacity: 0.4;
    font-size: 0.85rem;
    padding: 1rem;
    grid-column: 1 / -1;
}

.thumbnail-item {
    aspect-ratio: 1;
    border-radius: 0.5rem;
    overflow: hidden;
    cursor: pointer;
    position: relative;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
}

.thumbnail-item:hover {
    transform: scale(1.05);
    border-color: rgba(255, 255, 255, 0.3);
}

.thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    background: rgba(220, 53, 69, 0.8);
    color: #fff;
    border: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 0.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.thumbnail-item:hover .thumbnail-delete {
    opacity: 1;
}

/* ===================================
   ボタン
   =================================== */
.primary-btn, .secondary-btn, .share-btn, .danger-btn {
    font-family: inherit;
    font-weight: 700;
    border-radius: 0.6rem;
    padding: 0.8rem 1.2rem;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border: 1px solid transparent;
}

.primary-btn {
    background: rgba(220, 53, 69, 0.8);
    color: #fff;
    border-color: rgba(220, 53, 69, 0.5);
}

.primary-btn:hover:not(:disabled) {
    background: rgba(220, 53, 69, 1);
    transform: scale(1.02);
}

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

.secondary-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.2);
}

.secondary-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.share-btn {
    background: #000;
    color: #fff;
    border-color: rgba(255, 255, 255, 0.3);
}

.share-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.danger-btn {
    background: rgba(220, 53, 69, 0.3);
    color: #fff;
    border-color: rgba(220, 53, 69, 0.4);
}

.danger-btn:hover {
    background: rgba(220, 53, 69, 0.5);
}

.camera-start-btn {
    width: 100%;
    margin-top: 0.5rem;
    font-size: 1.1rem;
    padding: 1rem;
}

.action-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.8rem;
    margin-top: 1rem;
    margin-bottom: 2rem;
}

.action-group {
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.icon-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 0.9rem;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* ===================================
   フレーム構成
   =================================== */
.photo-frame {
    background: #fff;
    border-radius: 0.25rem;
    position: relative;
    width: 100%;
    max-width: 700px;
    margin: 0 auto 1rem;
    aspect-ratio: 64 / 45;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    overflow: hidden;
}

.frame-content {
    position: absolute;
    top: 4.79%;
    left: 3.125%;
    width: 93.75%;
    height: 75%;
    background: #000;
    overflow: hidden;
    border-radius: 0.125rem;
}

.camera-video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.overlay-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    cursor: grab;
    touch-action: none;
    transform-origin: 0 0;
}

.overlay-canvas:active {
    cursor: grabbing;
}

/* ===================================
   フレーム内テキストレイヤー
   =================================== */
.frame-text-layer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 20.2%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    color: #000;
    pointer-events: none;
    z-index: 5;
}

.frame-title {
    font-size: clamp(0.8rem, 2vw, 1.4rem);
    font-weight: 700;
    text-align: center;
    line-height: 1.3;
    max-width: 90%;
    word-break: break-word;
}

.frame-comment {
    font-size: clamp(0.55rem, 1.2vw, 0.9rem);
    text-align: center;
    line-height: 1.4;
    opacity: 0.8;
    margin-top: 0.2rem;
    max-width: 90%;
    word-break: break-word;
    white-space: pre-wrap;
}

.frame-meta {
    position: absolute;
    bottom: 0.3rem;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: space-between;
    padding: 0 0.8rem;
    font-size: clamp(0.45rem, 1vw, 0.75rem);
    opacity: 0.7;
}

.frame-photographer {
    text-align: left;
}

.frame-date-location {
    text-align: right;
}

/* ===================================
   調整パネル
   =================================== */
.controls-panel {
    max-width: 700px;
    margin: 0 auto 1rem;
    padding: 1rem;
}

.control-group {
    margin-bottom: 0.8rem;
}

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

.control-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 0.4rem;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.slider {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
}

.slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(220, 53, 69, 0.9);
    cursor: pointer;
    border: 2px solid #fff;
}

.slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: rgba(220, 53, 69, 0.9);
    cursor: pointer;
    border: 2px solid #fff;
}

.color-picker-display {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 0.5rem;
    cursor: pointer;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: border-color 0.2s ease;
}

.color-picker-display:hover {
    border-color: rgba(255, 255, 255, 0.3);
}

.color-dot {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.color-value {
    font-size: 0.85rem;
    opacity: 0.6;
}

/* ===================================
   プレビュー画面
   =================================== */
.preview-frame {
    max-width: 700px;
    margin: 0 auto 1rem;
    background: #fff;
    border-radius: 0.25rem;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    aspect-ratio: 64 / 45;
}

.result-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

/* ===================================
   入力フォーム
   =================================== */
.form-card {
    max-width: 700px;
    margin: 0 auto 1rem;
}

.form-group {
    margin-bottom: 1rem;
}

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

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 700;
    margin-bottom: 0.4rem;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.form-input, .form-textarea {
    width: 100%;
    padding: 0.7rem 0.9rem;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 0.5rem;
    color: #fff;
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.3s ease;
}

.form-input:focus, .form-textarea:focus {
    outline: none;
    border-color: rgba(220, 53, 69, 0.6);
}

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

input[type="date"] {
    color-scheme: dark;
    -webkit-text-fill-color: #fff;
}

input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    opacity: 0.6;
    cursor: pointer;
}

input[type="date"]::-webkit-calendar-picker-indicator:hover {
    opacity: 1;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.location-input-wrap {
    display: flex;
    gap: 0.4rem;
}

.location-input-wrap .form-input {
    flex: 1;
}

.location-suggestions {
    display: none;
    margin-top: 0.4rem;
    background: rgba(30, 30, 30, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 0.5rem;
    max-height: 150px;
    overflow-y: auto;
}

.location-suggestions.active {
    display: block;
}

.location-suggestion-item {
    padding: 0.6rem 0.9rem;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s ease;
}

.location-suggestion-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* ===================================
   モーダル
   =================================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(4px);
}

.modal-content {
    position: relative;
    background: #1a1a1a;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 1rem;
    max-width: 400px;
    width: 90%;
    padding: 1.5rem;
    z-index: 1;
    text-align: center;
}

.modal-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: rgba(220, 53, 69, 0.9);
}

.modal-text {
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 1.2rem;
    opacity: 0.9;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.modal-actions .primary-btn,
.modal-actions .secondary-btn,
.modal-actions .danger-btn {
    width: 100%;
}

/* ===================================
   デバッグログ（仮）
   =================================== */
.debug-panel {
    max-width: 700px;
    margin: 0.5rem auto 1rem;
    padding: 0.5rem 1rem;
    display: none;
}

.debug-panel.active {
    display: block;
}

.debug-log {
    width: 100%;
    height: 120px;
    font-size: 0.65rem;
    font-family: 'Courier New', monospace;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
    border-radius: 0.3rem;
    padding: 0.5rem;
    resize: none;
    margin-bottom: 0.5rem;
    outline: none;
}

/* ===================================
   フッター
   =================================== */
.page-footer {
    text-align: center;
    padding: 2rem 0 1rem;
    font-size: 0.85rem;
    opacity: 0.4;
    margin-top: auto;
}

.git-commit {
    font-size: 0.7rem;
    opacity: 0.6;
    margin-top: 0.3rem;
    font-family: 'Courier New', monospace;
}

/* ===================================
   エラートースト
   =================================== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(30, 30, 30, 0.95);
    border: 1px solid rgba(220, 53, 69, 0.5);
    color: #fff;
    padding: 1rem 1.5rem;
    border-radius: 0.75rem;
    font-size: 0.9rem;
    z-index: 20000;
    transition: transform 0.4s ease;
    max-width: 90%;
    text-align: center;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* ===================================
   レスポンシブ
   =================================== */
@media (max-width: 768px) {
    #content {
        padding: 1rem;
    }

    .page-title {
        font-size: 1.8rem;
    }

    .thumbnail-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .action-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .action-group {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .thumbnail-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .photo-frame {
        border-radius: 0.15rem;
    }

    .frame-title {
        font-size: 0.7rem;
    }

    .frame-comment {
        font-size: 0.5rem;
    }

    .frame-meta {
        font-size: 0.4rem;
    }
}

@media (min-width: 1024px) {
    .photo-frame {
        max-width: 800px;
    }
}

/* ===================================
   アニメーション
   =================================== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in-up {
    animation: fadeInUp 0.5s ease;
}
