/* ===== リセット & ベース ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --merit:        #10b981;
  --merit-light:  #d1fae5;
  --merit-dark:   #059669;
  --demerit:      #ef4444;
  --demerit-light:#fee2e2;
  --demerit-dark: #dc2626;
  --primary:      #4f46e5;
  --primary-light:#e0e7ff;
  --bg:           #f3f4f6;
  --card:         #ffffff;
  --text:         #111827;
  --text-sub:     #6b7280;
  --border:       #e5e7eb;
  --radius:       12px;
  --radius-sm:    8px;
  --safe-b:       env(safe-area-inset-bottom, 0px);
  --safe-t:       env(safe-area-inset-top, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans',
    'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ===== 画面管理 ===== */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
  overflow: hidden;
}
.screen.active { display: flex; }

.hidden { display: none !important; }

/* ===== ヘッダー ===== */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  height: 54px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.app-header-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.board-title-display {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 8px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  font-size: 20px;
  flex-shrink: 0;
}
.icon-btn:active { background: var(--border); }

/* ===== ロック / セットアップ画面 ===== */
.lock-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 24px 32px;
  padding-bottom: calc(24px + var(--safe-b));
  gap: 12px;
}

.lock-emoji {
  font-size: 56px;
  margin-bottom: 4px;
}

.lock-title {
  font-size: 26px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.lock-subtitle {
  font-size: 14px;
  color: var(--text-sub);
  text-align: center;
}

.pin-dots {
  display: flex;
  gap: 20px;
  margin: 8px 0;
}

.dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--primary);
  background: transparent;
  transition: background 0.15s;
}
.dot.filled {
  background: var(--primary);
}

.pin-error {
  font-size: 13px;
  color: var(--demerit);
  text-align: center;
  font-weight: 500;
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ===== テンキー ===== */
.numpad {
  display: grid;
  grid-template-columns: repeat(3, 76px);
  grid-template-rows: repeat(4, 66px);
  gap: 10px;
  margin-top: 8px;
}

.numpad-btn {
  border: none;
  border-radius: 50%;
  background: var(--card);
  font-size: 24px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
  transition: background 0.12s;
  -webkit-user-select: none;
  user-select: none;
}
.numpad-btn:active { background: var(--border); }

.numpad-btn.empty {
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}

.numpad-btn.backspace {
  font-size: 20px;
  background: transparent;
  box-shadow: none;
  color: var(--text-sub);
}
.numpad-btn.backspace:active { background: var(--border); }

.cancel-link {
  margin-top: 8px;
  border: none;
  background: transparent;
  color: var(--primary);
  font-size: 14px;
  cursor: pointer;
  padding: 8px 16px;
}

/* ===== ホーム画面 ===== */
.screen-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 8px;
}

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

.board-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
  -webkit-user-select: none;
  user-select: none;
}
.board-card:active { border-color: var(--primary); }

.board-card-name {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-card-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
}

.board-card-merit {
  color: var(--merit-dark);
  background: var(--merit-light);
  padding: 2px 10px;
  border-radius: 20px;
  font-weight: 500;
}

.board-card-demerit {
  color: var(--demerit-dark);
  background: var(--demerit-light);
  padding: 2px 10px;
  border-radius: 20px;
  font-weight: 500;
}

.board-card-verdict {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-sub);
  font-weight: 500;
}
.board-card-verdict.merit-dom { color: var(--merit-dark); }
.board-card-verdict.demerit-dom { color: var(--demerit-dark); }

/* ミニバー（ボードカード内） */
.board-card-bar {
  margin-top: 10px;
  position: relative;
  height: 6px;
  border-radius: 3px;
  background: #e5e7eb;
  overflow: hidden;
}
.board-card-bar-merit {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--merit);
  border-radius: 3px;
  transition: width 0.3s;
}
.board-card-bar-demerit {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  background: var(--demerit);
  border-radius: 3px;
  transition: width 0.3s;
}

/* 空状態 */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 24px;
  text-align: center;
}
.empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-title { font-size: 17px; font-weight: 600; color: var(--text); }
.empty-desc { font-size: 14px; color: var(--text-sub); margin-top: 6px; }

/* ボトムバー */
.bottom-bar {
  padding: 12px 16px;
  background: var(--card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.primary-btn {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.primary-btn:active { opacity: 0.8; }

/* ===== ボード画面 ===== */

/* スコアエリア */
.score-area {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  flex-shrink: 0;
}

.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.score-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 80px;
}

.score-num {
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
}
.merit-num { color: var(--merit-dark); }
.demerit-num { color: var(--demerit-dark); }

.score-cell-lbl {
  font-size: 11px;
  color: var(--text-sub);
  margin-top: 2px;
}

.score-verdict {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
  text-align: center;
  flex: 1;
  padding: 0 8px;
  line-height: 1.3;
}
.score-verdict.merit-dom { color: var(--merit-dark); }
.score-verdict.demerit-dom { color: var(--demerit-dark); }
.score-verdict.draw { color: var(--primary); }

/* バー */
.bar-outer { }

.bar-track {
  position: relative;
  height: 12px;
  border-radius: 6px;
  background: #e5e7eb;
  overflow: hidden;
}

.bar-merit {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--merit);
  border-radius: 6px 0 0 6px;
  transition: width 0.4s ease;
}

.bar-demerit {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  background: var(--demerit);
  border-radius: 0 6px 6px 0;
  transition: width 0.4s ease;
}

.bar-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
}

.bar-lbl {
  font-size: 10px;
  color: var(--text-sub);
}
.merit-bar-lbl { color: var(--merit-dark); }
.demerit-bar-lbl { color: var(--demerit-dark); }

/* ===== 2カラム ===== */
.columns {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow: hidden;
}

.col {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.col-sep {
  width: 1px;
  background: var(--border);
  flex-shrink: 0;
}

.col-header {
  padding: 10px 10px 8px;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  text-align: center;
  letter-spacing: 0.2px;
}
.merit-col-header {
  background: var(--merit-light);
  color: var(--merit-dark);
  border-bottom: 1px solid #a7f3d0;
}
.demerit-col-header {
  background: var(--demerit-light);
  color: var(--demerit-dark);
  border-bottom: 1px solid #fecaca;
}

.col-items {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 6px;
}

/* 項目カード */
.item-card {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 8px;
  margin-bottom: 6px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  border-left: 3px solid transparent;
}
.merit-col .item-card { border-left-color: var(--merit); }
.demerit-col .item-card { border-left-color: var(--demerit); }

.item-weight-dots {
  display: flex;
  gap: 3px;
  margin-bottom: 4px;
}
.weight-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.merit-col .weight-dot.on { background: var(--merit); }
.merit-col .weight-dot.off { background: #d1d5db; }
.demerit-col .weight-dot.on { background: var(--demerit); }
.demerit-col .weight-dot.off { background: #d1d5db; }

.item-text {
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
  word-break: break-all;
  margin-bottom: 6px;
}

.item-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
}

.item-act-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-sub);
}
.item-act-btn:active { background: var(--border); }
.item-act-btn.del:active { color: var(--demerit); }

/* 追加ボタン */
.col-add {
  flex-shrink: 0;
  width: 100%;
  padding: 10px;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-top: 1px solid var(--border);
  transition: opacity 0.15s;
}
.merit-add {
  background: var(--merit-light);
  color: var(--merit-dark);
}
.demerit-add {
  background: var(--demerit-light);
  color: var(--demerit-dark);
}
.col-add:active { opacity: 0.7; }

/* 削除リンク */
.board-footer {
  padding: 8px 16px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: var(--card);
  display: flex;
  justify-content: center;
}

.danger-text-btn {
  border: none;
  background: transparent;
  color: var(--demerit);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 12px;
}

/* ===== 設定画面 ===== */
.settings-group {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.settings-row {
  display: flex;
  align-items: center;
  padding: 16px 16px;
  gap: 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; }
.settings-row:active { background: var(--bg); }

.settings-icon { font-size: 22px; }
.settings-label { flex: 1; font-size: 15px; }
.settings-arrow { color: var(--text-sub); font-size: 20px; }
.danger-label { color: var(--demerit); }

.app-version {
  text-align: center;
  font-size: 12px;
  color: var(--text-sub);
  padding: 16px;
}

/* ===== モーダル ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  z-index: 100;
  animation: fade-in 0.2s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-sheet {
  width: 100%;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 0 0 calc(16px + var(--safe-b));
  animation: slide-up 0.25s ease;
}

@keyframes slide-up {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.modal-drag {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 16px;
}

.modal-title {
  font-size: 17px;
  font-weight: 700;
  padding: 0 20px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-body {
  padding: 16px 20px;
}

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
  margin-bottom: 8px;
}
.field-label.mt { margin-top: 16px; }

.field-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  font-family: inherit;
  resize: none;
  outline: none;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
}
.field-textarea:focus { border-color: var(--primary); }

.field-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  color: var(--text);
  background: var(--bg);
}
.field-input:focus { border-color: var(--primary); }

/* 重要度選択 */
.weight-row {
  display: flex;
  gap: 8px;
}

.weight-btn {
  flex: 1;
  height: 44px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-sub);
  transition: all 0.15s;
}
.weight-btn.selected.merit-weight {
  border-color: var(--merit);
  background: var(--merit-light);
  color: var(--merit-dark);
}
.weight-btn.selected.demerit-weight {
  border-color: var(--demerit);
  background: var(--demerit-light);
  color: var(--demerit-dark);
}

/* モーダルアクション */
.modal-actions {
  display: flex;
  gap: 10px;
  padding: 8px 20px 0;
}

.modal-btn {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.modal-btn:active { opacity: 0.8; }

.cancel-btn {
  background: var(--bg);
  color: var(--text-sub);
  border: 1px solid var(--border);
}

.confirm-btn {
  background: var(--primary);
  color: white;
}

.danger-btn {
  background: var(--demerit);
  color: white;
}

.confirm-msg {
  font-size: 14px;
  color: var(--text-sub);
  padding: 12px 20px 8px;
}

/* ===== トースト ===== */
.toast {
  position: fixed;
  bottom: calc(80px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  animation: toast-in 0.25s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}
