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

body {
  font-family: "Meiryo", "Hiragino Kaku Gothic ProN", sans-serif;
  background-color: #f1f3f5;
  color: #212529;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ヘッダー・タブナビゲーション */
.app-header {
  background-color: #212529;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  height: 52px;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: bold;
  color: #ffd43b;
}

.tab-nav {
  display: flex;
  gap: 8px;
}

.tab-btn {
  background: #343a40;
  color: #dee2e6;
  border: 1px solid #495057;
  padding: 6px 18px;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: bold;
  cursor: pointer;
}

.tab-btn.active {
  background: #1971c2;
  color: #ffffff;
  border-color: #4dabf7;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.header-user input {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid #ced4da;
  width: 130px;
}

.room-badge {
  background: #495057;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.82rem;
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
}

/* 設定タブ */
.setup-grid {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  padding: 16px;
  height: 100%;
}

.card-panel {
  background: #ffffff;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.panel-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.create-room-row {
  display: flex;
  gap: 8px;
}

.create-room-row input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid #ced4da;
  border-radius: 4px;
}

.hint-text {
  font-size: 0.8rem;
  color: #6c757d;
}

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

.room-item {
  border: 1px solid #ced4da;
  border-radius: 6px;
  padding: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #f8f9fa;
}

.room-item.active-room {
  border: 2px solid #1971c2;
  background: #e7f5ff;
}

.sub-box {
  border: 1px solid #e9ecef;
  background: #f8f9fa;
  border-radius: 6px;
  padding: 12px;
}

.sub-box h3 {
  font-size: 0.98rem;
  margin-bottom: 10px;
  color: #343a40;
}

.seats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 8px;
}

.seat-card {
  background: #ffffff;
  border: 1px solid #ced4da;
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.seat-card.my-seat {
  border: 2px solid #2b8a3e;
  background: #ebfbee;
}

.rules-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 10px;
  align-items: center;
}

.rules-form-grid label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
  font-weight: bold;
  background: #ffffff;
  padding: 6px 10px;
  border-radius: 4px;
  border: 1px solid #dee2e6;
}

.rules-form-grid input[type="number"],
.rules-form-grid select {
  width: 90px;
  padding: 4px;
}

.checkbox-label {
  display: flex !important;
  justify-content: flex-start !important;
  gap: 8px;
  cursor: pointer;
}

.deal-preview {
  margin-top: 8px;
  font-size: 0.88rem;
  font-weight: bold;
  color: #1971c2;
}

.packs-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* 対戦タブ */
.battle-top-bar {
  background: #212529;
  color: #ffffff;
  padding: 6px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.player-badges-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.p-badge {
  background: #343a40;
  color: #f8f9fa;
  border: 2px solid #495057;
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 0.86rem;
  font-weight: bold;
}

.p-badge.turn-current {
  background: #ffd43b;
  color: #000000;
  border-color: #f08c00;
}

.p-badge.turn-next {
  background: #51cf66;
  color: #000000;
  border-color: #2b8a3e;
}

.round-info-label {
  color: #ffd166;
  font-weight: bold;
  font-size: 0.95rem;
}

.battle-center-area {
  flex: 1;
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  min-height: 0;
}

.map-section {
  flex: 1;
  background: #ffffff;
  border: 1px solid #dee2e6;
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.map-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 6px;
  font-size: 0.9rem;
  font-weight: bold;
}

.island-summary {
  margin-left: auto;
  color: #1971c2;
}

.map-canvas-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e6f2ff;
  border: 1px solid #90b4ce;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

#main-map-canvas {
  cursor: grab;
  display: block;
  touch-action: none;   /* 指のドラッグ・ピンチは地図の移動と拡大に使う */
}

#main-map-canvas:active {
  cursor: grabbing;
}

.battle-side-panel {
  width: 310px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rule-status-box {
  background: #f8f9fa;
  border: 2px groove #ced4da;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 0.83rem;
  line-height: 1.45;
  white-space: pre-line;
  font-weight: bold;
}

.log-box-wrapper {
  flex: 1;
  background: #ffffff;
  border: 1px solid #ced4da;
  border-radius: 6px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.log-title {
  font-size: 0.82rem;
  font-weight: bold;
  color: #495057;
  margin-bottom: 4px;
}

.game-log-box {
  flex: 1;
  overflow-y: auto;
  font-size: 0.82rem;
  line-height: 1.45;
  padding: 4px;
  background: #fcfcfc;
}

.pref-green {
  color: #2b8a3e;
  font-weight: bold;
}

/* 手札エリア */
.battle-bottom-area {
  display: flex;
  gap: 10px;
  padding: 6px 12px;
  background: #e9ecef;
  border-top: 1px solid #ced4da;
}

.hand-panel {
  flex: 1;
  background: #ffffff;
  border: 1px solid #ced4da;
  border-radius: 6px;
  padding: 6px 8px;
  min-width: 0;
}

.hand-panel-title {
  font-size: 0.82rem;
  font-weight: bold;
  color: #495057;
  margin-bottom: 4px;
}

.hand-cards-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  min-height: 118px;
  align-items: center;
}

.hand-card-canvas {
  border-radius: 6px;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s;
}

.hand-card-canvas:hover {
  transform: translateY(-3px);
}

.action-panel {
  width: 210px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}

.btn {
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  font-weight: bold;
  cursor: pointer;
  font-family: inherit;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: #1971c2;
  color: #ffffff;
}

.btn-success {
  background: #2b8a3e;
  color: #ffffff;
}

.btn-danger {
  background: #e03131;
  color: #ffffff;
}

.btn-secondary {
  background: #495057;
  color: #ffffff;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.8rem;
}

.btn-large {
  padding: 10px 20px;
  font-size: 1rem;
}

.btn-play {
  height: 68px;
  font-size: 1rem;
}

.battle-status-bar {
  background: #343a40;
  color: #ffffff;
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 24px;
  font-size: 0.92rem;
}

.my-score {
  color: #63e6be;
  font-weight: bold;
  font-size: 1rem;
}
/* ===== 自分の手番の通知 ===== */
.hand-panel.my-turn {
  border: 2px solid #f08c00;
  animation: my-turn-glow 1.4s ease-in-out infinite;
}
@keyframes my-turn-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(240, 140, 0, 0.0); }
  50% { box-shadow: 0 0 0 5px rgba(240, 140, 0, 0.45); }
}
.turn-toast {
  position: fixed;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%);
  background: #ffd43b;
  color: #212529;
  border: 3px solid #f08c00;
  border-radius: 14px;
  padding: 14px 28px;
  font-size: 1.4rem;
  font-weight: bold;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  z-index: 50;
  pointer-events: none;
  opacity: 0;
  white-space: nowrap;
}
.turn-toast.show {
  animation: turn-toast 1.8s ease-out forwards;
}
@keyframes turn-toast {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7); }
  12% { opacity: 1; transform: translate(-50%, -50%) scale(1.05); }
  20% { transform: translate(-50%, -50%) scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; }
}

/* ===== 結果画面 ===== */
.result-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 16px;
}
.result-modal.show { display: flex; }
.result-box {
  background: #ffffff;
  border-radius: 12px;
  padding: 18px 20px;
  width: min(520px, 100%);
  max-height: 100%;
  overflow-y: auto;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}
.result-box h2 { font-size: 1.25rem; margin-bottom: 12px; text-align: center; }
.result-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.result-table th, .result-table td { padding: 6px 8px; border-bottom: 1px solid #e9ecef; text-align: left; }
.result-table th { font-size: 0.8rem; color: #6c757d; }
.result-table td:nth-child(3), .result-table td:nth-child(4), .result-table th:nth-child(3), .result-table th:nth-child(4) { text-align: right; }
.result-table tr.me td { background: #ebfbee; }
.result-buttons { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }

/* ===== 部屋主の操作 ===== */
.host-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; align-items: center; }
.host-note { background: #fff9db; border: 1px solid #ffe066; border-radius: 6px; padding: 6px 10px; font-size: 0.85rem; }

/* ===== 地図の「置いた人」の凡例 ===== */
.owner-legend {
  position: absolute;
  left: 6px;
  top: 6px;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #ced4da;
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
  pointer-events: none;
  max-width: 60%;
}
.owner-legend span { display: flex; align-items: center; gap: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.owner-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; flex: none; border: 1px solid #212529; }

/* ===== スマホ（幅が狭い画面） ===== */
@media (max-width: 760px) {
  .app-header { height: auto; flex-wrap: wrap; gap: 6px; padding: 6px 10px; }
  .brand-title { font-size: 1rem; }
  .tab-btn { padding: 5px 10px; font-size: 0.85rem; }
  .header-user { width: 100%; gap: 6px; font-size: 0.8rem; }
  .header-user label { white-space: nowrap; }
  .header-user input { flex: 1; width: auto; min-width: 0; }
  .room-badge { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }

  .setup-grid { grid-template-columns: 1fr; padding: 10px; gap: 10px; height: auto; }
  #room-config-panel { order: -1; }   /* スマホでは、設定と開始ボタンを先に出す */
  .card-panel { overflow: visible; }
  .panel-header-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .host-actions { justify-content: stretch; }
  .host-actions .btn { flex: 1; }
  .seats-grid, .rules-form-grid { grid-template-columns: 1fr; }
  .seat-card { flex-wrap: wrap; }

  .battle-top-bar { padding: 4px 8px; }
  .player-badges-row { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; width: 100%; }
  .p-badge { font-size: 0.68rem; padding: 2px 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .round-info-label { font-size: 0.78rem; }

  /* 並び順：上のバー → 地図 → 得点と指示 → 手札・出すボタン → ログ */
  .battle-center-area { display: contents; }
  .battle-top-bar { order: 0; }
  .map-section { order: 1; flex: none; height: 38vh; height: 38dvh; padding: 4px; margin: 6px 8px 0; }
  .map-toolbar { margin-bottom: 4px; }
  .battle-status-bar { order: 2; }
  .battle-bottom-area { order: 3; }
  .battle-side-panel { order: 4; padding: 0 8px 10px; }
  .map-toolbar { flex-wrap: wrap; gap: 6px 10px; font-size: 0.78rem; }
  .island-summary { margin-left: 0; }
  .battle-side-panel { width: 100%; }
  .rule-status-box { display: none; }   /* 細かいルール表示はスマホでは省く */
  .log-box-wrapper { height: 150px; flex: none; }

  .battle-bottom-area { flex-direction: column; padding: 6px 8px; gap: 6px; }
  .action-panel { width: 100%; flex-direction: row; position: sticky; bottom: 0; z-index: 5; background: #e9ecef; padding: 4px 0; }   /* 出すボタンは常に画面下に見えるように */
  .action-panel .btn-play { flex: 1; height: 48px; }
  .hand-panel-title { display: none; }   /* 色の説明は札の上の表記で分かるので省く */
  .hand-cards-scroll { min-height: 0; }
  .battle-status-bar { flex-direction: column; align-items: flex-start; gap: 2px; padding: 6px 10px; font-size: 0.8rem; }
  .turn-toast { font-size: 1.15rem; padding: 12px 20px; }
}
