/**
 * Zovira - Base Styles
 * リセット + モバイル対応（iOS/Android/その他）+ カスタムスタイル
 */

/* ========================================
   1. CSS Reset (Modern)
   ======================================== */

*, *::before, *::after {
    box-sizing: border-box;
}

* {
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

img, picture, video, canvas, svg {
    display: block;
    max-width: 100%;
}

input, button, textarea, select {
    font: inherit;
    color: inherit;
}

button {
    background: none;
    border: none;
    cursor: pointer;
}

a {
    color: inherit;
    text-decoration: none;
}

ul, ol {
    list-style: none;
}

p, h1, h2, h3, h4, h5, h6 {
    overflow-wrap: break-word;
}

/* ========================================
   2. Mobile / Touch Device Optimization
   （iOS Safari, Android Chrome, Samsung Internet, Firefox Mobile）
   ======================================== */

/* タップハイライト無効化（iOS/Android共通） */
* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* タッチ操作の最適化 */
button, a, input, select, textarea {
    touch-action: manipulation;
}

/* フォーム要素のズーム防止（iOS: 16px未満でズーム発生） */
input, select, textarea {
    font-size: 16px;
}

/* 入力フィールドのデフォルトスタイル無効化（iOS/Android） */
input, textarea {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border-radius: 0;
}

/* ボタンのデフォルトスタイル無効化 */
button, input[type="button"], input[type="submit"], input[type="reset"] {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* セレクトボックス（カスタム矢印） */
select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

/* Android: フォーカス時のアウトライン色 */
input:focus, textarea:focus, select:focus {
    outline-color: #0ea5e9;
}

/* ========================================
   3. Viewport Height（キーボード対応）
   dvh: Dynamic Viewport Height（キーボード表示時に追従）
   svh: Small Viewport Height（キーボード表示時の最小）
   lvh: Large Viewport Height（キーボード非表示時の最大）
   ======================================== */

:root {
    /* フォールバック付きのビューポート高さ */
    --vh: 1vh;
    --dvh: 1dvh;

    /* Safe Area */
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
}

/* 全画面表示（キーボード対応） */
.full-height {
    height: 100vh;
    height: 100dvh;
}

/* 最小高さ（キーボード対応） */
.min-full-height {
    min-height: 100vh;
    min-height: 100dvh;
}

/* ========================================
   4. Safe Area (iOS Notch / Android Gesture Bar)
   ======================================== */

/* ボトムナビゲーションのSafe Area対応 */
.safe-area-bottom {
    padding-bottom: var(--safe-area-inset-bottom);
}

/* ヘッダーのSafe Area対応 */
.safe-area-top {
    padding-top: var(--safe-area-inset-top);
}

/* 左右のSafe Area対応（横向き時） */
.safe-area-x {
    padding-left: var(--safe-area-inset-left);
    padding-right: var(--safe-area-inset-right);
}

/* ========================================
   5. Scroll Behavior
   ======================================== */

html {
    scroll-behavior: smooth;
    /* Firefox: スクロールのスナップ */
    scroll-padding-top: 48px; /* ヘッダー高さ分 */
}

/* オーバースクロール（バウンス）制御 */
body {
    overscroll-behavior: none;
    overscroll-behavior-y: none;
}

/* iOS: 慣性スクロール */
.scroll-touch {
    -webkit-overflow-scrolling: touch;
}

/* モーダル表示時のスクロール無効化 */
body.overflow-hidden {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
    /* iOS Safari: スクロール位置を維持 */
    top: 0;
    left: 0;
}

/* ========================================
   6. Custom Scrollbar
   ======================================== */

/* Webkit (Chrome, Safari, Edge, Samsung Internet) */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

::-webkit-scrollbar-track {
    background: #171717;
}

::-webkit-scrollbar-thumb {
    background: #404040;
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: #525252;
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: #404040 #171717;
}

/* ========================================
   7. Focus Styles (Accessibility)
   ======================================== */

/* デフォルトのアウトライン無効化 */
:focus {
    outline: none;
}

/* キーボードフォーカス時のみアウトライン表示 */
:focus-visible {
    outline: 2px solid #0ea5e9;
    outline-offset: 2px;
}

/* Firefox: focus-visible対応 */
@supports not selector(:focus-visible) {
    :focus {
        outline: 2px solid #0ea5e9;
        outline-offset: 2px;
    }
}

/* ========================================
   8. Selection
   ======================================== */

::selection {
    background-color: #0ea5e9;
    color: #fff;
}

::-moz-selection {
    background-color: #0ea5e9;
    color: #fff;
}

/* ========================================
   9. Animations
   ======================================== */

/* prefers-reduced-motion: アニメーション無効化設定を尊重 */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    html {
        scroll-behavior: auto;
    }
}

/* ボトムシートアニメーション */
.bottom-sheet {
    transform: translateY(100%);
    transition: transform 0.3s ease-out;
    will-change: transform;
}

.bottom-sheet.active {
    transform: translateY(0);
}

/* フェードイン */
.fade-in {
    animation: fadeIn 0.2s ease-out;
}

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

/* スケールイン */
.scale-in {
    animation: scaleIn 0.2s ease-out;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* スライドアップ */
.slide-up {
    animation: slideUp 0.3s ease-out;
}

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

/* ========================================
   10. Utility Classes
   ======================================== */

/* 行数制限 */
.line-clamp-1 {
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* 横スクロール（エリアチップ等） */
.scroll-x {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.scroll-x::-webkit-scrollbar {
    display: none;
}

/* テキスト選択無効化 */
.no-select {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ドラッグ無効化（画像など） */
.no-drag {
    -webkit-user-drag: none;
}

/* GPU アクセラレーション有効化 */
.gpu {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
}

/* ========================================
   11. Typography
   ======================================== */

body {
    font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    /* Android: フォントレンダリング最適化 */
    text-rendering: optimizeLegibility;
}

/* 日本語の改行制御 */
.break-ja {
    word-break: break-all;
    overflow-wrap: break-word;
}

/* ========================================
   12. Form Elements Enhancement
   ======================================== */

/* プレースホルダーの色（クロスブラウザ） */
::placeholder {
    color: #737373;
    opacity: 1;
}

::-webkit-input-placeholder {
    color: #737373;
}

::-moz-placeholder {
    color: #737373;
    opacity: 1;
}

:-ms-input-placeholder {
    color: #737373;
}

/* オートフィル時の背景色（Chrome/Edge/Samsung Internet） */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
textarea:-webkit-autofill:hover,
textarea:-webkit-autofill:focus,
select:-webkit-autofill,
select:-webkit-autofill:hover,
select:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px #000 inset;
    -webkit-text-fill-color: #f5f5f5;
    transition: background-color 5000s ease-in-out 0s;
}

/* チェックボックス・ラジオボタン */
input[type="checkbox"],
input[type="radio"] {
    width: 18px;
    height: 18px;
    accent-color: #0ea5e9;
    cursor: pointer;
}

/* カスタムラジオボタン（通報モーダル用） */
.report-option input:checked + .report-radio {
    border-color: #0ea5e9;
}

.report-option input:checked + .report-radio span {
    transform: scale(1);
}

/* 数値入力のスピナー非表示 */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

/* 検索入力のクリアボタン・検索アイコン非表示 */
input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration,
input[type="search"]::-webkit-search-results-button,
input[type="search"]::-webkit-search-results-decoration {
    -webkit-appearance: none;
}

/* ========================================
   13. PWA / Standalone Mode
   ======================================== */

/* PWAとして起動時のスタイル */
@media (display-mode: standalone) {
    /* ヘッダーをSafe Area対応 */
    header {
        padding-top: var(--safe-area-inset-top);
    }

    /* プルダウンリフレッシュ無効化 */
    body {
        overscroll-behavior-y: contain;
    }
}

/* iOS: ホーム画面から起動時 */
@media (display-mode: standalone) and (max-width: 768px) {
    /* ステータスバー領域の確保 */
    .safe-area-top {
        padding-top: max(var(--safe-area-inset-top), 20px);
    }
}

/* ========================================
   14. Dark Mode Enhancement
   ======================================== */

/* ダークモード時の調整（すでにダークテーマだが明示的に） */
@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
    }
}

/* ライトモード対策（万が一システムがライトの場合） */
html {
    color-scheme: dark;
    background-color: #000;
}

/* ========================================
   15. Like Particle Animation
   ======================================== */

@keyframes likeParticle {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translate(var(--tx), var(--ty)) scale(0);
    }
}

.like-particle {
    position: absolute;
    pointer-events: none;
    animation: likeParticle 0.6s ease-out forwards;
}

/* ========================================
   16. Skeleton Loading
   ======================================== */

@keyframes skeletonPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.7; }
}

.skeleton-pulse {
    background: #262626;
    border-radius: 4px;
    animation: skeletonPulse 1.5s ease-in-out infinite;
}

.skeleton-circle {
    background: #262626;
    border-radius: 9999px;
    animation: skeletonPulse 1.5s ease-in-out infinite;
}

/* ========================================
   17. Image Blur Preview
   ======================================== */

.img-blur-loading {
    filter: blur(10px);
    transition: filter 0.3s ease-out;
}

.img-blur-loaded {
    filter: blur(0);
}

/* ========================================
   18. Post Confetti
   ======================================== */

@keyframes confettiFall {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translateY(120px) rotate(var(--rot, 360deg));
    }
}

.confetti-piece {
    position: fixed;
    top: -10px;
    pointer-events: none;
    z-index: 200;
    animation: confettiFall var(--duration, 1.2s) ease-out forwards;
}

/* ========================================
   19. Bottom Nav Bounce
   ======================================== */

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

.nav-bounce {
    animation: navBounce 0.3s ease-out;
}

/* ========================================
   20. Header Hide/Show on Scroll
   ======================================== */

.header-hidden {
    transform: translateY(-100%);
}

/* ========================================
   21. Line Clamp for Posts
   ======================================== */

.line-clamp-4 {
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.line-clamp-none {
    display: block;
    -webkit-line-clamp: unset;
    overflow: visible;
}

/* ========================================
   22. Pull to Refresh Indicator
   ======================================== */

.pull-indicator {
    transition: transform 0.2s ease-out, opacity 0.2s ease-out;
}

/* ========================================
   23. Print Styles
   ======================================== */

@media print {
    /* ナビゲーション非表示 */
    header, nav, .fab, .bottom-sheet {
        display: none !important;
    }

    /* 背景色を白に */
    body {
        background: #fff !important;
        color: #000 !important;
    }

    /* リンクURLを表示 */
    a[href]::after {
        content: " (" attr(href) ")";
    }
}
