/* ==========================================
   基本設定・スマホ誤作動防止
   ========================================== */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f4f5f7;
    color: #333333;
    line-height: 1.5;
    padding-bottom: calc(80px + env(safe-area-inset-bottom)); /* 固定広告とコンテンツの重なりを防止 */
    user-select: none; /* テキストの誤選択を防止 */
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

/* 入力欄のテキスト選択は許可 */
textarea {
    user-select: text;
    -webkit-user-select: text;
}

/* ==========================================
   ヘッダー & レイアウト
   ========================================== */
.header {
    background-color: #1a1a1a;
    color: #ffffff;
    text-align: center;
    padding: calc(16px + env(safe-area-inset-top)) 16px 16px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 16px max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left));
}

/* ==========================================
   カードスタイル
   ========================================== */
.card {
    background: #ffffff;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    border: 1px solid #e5e7eb;
}

.card h2 {
    font-size: 1rem;
    color: #1a1a1a;
    margin-bottom: 12px;
    padding-bottom: 6px;
    border-bottom: 2px solid #f0f0f0;
}

.label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: #4b5563;
    margin-bottom: 8px;
}

textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 16px;
    resize: none;
    word-break: break-all;
    outline: none;
    transition: border-color 0.2s;
}

textarea:focus {
    border-color: #1a1a1a;
}

/* ==========================================
   ボタン
   ========================================== */
.btn {
    display: block;
    width: 100%;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
    border: none;
    cursor: pointer;
    transition: opacity 0.2s;
    touch-action: manipulation; /* ダブルタップズーム防止 */
}

.btn:active {
    opacity: 0.8;
}

.btn-primary {
    background-color: #1a1a1a;
    color: #ffffff;
    margin-top: 12px;
}

.btn-secondary {
    background-color: #2563eb;
    color: #ffffff;
    margin-top: 16px;
}

.btn-outline {
    background-color: transparent;
    border: 1px solid #d1d5db;
    color: #4b5563;
    margin-top: 12px;
}

/* ==========================================
   QRコード表示エリア
   ========================================== */
.result-card {
    text-align: center;
}

#qrcode-box {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    background-color: #ffffff;
}

#qrcode-box img, #qrcode-box canvas {
    max-width: 100%;
    height: auto;
}

/* ==========================================
   リストスタイル (履歴・お気に入り)
   ========================================== */
.item-list {
    list-style: none;
}

.item-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #f3f4f6;
    gap: 8px;
}

.item-row:last-child {
    border-bottom: none;
}

.item-text {
    flex: 1;
    font-size: 0.875rem;
    color: #374151;
    word-break: break-all;
    cursor: pointer;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.item-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.action-icon-btn {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 4px;
    color: #9ca3af;
    line-height: 1;
}

.action-icon-btn.active {
    color: #f59e0b;
}

.action-icon-btn.delete:active {
    color: #ef4444;
}

.empty-msg {
    font-size: 0.85rem;
    color: #9ca3af;
    text-align: center;
    padding: 12px 0;
}

/* ==========================================
   モーダル
   ========================================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 2000;
    justify-content: center;
    align-items: flex-end;
}

.modal.open {
    display: flex;
}

.modal-content {
    background-color: #ffffff;
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    padding: 20px max(20px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e5e7eb;
}

.modal-header h3 {
    font-size: 1.1rem;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: #6b7280;
    cursor: pointer;
}

.modal-list {
    overflow-y: auto;
    flex: 1;
}

/* 画面最下部固定広告 */
.ad-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #121212;
    z-index: 1000;
    padding-top: 1px;
    padding-bottom: calc(1px + env(safe-area-inset-bottom));
    border-top: 1px solid #333;
 }


/* MRS TOOLS link */
.mrs-tools-link {
    display: inline-block;
    color: #888888;
    font-size: 0.85rem;
    text-decoration: underline;
    padding: 4px 8px;
}


/* QR画像の長押し保存は許可する。 */
#qrcode-box img, #qrcode-box canvas {
    -webkit-touch-callout: default;
    user-select: auto;
    -webkit-user-select: auto;
}

/* ラベル付きお気に入りとラベル編集 */
.item-text.named-favorite { display: block; }
.favorite-label { display: block; font-weight: 600; }
.favorite-source { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: #6b7280; font-size: 0.8rem; }
.edit-name-btn { font-size: 0.8rem; color: #4b5563; }
.item-actions .action-icon-btn { min-width: 40px; min-height: 44px; }
.name-modal { z-index: 2100; }
.name-source { word-break: break-all; margin: 8px 0 16px; color: #6b7280; max-height: 100px; overflow: auto; }
#favorite-name { width: 100%; padding: 12px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 16px; user-select: text; -webkit-user-select: text; }
.name-help { margin-top: 8px; font-size: 0.85rem; color: #6b7280; }
.name-buttons { display: flex; gap: 12px; }
.name-buttons .btn { flex: 1; margin-top: 16px; }
.btn:disabled { opacity: 0.6; cursor: default; }

/* 保存一覧のタブ。通常ボタンと区別するため下線で選択を示す。 */
.saved-tabs { display: flex; border-bottom: 1px solid #d1d5db; margin-bottom: 12px; }
.saved-tab { flex: 1; min-height: 48px; padding: 12px 8px; border: 0; border-bottom: 3px solid transparent; margin-bottom: -1px; background: transparent; color: #6b7280; font: inherit; font-weight: 600; cursor: pointer; touch-action: manipulation; }
.saved-tab[aria-selected="true"] { border-bottom-color: #f59e0b; color: #1a1a1a; }
.saved-tab:focus-visible { outline: 2px solid #2563eb; outline-offset: -4px; }
.saved-items [role="tabpanel"][hidden] { display: none; }

/* 画像保存を左、共有を右に同じ幅で配置する。 */
.image-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 16px; }
.image-actions .btn { margin-top: 0; min-width: 0; min-height: 48px; padding: 10px 6px; font-size: 0.85rem; overflow-wrap: anywhere; }
