:root {
  --primary: #e05c2b;
  --primary-dark: #c04a1f;
  --bg: #f5f5f0;
  --card-bg: #ffffff;
  --text: #222222;
  --muted: #666666;
  --border: #e0e0e0;
  --accent: #2b7de0;
  --success: #2bc469;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', sans-serif;
  line-height: 1.6;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

header {
  text-align: center;
  margin-bottom: 32px;
}

header h1 {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.5px;
}

.subtitle {
  color: var(--muted);
  margin-top: 4px;
  font-size: 0.95rem;
}

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

h2 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

/* 目標セクション */
.goal-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.goal-row label {
  font-weight: 600;
  min-width: 120px;
}

.goal-row input {
  width: 120px;
}

.progress-bar-wrap {
  height: 18px;
  background: var(--border);
  border-radius: 9px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #f0914a);
  border-radius: 9px;
  transition: width 0.5s ease;
  width: 0%;
}

.progress-text {
  font-size: 0.9rem;
  color: var(--muted);
  text-align: right;
}

/* フォーム */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

@media (max-width: 600px) {
  .form-grid {
    grid-template-columns: 1fr;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="month"] {
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
  transition: border-color 0.2s;
  background: #fafafa;
  width: 100%;
  font-family: inherit;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="month"]:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}

.time-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
}

.time-inputs input {
  width: 64px;
  text-align: center;
  padding: 10px 6px;
}

.time-inputs span {
  font-weight: 700;
  color: var(--muted);
  font-size: 1.2rem;
}

.preview {
  background: #fff8f5;
  border: 1.5px dashed var(--primary);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.95rem;
  color: var(--primary-dark);
  margin-bottom: 16px;
  min-height: 42px;
  display: flex;
  align-items: center;
}

button {
  cursor: pointer;
  font-family: inherit;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.2s, transform 0.1s;
}

button:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: white;
  padding: 12px 32px;
  font-size: 1rem;
  width: 100%;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.goal-row button {
  background: var(--accent);
  color: white;
  padding: 10px 18px;
}

.goal-row button:hover {
  background: #1a6fd0;
}

/* 統計 */
.stats-section {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

@media (max-width: 700px) {
  .stats-section {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 12px;
  text-align: center;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
}

/* グラフ */
.chart-wrap {
  position: relative;
  height: 200px;
}

canvas {
  width: 100% !important;
}

/* 記録一覧 */
.records-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.records-header h2 {
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: #fafafa;
}

.pace-cell {
  font-weight: 700;
  color: var(--primary);
}

.delete-btn {
  background: none;
  color: #ccc;
  padding: 4px 8px;
  font-size: 1.1rem;
  border-radius: 4px;
}

.delete-btn:hover {
  background: #fee;
  color: #e05;
}

.empty-msg {
  text-align: center;
  color: var(--muted);
  padding: 32px 0;
}

.memo-cell {
  color: var(--muted);
  font-size: 0.85rem;
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* トースト通知 */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #222;
  color: white;
  padding: 12px 24px;
  border-radius: 24px;
  font-size: 0.95rem;
  font-weight: 600;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
  transition: transform 0.3s ease;
  z-index: 1000;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

/* 同期キーモーダル */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 16px;
}

.modal {
  background: white;
  border-radius: var(--radius);
  padding: 40px 32px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
}

.modal-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.modal h2 {
  font-size: 1.4rem;
  margin-bottom: 12px;
}

.modal p {
  color: var(--muted);
  font-size: 0.92rem;
  margin-bottom: 24px;
  line-height: 1.7;
}

.modal input {
  width: 100%;
  margin-bottom: 16px;
  font-size: 1.1rem;
  text-align: center;
  letter-spacing: 1px;
}

/* 同期キーボタン（ヘッダー） */
.sync-key-btn {
  background: none;
  border: 1.5px solid var(--border);
  color: var(--muted);
  font-size: 0.8rem;
  padding: 6px 14px;
  border-radius: 20px;
  margin-top: 10px;
  transition: border-color 0.2s, color 0.2s;
}

.sync-key-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ローディング */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1500;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
