/**
 * 麻雀アプリ メインスタイルシート (横画面スマホ最適化・Google DESIGN.md準拠)
 */

:root {
  --table-green: #155724;
  --table-border: #4a2810;
  --felt-texture: radial-gradient(circle at 50% 50%, #1e7e34 0%, #155724 75%, #0f401b 100%);
  --wood-rim: linear-gradient(135deg, #5c3317 0%, #3d210d 50%, #261408 100%);
  --accent-gold: #f59e0b;
  --accent-red: #ef4444;
  --accent-blue: #0284c7;
  --surface-dark: rgba(18, 24, 27, 0.88);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --font-family: "Noto Sans JP", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* URLバーの有無に自動追従 */
  overflow: hidden;
  position: fixed;
  inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  font-family: var(--font-family);
  background-color: #0b130e;
  color: var(--text-main);
  user-select: none;
  -webkit-user-select: none;
}

/* =========================================
   縦画面ガイダンス（スマホ横向き誘導）
   ========================================= */
#orientation-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: #0f172a;
  color: #fff;
  z-index: 99999;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 20px;
}

@media (orientation: portrait) {
  #orientation-overlay {
    display: flex;
  }
}

.rotate-device-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  animation: rotateDevice 2s ease-in-out infinite alternate;
}

@keyframes rotateDevice {
  0% { transform: rotate(0deg); }
  40%, 100% { transform: rotate(90deg); }
}

.rotate-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--accent-gold);
}

.rotate-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* =========================================
   メインゲームコンテナ (16:9〜20:9 横画面フィット)
   ========================================= */
#app-container {
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #000;
}

#mahjong-table {
  position: relative;
  width: 100vw;
  height: 100%;
  height: 100dvh;
  max-width: calc(100dvh * 2.2);
  background: var(--felt-texture);
  border: clamp(4px, 1vh, 8px) solid #3d210d;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.7), 0 0 20px rgba(0, 0, 0, 0.8);
  display: grid;
  grid-template-rows: min(38px, 9dvh) 1fr min(68px, 20dvh);
  grid-template-columns: min(72px, 12vw) 1fr min(72px, 12vw);
  overflow: hidden;
}

/* ヘッダー・トップバー */
.table-header {
  position: absolute;
  top: max(4px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  right: max(8px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
  pointer-events: none;
}

.table-header > * {
  pointer-events: auto;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #38bdf8;
}

.latency-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 5px #22c55e;
}

.room-info-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: 9999px;
  font-size: 0.75rem;
  color: var(--accent-gold);
  font-weight: 700;
}

.btn-fullscreen-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  background: rgba(30, 41, 59, 0.85);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 9999px;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.btn-fullscreen-toggle:active {
  transform: scale(0.94);
  background: rgba(51, 65, 85, 0.95);
}

/* =========================================
   中央ボード (卓中央：局・点棒・ドラ・山残数)
   ========================================= */
.table-center {
  grid-row: 2;
  grid-column: 2;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.center-core {
  width: clamp(90px, 13vw, 120px);
  height: clamp(60px, 16dvh, 80px);
  background: #111827;
  border: 2px solid #374151;
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6), inset 0 0 8px rgba(0,0,0,0.8);
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
  padding: 3px;
  z-index: 50;
}

.center-round-info {
  font-size: clamp(0.85rem, 2.1vh, 1.05rem);
  font-weight: 800;
  color: #fbbf24;
  letter-spacing: 0.05em;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.8);
}

.center-honba-info {
  font-size: 0.65rem;
  color: var(--text-muted);
  display: flex;
  gap: 5px;
}

.dora-display-row {
  display: flex;
  align-items: center;
  gap: 2px;
  background: rgba(0, 0, 0, 0.5);
  padding: 1px 4px;
  border-radius: 4px;
}

.dora-label {
  font-size: 0.58rem;
  font-weight: 700;
  color: #f87171;
  margin-right: 2px;
}

.dora-tiles {
  display: flex;
  gap: 2px;
}

.dora-tiles .tile {
  width: clamp(14px, 2vw, 18px);
  aspect-ratio: 3 / 4;
}

.deck-count {
  font-size: 0.62rem;
  color: #38bdf8;
  font-weight: 600;
}

/* =========================================
   河（捨て牌エリア）4人分
   ========================================= */
.rivers-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.river {
  position: absolute;
  display: flex;
  flex-wrap: wrap;
  width: clamp(120px, 17vw, 155px);
  pointer-events: auto;
}

/* 自家（下）の河 */
.river-self {
  top: calc(50% + clamp(33px, 9dvh, 45px));
  left: 50%;
  transform: translateX(-50%);
  justify-content: flex-start;
}

/* 対面（上）の河 */
.river-top {
  bottom: calc(50% + clamp(33px, 9dvh, 45px));
  left: 50%;
  transform: translateX(-50%) rotate(180deg);
  justify-content: flex-start;
}

/* 上家（左）の河 */
.river-left {
  right: calc(50% + clamp(50px, 7.5vw, 65px));
  top: 50%;
  transform: translateY(-50%) rotate(90deg);
  justify-content: flex-start;
}

/* 下家（右）の河 */
.river-right {
  left: calc(50% + clamp(50px, 7.5vw, 65px));
  top: 50%;
  transform: translateY(-50%) rotate(-90deg);
  justify-content: flex-start;
}

/* =========================================
   プレイヤー情報ボックス
   ========================================= */
.player-box {
  position: absolute;
  background: var(--surface-dark);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 6px;
  padding: 3px 6px;
  display: flex;
  flex-direction: column;
  min-width: 68px;
  z-index: 60;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.player-box.active-turn {
  border-color: #fbbf24;
  box-shadow: 0 0 10px rgba(251, 191, 36, 0.6);
}

.player-box.riichi {
  border-color: #ef4444;
}

.player-box.player-self {
  bottom: calc(min(68px, 20dvh) + 4px);
  left: max(8px, env(safe-area-inset-left));
}

.player-box.player-top {
  top: max(38px, calc(env(safe-area-inset-top) + 32px));
  right: max(130px, 22vw);
}

.player-box.player-left {
  top: max(38px, calc(env(safe-area-inset-top) + 32px));
  left: max(8px, env(safe-area-inset-left));
}

.player-box.player-right {
  bottom: calc(min(68px, 20dvh) + 4px);
  right: max(8px, env(safe-area-inset-right));
}

.player-header-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.7rem;
}

.player-wind-badge {
  font-weight: 800;
  color: #fbbf24;
  margin-right: 3px;
}

.player-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60px;
}

.player-points {
  font-size: 0.78rem;
  font-weight: 800;
  color: #fff;
  margin-top: 1px;
}

.riichi-badge {
  display: inline-block;
  font-size: 0.55rem;
  background: #ef4444;
  color: #fff;
  padding: 1px 3px;
  border-radius: 2px;
  margin-left: 3px;
  font-weight: 700;
}

/* =========================================
   他家の手牌
   ========================================= */
.opponent-hand {
  position: absolute;
  display: flex;
  z-index: 40;
}

.opponent-hand.top-hand {
  top: max(6px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
}

.opponent-hand.left-hand {
  left: max(6px, env(safe-area-inset-left));
  top: 50%;
  transform: translateY(-50%);
  flex-direction: column;
}

.opponent-hand.right-hand {
  right: max(6px, env(safe-area-inset-right));
  top: 50%;
  transform: translateY(-50%);
  flex-direction: column;
}

/* =========================================
   自分の手牌（最下部・メインエリア）
   ========================================= */
.bottom-panel {
  grid-row: 3;
  grid-column: 1 / span 3;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  padding-bottom: max(3px, env(safe-area-inset-bottom));
  z-index: 90;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0.4) 75%, transparent 100%);
}

.my-hand-wrapper {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  width: 100%;
}

.my-hand {
  display: flex;
  align-items: flex-end;
}

.my-melds {
  display: flex;
  align-items: flex-end;
  margin-left: 8px;
}

/* =========================================
   アクションボタンバー (ポン・チー・カン・リーチ・ロン・ツモ・スキップ)
   ========================================= */
.action-bar {
  position: absolute;
  bottom: calc(min(68px, 20dvh) + 8px);
  display: flex;
  gap: clamp(6px, 1.2vw, 10px);
  z-index: 120;
}

#discard-confirm-bar {
  bottom: calc(min(68px, 20dvh) + 6px);
}

.btn-action {
  padding: clamp(6px, 1.2vh, 10px) clamp(10px, 2vw, 16px);
  font-size: clamp(0.85rem, 2.2vh, 1.05rem);
  font-weight: 800;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.6);
  transform: scale(1);
  transition: transform 0.1s ease, filter 0.1s ease;
  user-select: none;
}

.btn-action:active {
  transform: scale(0.95);
}

.btn-ron {
  background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
  color: #fff;
  border: 2px solid #fca5a5;
  animation: pulseButton 1s infinite alternate;
}

.btn-tsumo {
  background: linear-gradient(135deg, #f59e0b 0%, #b45309 100%);
  color: #fff;
  border: 2px solid #fde68a;
  animation: pulseButton 1s infinite alternate;
}

.btn-riichi {
  background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
  color: #fff;
}

.btn-pon, .btn-chi, .btn-kan {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%);
  color: #fff;
  border: 1px solid #7dd3fc;
}

.btn-pass {
  background: rgba(55, 65, 81, 0.9);
  color: #d1d5db;
  border: 1px solid #6b7280;
}

@keyframes pulseButton {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

/* =========================================
   モーダル・ダイアログ (共有、設定、リザルト)
   ========================================= */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 999;
  justify-content: center;
  align-items: center;
  padding: 16px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: #182228;
  border: 1px solid #334155;
  border-radius: 16px;
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.8);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent-gold);
  text-align: center;
}

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

.form-group label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control {
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  color: #fff;
  padding: 10px 14px;
  font-size: 0.95rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.btn-primary {
  background: linear-gradient(135deg, #15803d 0%, #166534 100%);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(22, 101, 52, 0.4);
}

.btn-secondary {
  background: #334155;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.share-url-box {
  background: #0f172a;
  border: 1px dashed #38bdf8;
  border-radius: 8px;
  padding: 10px;
  font-size: 0.85rem;
  word-break: break-all;
  user-select: all;
  text-align: center;
  color: #38bdf8;
}

.qr-code-wrapper {
  display: flex;
  justify-content: center;
  margin: 10px 0;
}

.qr-code-wrapper img {
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}
