/* ===== CSS変数 ===== */
:root { --accent-color: #111827; }

/* ===== ベーススタイル ===== */
body {
  font-family: 'Inter', 'Noto Sans JP', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  background: #f3f4f6;
  color: #111827;
  padding: 0;
  margin: 0;
  line-height: 1.6;
  overscroll-behavior-y: contain;
}

/* ===== ヘッダー ===== */
.header {
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  position: sticky;
  top: 0;
  z-index: 40;
}
.header-content {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}
.header-subject-select {
  height: 36px;
  padding: 0 0.75rem;
  padding-right: 1.75rem;
  background: var(--accent-color);
  color: #fff;
  border-radius: 0.5rem;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='white' d='M6 9L1 4h10L6 9z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  transition: all 0.15s;
  min-width: 100px;
}
.header-subject-select:hover:not(:disabled) {
  filter: brightness(1.1);
}
.header-subject-select:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}
.header-subject-select:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}
.header-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  color: #111827;
}
.header-settings {
  height: 36px;
  padding: 0 0.75rem;
  background: transparent;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 0.875rem;
}
.header-settings:hover:not(:disabled) {
  background: #f9fafb;
  border-color: #d1d5db;
  color: #111827;
}
.header-settings:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.app { 
  max-width: 900px; 
  margin: 0 auto; 
  padding: 2rem;
}



/* ===== ステータスカード ===== */
.status {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: .75rem;
  margin-top: .25rem;
}
.stat-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: .75rem;
  padding: .75rem 1rem;
  box-shadow: 0 10px 20px rgba(0,0,0,0.05), 0 2px 6px rgba(0,0,0,0.05);
}
.stat-label {
  font-size: .8rem;
  color: #6b7280;
  margin-bottom: .125rem;
}
.stat-time {
  font-size: 1.6rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== プログレスバー ===== */
.progress {
  width: 100%;
  height: 12px;
  background: linear-gradient(180deg, #e5e7eb, #f3f4f6);
  border-radius: 9999px;
  overflow: hidden;
  margin: .5rem 0 .5rem;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #60a5fa, #22c55e);
  width: 0%;
  transition: width .3s ease;
}

/* ===== テーブル ===== */
table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 1rem;
}
th, td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #d1d5db;
  text-align: left;
}
tr.current { background-color: #d1fae5; }

/* メインテーブルスタイル */
table.table thead { background: #f9fafb; }
table.table th { color: #6b7280; font-weight: 700; font-size: 1rem; }
table.table td { background: #fff; font-variant-numeric: tabular-nums; }
table.table tr { transition: background .15s ease; }
table.table tr:hover td { background: #f9fafb; }
table.table tr.current td { background-color: #d1fae5; }
table.table th:nth-child(2),
table.table td:nth-child(2) { text-align: right; }

/* ===== ボタン ===== */
.btn {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  border: none;
  border-radius: 0.5rem;
  background: #e5e7eb;
  color: #111827;
  cursor: pointer;
  transition: background 0.2s ease;
}
.btn:hover:not(:disabled) { filter: brightness(.98); }
.btn:disabled { opacity: .7; cursor: not-allowed; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1d4ed8; }
.btn-secondary { background: #10b981; color: #fff; }
.btn-secondary:hover:not(:disabled) { background: #059669; }
.btn-sm { padding: .45rem .8rem; font-size: .9rem; }
.btn-block { display: block; width: 100%; }
.btn-ghost { background: #f3f4f6; color: #111827; }
.btn-ghost:hover:not(:disabled) { background: #e5e7eb; }
.btn-circle { 
  width: 80px; 
  height: 80px; 
  border-radius: 9999px; 
  padding: 0; 
  display: inline-flex; 
  align-items: center; 
  justify-content: center; 
  font-weight: 700; 
  font-size: 1rem; 
  white-space: nowrap; 
}

/* コントロールボタンコンテナ */
.controls { 
  display: flex; 
  gap: .75rem; 
  align-items: center; 
  justify-content: center; 
  margin: .75rem 0 0; 
}

/* ===== 設定UI ===== */
.settings {
  margin-top: 1.25rem;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: .75rem;
  padding: 1rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.settings h2 {
  font-size: 1.1rem;
  margin: 0 0 .75rem;
}
.settings-row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem .75rem;
  align-items: center;
  margin-bottom: .75rem;
}
.settings-row select {
  flex: 1;
  min-width: 0;
  padding: .4rem .6rem;
  border: 1px solid #d1d5db;
  border-radius: .5rem;
  background: #fff;
}
.settings-row label { color: #374151; }

/* ===== エディタ ===== */
.editor table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.editor th, .editor td { 
  border-bottom: 1px solid #e5e7eb; 
  padding: .4rem .3rem;
  vertical-align: middle;
}
.editor th:nth-child(1) { width: 50%; }
.editor th:nth-child(2) { width: 40%; padding-left: 1.25rem; white-space: nowrap; }
.editor th:nth-child(3) { width: 10%; }
#totalMinutes {
  font-weight: 700;
  /* color: #2563eb; */
}
.editor td:nth-child(1) { padding-right: 0.75rem; }
.editor td:nth-child(2) { 
  padding-left: 0.75rem;
  padding-right: 0.75rem;
  text-align: center;
}
.editor td:nth-child(3) { padding-left: 0.75rem; }
.editor input[type="text"], .editor input[type="number"] {
  width: 100%;
  padding: .35rem .4rem;
  border: 1px solid #d1d5db;
  border-radius: .5rem;
  background: #fff;
}
.editor .row-actions { 
  text-align: right; 
  width: 40px; 
  white-space: nowrap;
  vertical-align: middle;
}
.editor .danger {
  background: #ef4444;
  color: #fff;
  border-radius: 50%;
  box-shadow: none;
  border: none;
  white-space: nowrap;
  width: 28px;
  height: 28px;
  padding: 0;
  font-size: 1.1rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
.editor .danger:hover { background: #dc2626; }

/* 時間コントロール */
.time-control {
  display: inline-flex;
  align-items: stretch;
  gap: 0;
  justify-content: center;
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  background: #fff;
  overflow: hidden;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}
.time-control input[type="number"] {
  width: 45px;
  text-align: center;
  font-weight: 600;
  font-size: 1rem;
  background: transparent;
  cursor: default;
  border: none;
  border-left: 1px solid #d1d5db;
  border-right: 1px solid #d1d5db;
  border-radius: 0;
  padding: 0.3rem 0;
  margin: 0;
  -webkit-appearance: none;
  -moz-appearance: textfield;
}
.time-control input[type="number"]::-webkit-inner-spin-button,
.time-control input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.time-btn {
  width: 30px;
  height: auto;
  border: none;
  background: transparent;
  color: #6b7280;
  font-size: 1.2rem;
  font-weight: 400;
  cursor: pointer;
  transition: background 0.1s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0.3rem 0;
  margin: 0;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}
.time-btn:hover { background: #f3f4f6; }
.time-btn:active { background: #e5e7eb; }

/* ===== ドロワー ===== */

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
  z-index: 90;
}
.backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 90vw);
  height: 100vh;
  background: #fff;
  box-shadow: -8px 0 24px rgba(0,0,0,.15);
  transform: translateX(100%);
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
  z-index: 100;
}
.drawer.active { transform: translateX(0); }
.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  border-bottom: 1px solid #e5e7eb;
}
.drawer-header h2 { margin: 0; font-size: 1.25rem; font-weight: 700; }
.drawer-close {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #374151;
  color: #fff;
  border: none;
  border-radius: 0.5rem;
  cursor: pointer;
  font-size: 1.5rem;
  line-height: 1;
}
.drawer-close:hover {
  background: #1f2937;
}
.drawer .settings { 
  box-shadow: none; 
  border: none; 
  border-radius: 0; 
  margin: 0; 
  height: 100%; 
  overflow-y: auto; 
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: 3rem;
}

/* ===== ソーシャルボタン ===== */
.section-divider {
  border: none;
  height: 1px;
  background: #e5e7eb;
  margin: 1rem 0 1.25rem;
}
.social-section { margin-top: 1rem; }
.social-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.social-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: #fff;
  color: #111827;
  font-weight: 600;
  border: 1px solid #e5e7eb;
  border-radius: 1rem;
  text-decoration: none;
  transition: all 0.15s ease;
  font-size: 0.95rem;
}
.social-button:hover {
  background: #f9fafb;
  border-color: #d1d5db;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.social-button.contact {
  background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
  border: 1px solid #e5e7eb;
  color: #4b5563;
}
.social-button.contact:hover {
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  border-color: #d1d5db;
}
.social-button.twitter {
  background: linear-gradient(135deg, #1da1f2 0%, #0c85d0 100%);
  color: #fff;
  border: none;
  box-shadow: 0 2px 8px rgba(29, 161, 242, 0.25);
}
.social-button.twitter:hover {
  background: linear-gradient(135deg, #1a91da 0%, #0a75b9 100%);
  box-shadow: 0 4px 12px rgba(29, 161, 242, 0.35);
}
.social-button.instagram {
  background: linear-gradient(135deg, #6b7280 0%, #4b5563 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(107, 114, 128, 0.25);
}
.social-button.instagram:hover {
  background: linear-gradient(135deg, #4b5563 0%, #374151 100%);
  box-shadow: 0 4px 12px rgba(107, 114, 128, 0.35);
}

/* Buy Me a Coffee ボタン */
.donate { display: flex; justify-content: center; }
.bmc-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, #ffdd00 0%, #ffc700 100%);
  color: #000;
  font-weight: 600;
  font-size: 0.95rem;
  border-radius: 1rem;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(255, 221, 0, 0.3);
  transition: transform .15s ease, box-shadow .15s ease;
  border: none;
}
.bmc-inline { 
  position: static; 
  box-shadow: 0 2px 8px rgba(255, 221, 0, 0.25);
  width: 100%;
  justify-content: center;
}
.bmc-button:hover {
  transform: translateY(-1px);
  background: linear-gradient(135deg, #ffc700 0%, #ffb700 100%);
  box-shadow: 0 4px 12px rgba(255, 221, 0, 0.4);
}
.bmc-button:active { transform: translateY(0); }

/* ===== プルリロード ===== */
#pullToRefresh {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.95);
  z-index: 1000;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  transition: all 0.3s ease;
}

/* ===== 使用上の注意 ===== */
.usage-notes {
  padding: 16px;
  background: #fef3c7;
  border-radius: 8px;
  margin-top: 24px;
  margin-bottom: 24px;
}
.usage-notes h3 {
  margin-bottom: 10px;
  color: #92400e;
  font-size: 13px;
  font-weight: 600;
}
.usage-notes ul {
  margin: 0;
  padding-left: 20px;
  font-size: 12px;
  color: #92400e;
  line-height: 1.6;
}

/* ===== モバイル用ヘッダー ===== */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 0.75rem 1rem;
  z-index: 40;
  justify-content: space-between;
  align-items: center;
}
.mobile-header-left {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.mobile-header-right {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.mobile-logo {
  font-size: 1.25rem;
}
.mobile-app-name {
  font-size: 0.875rem;
  font-weight: 600;
  color: #6b7280;
}
.mobile-subject-select {
  font-size: 0.75rem;
  font-weight: 600;
  height: 32px;
  padding: 0 0.6rem;
  padding-right: 1.4rem;
  background-color: var(--accent-color);
  color: #fff;
  border-radius: 0.5rem;
  border: none;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='8' viewBox='0 0 12 12'%3E%3Cpath fill='white' d='M6 9L1 4h10L6 9z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.4rem center;
  transition: all 0.15s;
  min-width: 65px;
  text-align: left;
}
.mobile-subject-select:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}
.mobile-subject-select:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}
.mobile-settings {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.15s;
}
.mobile-settings:hover {
  opacity: 1;
}
.mobile-settings:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* ===== モバイル対応 ===== */
@media (max-width: 640px) {
  .header { display: none; }
  .mobile-header { display: flex; }
  body { 
    font-size: 16px; 
  }
  .app { 
    padding: 1rem;
    margin-top: 60px;
    padding-left: calc(1rem + env(safe-area-inset-left)); 
    padding-right: calc(1rem + env(safe-area-inset-right));
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }
  
  /* ドロワー内の安全領域対応 */
  .drawer .settings {
    padding-bottom: calc(3rem + env(safe-area-inset-bottom));
  }
  
  
  /* ステータスカード */
  .status { 
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 0.5rem;
  }
  .stat-card { padding: 0.6rem 0.75rem; }
  .stat-label { font-size: 0.75rem; }
  .stat-time { font-size: 1.2rem; }
  
  /* テーブル */
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-left: calc(-1rem - env(safe-area-inset-left));
    margin-right: calc(-1rem - env(safe-area-inset-right));
    padding-left: calc(1rem + env(safe-area-inset-left));
    padding-right: calc(1rem + env(safe-area-inset-right));
  }
  table { min-width: 320px; }
  table th, table td { 
    padding: 0.6rem 0.5rem; 
    font-size: 1rem;
    white-space: nowrap;
  }
  
  /* コントロール */
  .controls { 
    position: sticky; 
    bottom: 0; 
    background: #f3f4f6; 
    padding: 0.75rem;
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
    margin-left: calc(-1rem - env(safe-area-inset-left));
    margin-right: calc(-1rem - env(safe-area-inset-right));
    margin-bottom: calc(-1rem - env(safe-area-inset-bottom));
    box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
  }
  
  /* ボタン */
  button { padding: 0.6rem 1rem; font-size: 0.95rem; }
  .btn-circle { width: 90px; height: 90px; font-size: 1.05rem; }
  
  
  /* ドロワー */
  .drawer { width: min(100vw, 420px); }
  
  /* プログレスバー */
  .progress { margin: 0.5rem 0; }
  
  /* エディタ */
  .editor .row-actions { width: 45px; }
  .editor .danger { width: 26px; height: 26px; font-size: 1rem; }
  .editor td:nth-child(1) { padding-right: 0.6rem; }
  .editor td:nth-child(2) { padding-left: 0.6rem; padding-right: 0.6rem; }
  .editor td:nth-child(3) { padding-left: 0.6rem; }
  
  /* 時間コントロール */
  .time-control input[type="number"] { width: 44px; font-size: 0.95rem; }
  .time-btn { width: 32px; font-size: 1.2rem; }
  
  /* ソーシャルボタン */
  .social-buttons { gap: 0.6rem; margin-bottom: 1rem; }
  .social-button { padding: 0.65rem 0.9rem; font-size: 0.9rem; }
}


/* Extra small devices */
@media (max-width: 420px) {
  .app {
    padding: 0.75rem;
    padding-left: calc(0.75rem + env(safe-area-inset-left)); 
    padding-right: calc(0.75rem + env(safe-area-inset-right));
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
  }
  
  /* タイトル */
  .title { 
    font-size: 1.05rem;
    padding-right: 2.5rem;
    margin-bottom: 0.6rem;
  }
  .title-subject { font-size: 1.1rem; }
  
  /* ステータスカード（1列） */
  .status { 
    grid-template-columns: 1fr;
    gap: 6px;
  }
  .stat-card { padding: 0.5rem 0.6rem; }
  .stat-time { font-size: 1.15rem; }
  
  /* テーブル */
  table th, table td { 
    padding: 0.5rem 0.4rem; 
    font-size: 0.95rem;
  }
  
  /* ボタン */
  .btn-circle { width: 75px; height: 75px; font-size: 0.95rem; }
  
}