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

:root {
  --primary: #2d6a4f;
  --primary-dark: #1b4332;
  --primary-light: #52b788;
  --accent: #d4a017;
  --danger: #e63946;
  --bg: #f8f9fa;
  --bg-card: #ffffff;
  --text: #212529;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --shadow: 0 2px 8px rgba(0,0,0,0.1);
  --radius: 10px;
}

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

/* ===== レイアウト ===== */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

/* ===== ヘッダー ===== */
header {
  background: var(--primary-dark);
  color: white;
  padding: 16px;
  text-align: center;
}

header h1 {
  font-size: 1.4rem;
  font-weight: bold;
  letter-spacing: 0.05em;
}

header p {
  font-size: 0.85rem;
  opacity: 0.8;
  margin-top: 4px;
}


/* ===== カード ===== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 {
  font-size: 1.1rem;
  color: var(--primary-dark);
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary-light);
}

.card h3 {
  font-size: 1rem;
  color: var(--primary);
  margin-bottom: 12px;
}

/* ===== ステップ表示 ===== */
.step-indicator {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 16px 0;
  margin-bottom: 8px;
}

.step-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: bold;
  position: relative;
}

.step-dot.active {
  background: var(--primary);
  color: white;
}

.step-dot.done {
  background: var(--primary-light);
  color: white;
}

.step-dot::after {
  content: attr(data-label);
  position: absolute;
  bottom: -20px;
  font-size: 0.65rem;
  white-space: nowrap;
  color: var(--text-muted);
}

.step-dot.active::after {
  color: var(--primary);
  font-weight: bold;
}

/* ===== フォーム ===== */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: bold;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(82,183,136,0.15);
}

.form-group input.error {
  border-color: var(--danger);
}

.error-msg {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 4px;
}

/* ===== プレイヤー入力グループ ===== */
.player-inputs {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-row .player-label {
  min-width: 32px;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: bold;
}

.player-row input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
}

.player-row input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(82,183,136,0.15);
}

/* ===== 場代入力 ===== */
.venue-total {
  background: #f0f7f4;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
}

.venue-breakdown {
  display: grid;
  gap: 8px;
}

.venue-player-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.venue-player-name {
  min-width: 80px;
  font-size: 0.9rem;
  font-weight: bold;
  color: var(--primary-dark);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.venue-player-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  text-align: right;
}

.venue-player-row input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(82,183,136,0.15);
}

.venue-sum-check {
  margin-top: 10px;
  font-size: 0.85rem;
  text-align: right;
}

.venue-sum-check.ok {
  color: var(--primary);
}

.venue-sum-check.ng {
  color: var(--danger);
}

/* ===== 点数入力 ===== */
.game-inputs {
  display: grid;
  gap: 8px;
}

.game-player-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.game-player-name {
  min-width: 80px;
  font-size: 0.9rem;
  font-weight: bold;
  color: var(--primary-dark);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-player-row input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  text-align: right;
}

.game-player-row input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(82,183,136,0.15);
}

.zero-sum-check {
  margin-top: 10px;
  font-size: 0.85rem;
  text-align: right;
}

.zero-sum-check.ok {
  color: var(--primary);
}

.zero-sum-check.ng {
  color: var(--danger);
}

/* ===== 精算結果 ===== */
.result-summary {
  background: #f0f7f4;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 16px;
}

.result-summary h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.balance-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.balance-table th {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.8rem;
}

.balance-table td {
  padding: 8px;
  border-bottom: 1px solid #f0f0f0;
}

.balance-table td:last-child {
  text-align: right;
  font-weight: bold;
}

.balance-positive {
  color: var(--primary);
}

.balance-negative {
  color: var(--danger);
}

.transactions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.transaction-item {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.95rem;
}

.transaction-item .from {
  font-weight: bold;
  color: var(--danger);
}

.transaction-item .arrow {
  color: var(--text-muted);
  font-size: 1.1rem;
}

.transaction-item .to {
  font-weight: bold;
  color: var(--primary);
}

.transaction-item .amount {
  margin-left: auto;
  font-weight: bold;
  font-size: 1.05rem;
  color: var(--accent);
}

.no-transaction {
  text-align: center;
  color: var(--text-muted);
  padding: 16px;
  font-size: 0.9rem;
}

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--primary);
  color: white;
  width: 100%;
}

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

.btn-primary:disabled {
  background: var(--border);
  color: var(--text-muted);
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary);
  width: 100%;
}

.btn-secondary:hover {
  background: #f0f7f4;
}

.btn-copy {
  background: var(--accent);
  color: white;
  width: 100%;
}

.btn-copy:hover {
  background: #b8860b;
}

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

.btn-back {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  width: 100%;
  font-size: 0.9rem;
}

.btn-back:hover {
  background: var(--bg);
}

.btn-stack {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ===== ホームページ特有 ===== */
.player-count-select {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 20px;
}

.count-option {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: white;
}

.count-option:hover {
  border-color: var(--primary-light);
  background: #f0f7f4;
}

.count-option.selected {
  border-color: var(--primary);
  background: #e8f5f0;
}

.count-option .count-number {
  font-size: 2.5rem;
  font-weight: bold;
  color: var(--primary);
  display: block;
}

.count-option .count-label {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ===== ルームURL表示 ===== */
.room-url-box {
  background: #f8f9fa;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 0.8rem;
  word-break: break-all;
  color: var(--primary-dark);
  margin-bottom: 12px;
  font-family: monospace;
}

/* ===== ローディング ===== */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-muted);
}

.loading-spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

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

/* ===== エラー ===== */
.error-box {
  background: #fff5f5;
  border: 1px solid #ffc9c9;
  border-radius: 8px;
  padding: 16px;
  color: var(--danger);
  text-align: center;
}

/* ===== 完了バナー ===== */
.done-banner {
  background: var(--primary);
  color: white;
  border-radius: 8px;
  padding: 14px 16px;
  text-align: center;
  font-weight: bold;
  margin-bottom: 16px;
}

/* ===== フッター ===== */
footer {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  padding: 24px 16px;
}

footer a {
  color: var(--primary-light);
  text-decoration: none;
}

/* ===== ゲーム設定 ===== */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}


.uma-inputs {
  margin-bottom: 8px;
}

.uma-row {
  display: -webkit-flex;
  display: flex;
  -webkit-align-items: center;
  align-items: center;
  margin-bottom: 8px;
}

.uma-row:last-child {
  margin-bottom: 0;
}

.uma-row span:first-child {
  min-width: 36px;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: bold;
}

.uma-row span:first-child {
  margin-right: 8px;
}

.uma-row input {
  width: 90px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  font-family: inherit;
  text-align: right;
  margin-right: 8px;
}

.uma-row input:focus {
  outline: none;
  border-color: var(--primary-light);
  box-shadow: 0 0 0 3px rgba(82,183,136,0.15);
}

/* ===== 対局記録テーブル ===== */
.game-log-wrapper {
  overflow-x: auto;
}

.game-log-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  min-width: 260px;
}

.game-log-table th,
.game-log-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  text-align: right;
  white-space: nowrap;
}

.game-log-table th:first-child,
.game-log-table td:first-child {
  text-align: left;
}

.cumulative-row {
  background: #f0f7f4;
}

.cumulative-row td {
  border-top: 2px solid var(--primary-light);
  border-bottom: none;
}

/* 対局記録テーブル内の点数・pt表示 */
.log-score {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.log-pt {
  font-size: 0.9rem;
  font-weight: bold;
  white-space: nowrap;
}

/* ===== 修正ボタン ===== */
.btn-edit {
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: white;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-edit:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-edit.btn-edit-active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.btn-delete {
  padding: 3px 8px;
  border: 1px solid #ffc9c9;
  border-radius: 5px;
  background: white;
  color: var(--danger);
  font-size: 0.75rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  margin-left: 4px;
}

.btn-delete:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.editing-row td {
  background: #fffbf0;
}

/* ===== 飛び選択 ===== */
.tobi-select {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.tobi-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
  background: white;
}

.tobi-option:hover {
  border-color: var(--danger);
  background: #fff5f5;
}

.tobi-option input[type="radio"] {
  accent-color: var(--danger);
  width: 16px;
  height: 16px;
}

.tobi-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ===== レスポンシブ ===== */
@media (max-width: 400px) {
  header h1 {
    font-size: 1.2rem;
  }

  .card {
    padding: 14px;
  }

  .count-option .count-number {
    font-size: 2rem;
  }
}
