/* =====================================================
   麻雀ルール共有アプリ — 競技ブロードキャスト (Mリーグ風)
   Light theme, Card-based, Professional Design
   ===================================================== */

/* --- Reset & Base --- */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #F0F2F5;
  --surface: #FFFFFF;
  --text: #1A202C;
  --text-sub: #718096;
  --accent: #3182CE;
  --accent-hover: #2B6CB0;
  --highlight: #E53E3E;
  --highlight-bg: rgba(229, 62, 62, 0.08);
  --border: #E2E8F0;
  --green: #38A169;
  --green-light: #F0FFF4;
  --orange: #DD6B20;
  --purple: #805AD5;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --transition: 0.2s ease;
  --font: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@400;500;700&display=swap');

/* --- Layout --- */
.app { max-width: 520px; margin: 0 auto; min-height: 100dvh; display: flex; flex-direction: column; }
.screen { display: none; flex: 1; flex-direction: column; }
.screen.active { display: flex; }

/* --- Header --- */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 100;
  box-shadow: var(--shadow);
}
.header-title {
  font-size: 1rem; font-weight: 700; color: var(--text);
}
.header-back {
  background: none; border: none; color: var(--accent);
  font-size: 0.9rem; font-weight: 500; cursor: pointer; padding: 4px 0;
  transition: color var(--transition);
}
.header-back:hover { color: var(--accent-hover); }

/* --- ボタン --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: none; border-radius: 20px; cursor: pointer;
  font-family: var(--font); font-weight: 700; font-size: 0.85rem;
  padding: 10px 20px; transition: all var(--transition);
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); }
.btn-green { background: var(--green); color: #fff; }
.btn-green:hover { filter: brightness(0.95); }
.btn-orange { background: var(--orange); color: #fff; }
.btn-orange:hover { filter: brightness(0.95); }
.btn-purple { background: var(--purple); color: #fff; }
.btn-purple:hover { filter: brightness(0.95); }
.btn-red { background: var(--highlight); color: #fff; }
.btn-red:hover { filter: brightness(0.95); }
.btn-ghost {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-sub); padding: 10px 16px;
}
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 16px; font-size: 0.8rem; }

/* --- ホーム画面 --- */
.home-hero {
  text-align: center; padding: 28px 16px 16px;
}
.home-hero h1 {
  font-size: 1.4rem; font-weight: 700; color: var(--text);
}
.home-hero p { color: var(--text-sub); font-size: 0.85rem; margin-top: 4px; }

.create-btns {
  display: flex; gap: 10px; padding: 0 16px 12px;
}
.create-btns .btn { flex: 1; border-radius: 10px; padding: 14px 16px; font-size: 0.9rem; }

.rule-list { flex: 1; padding: 0 16px; overflow-y: auto; }

.rule-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: var(--shadow);
}
.rule-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.rule-card:active { transform: scale(0.99); }

.rule-card-info { flex: 1; min-width: 0; }
.rule-card-name {
  font-weight: 700; font-size: 0.95rem; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.rule-card-mode {
  font-size: 0.75rem; color: var(--text-sub); margin-top: 3px;
  display: flex; align-items: center; gap: 6px;
}
.rule-card-mode .badge {
  display: inline-block; font-size: 0.65rem; font-weight: 700;
  padding: 2px 8px; border-radius: 10px;
}
.badge-4ma { background: var(--accent); color: #fff; }
.badge-3ma { background: var(--purple); color: #fff; }

.rule-card-actions {
  display: flex; gap: 6px; flex-shrink: 0; margin-left: 10px;
}
.icon-btn {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 0.9rem;
  transition: all var(--transition);
}
.icon-btn:hover { border-color: var(--accent); background: #EBF8FF; }
.icon-btn.delete:hover { border-color: var(--highlight); background: #FFF5F5; }

.empty-state {
  text-align: center; padding: 48px 16px; color: var(--text-sub);
}
.empty-state .emoji { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* --- 編集画面 --- */
.edit-scroll { flex: 1; overflow-y: auto; padding: 0 0 20px; }

.name-input-wrap {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.name-input-wrap label {
  display: block; font-size: 0.75rem; color: var(--text-sub); margin-bottom: 5px;
}
.name-input {
  width: 100%; padding: 12px 16px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font); font-size: 1rem; font-weight: 600;
  outline: none; transition: border-color var(--transition);
}
.name-input:focus { border-color: var(--accent); }

.base-rule-wrap {
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
}
.base-rule-wrap label { font-size: 0.75rem; color: var(--text-sub); white-space: nowrap; }
.base-rule-wrap select { flex: 1; }

.info-box {
  background: var(--highlight-bg);
  border-left: 4px solid var(--highlight);
  padding: 10px 14px; margin: 12px 16px;
  border-radius: 4px; font-size: 0.8rem; line-height: 1.6;
  color: var(--text);
}

/* カテゴリ・設定項目 */
.category-section { padding: 0 16px; margin-top: 16px; }
.section-title {
  font-size: 0.85rem; font-weight: 700; color: var(--text);
  margin-bottom: 8px; padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.setting-list {
  background: var(--surface); border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-bottom: 4px;
}
.setting-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.setting-row:last-child { border-bottom: none; }
.setting-row.diff { background: var(--highlight-bg); }
.setting-label {
  font-size: 0.85rem; font-weight: 500; color: var(--text);
  display: flex; align-items: center; gap: 6px;
  flex-shrink: 0; max-width: 45%;
}
.setting-label .diff-badge {
  font-size: 0.6rem; background: var(--highlight); color: #fff;
  padding: 1px 6px; border-radius: 10px; font-weight: 700; white-space: nowrap;
}
.setting-value { flex: 1; min-width: 0; }
.setting-value select {
  width: 100%; text-align: right;
  background: transparent; border: none; color: var(--text-sub);
  font-family: var(--font); font-size: 0.85rem;
  outline: none; cursor: pointer; appearance: none;
  -webkit-appearance: none; padding: 0;
  direction: rtl;
}
.setting-row.diff .setting-value select {
  color: var(--highlight); font-weight: 700;
}

/* テキストエリア（特記事項） */
.setting-row-textarea {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.setting-row-textarea:last-child { border-bottom: none; }
.setting-row-textarea label {
  display: block; font-size: 0.8rem; font-weight: 500; color: var(--text);
  margin-bottom: 6px;
}
textarea {
  width: 100%; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font); font-size: 0.85rem;
  outline: none; resize: vertical; min-height: 56px;
  transition: border-color var(--transition);
}
textarea:focus { border-color: var(--accent); }

/* --- セレクト (フォーム用) --- */
select {
  width: 100%; padding: 10px 14px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font); font-size: 0.85rem;
  outline: none; appearance: none; -webkit-appearance: none;
  cursor: pointer;
  transition: border-color var(--transition);
}
select:focus { border-color: var(--accent); }
select:disabled, input:disabled, textarea:disabled {
  background: #f8fafc; color: var(--text); 
  border-color: #e2e8f0; opacity: 1; -webkit-text-fill-color: var(--text);
}

/* --- プレビュー画面 --- */
.preview-content { flex: 1; overflow-y: auto; padding: 12px 16px; }
#preview-area {
  background: #fff; color: #1a202c; border-radius: var(--radius);
  overflow: hidden; font-size: 13px; line-height: 1.6;
  box-shadow: var(--shadow-md); border: 1px solid var(--border);
}
#preview-area .pv-header {
  background: linear-gradient(135deg, #2D3748, #1A202C);
  color: #fff; padding: 18px 16px;
}
#preview-area .pv-header h2 { font-size: 1.05rem; margin-bottom: 2px; }
#preview-area .pv-header p { font-size: 0.75rem; color: #A0AEC0; }
#preview-area .pv-cat {
  background: #EDF2F7; padding: 8px 14px;
  font-weight: 700; font-size: 0.8rem; color: var(--text);
  border-bottom: 1px solid #E2E8F0;
}
#preview-area .pv-row {
  display: flex; justify-content: space-between;
  padding: 8px 14px; border-bottom: 1px solid #F0F0F0;
}
#preview-area .pv-row .pv-key { font-weight: 600; color: #2D3748; flex: 1; font-size: 0.85rem; }
#preview-area .pv-row .pv-val { color: #4A5568; text-align: right; flex: 1; font-size: 0.85rem; }
#preview-area .pv-row.diff { background: #FFF5F5; }
#preview-area .pv-row.diff .pv-val { color: #E53E3E; font-weight: 700; }
#preview-area .pv-row.diff .pv-key { color: #E53E3E; }
#preview-area .pv-memo { padding: 6px 14px; font-size: 0.8rem; color: #718096; border-bottom: 1px solid #F0F0F0; }

.export-btns {
  padding: 12px 16px; display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border-top: 1px solid var(--border);
}
.export-btns .btn-row { display: flex; gap: 8px; }
.export-btns .btn-row .btn { flex: 1; }

/* --- スナックバー --- */
.snackbar {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(100px);
  background: #2D3748; color: #fff; padding: 12px 24px;
  border-radius: var(--radius); font-size: 0.85rem; font-weight: 600;
  box-shadow: var(--shadow-md);
  transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
  z-index: 1000; white-space: nowrap; max-width: 90vw; text-align: center;
}
.snackbar.show { transform: translateX(-50%) translateY(0); }

/* --- 確認ダイアログ --- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: none; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px; max-width: 320px; width: 100%;
  text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,0.15);
}
.modal-box p { margin-bottom: 20px; font-size: 0.95rem; font-weight: 500; }
.modal-box .modal-btns { display: flex; gap: 10px; }
.modal-box .modal-btns .btn { flex: 1; }

/* --- PWA install banner --- */
.install-banner {
  background: linear-gradient(135deg, var(--accent), #2B6CB0);
  padding: 12px 16px; display: none; align-items: center; gap: 10px;
  cursor: pointer; border-radius: var(--radius); margin: 0 16px 10px;
  box-shadow: var(--shadow);
}
.install-banner.show { display: flex; }
.install-banner p { flex: 1; font-size: 0.8rem; font-weight: 600; color: #fff; }
.install-banner .btn { padding: 6px 14px; font-size: 0.75rem; background: #fff; color: var(--accent); }

/* --- 項目追加ボタン --- */
.btn-add-item {
  width: 100%; padding: 10px;
  background: var(--bg); border: 1px dashed var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
  font-family: var(--font); font-size: 0.85rem; font-weight: 500;
  color: var(--accent); margin-top: 4px;
  transition: all var(--transition);
}
.btn-add-item:hover { background: #EBF8FF; border-color: var(--accent); }

/* --- スワイプ削除 --- */
.swipe-row {
  position: relative; overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.swipe-row:last-of-type { border-bottom: none; }
.swipe-content {
  position: relative; z-index: 2;
  box-sizing: border-box;
  width: 100%; min-width: 100%;
  background: #fff;
  transition: transform 0.2s ease;
}
.swipe-content.diff {
  background: #FFF5F5;
}
.swipe-actions {
  position: absolute; right: 0; top: 0; bottom: 0;
  z-index: 1;
  display: flex;
}
.swipe-edit-btn {
  width: 60px;
  background: #3182CE; color: #fff; border: none;
  font-family: var(--font); font-size: 0.8rem; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.swipe-delete-btn {
  width: 60px;
  background: var(--highlight); color: #fff; border: none;
  font-family: var(--font); font-size: 0.8rem; font-weight: 700;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* --- Utilities --- */
.hidden { display: none !important; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E0; border-radius: 4px; }

/* --- Safe area for notch --- */
@supports (padding-top: env(safe-area-inset-top)) {
  .header { padding-top: calc(14px + env(safe-area-inset-top)); }
  .export-btns { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
}
