/* ============================
   CSS Variables & Base Styles
   ============================ */
:root {
  /* Color palette - Pastel Green Theme */
  --bg-primary: #c8e6c9;
  /* Pastel green background */
  --bg-secondary: #a5d6a7;
  /* Slightly deeper pastel green */
  --bg-card: #ffffff;
  /* Pure white for buttons/cards to stand out */
  --bg-card-hover: #f1f8e9;
  /* Extremely light green for hover */
  --surface: #ffffff;
  /* Pure white for UI surfaces */
  --surface-light: #e8f5e9;
  /* Very light green surface */

  /* Accent colors */
  --accent-primary: #4fc3f7;
  --accent-primary-hover: #81d4fa;
  --accent-secondary: #ff8a65;
  --accent-glow: rgba(79, 195, 247, 0.3);

  /* Tile colors */
  --tile-red: #ef5350;
  --tile-blue: #42a5f5;
  --tile-black: #455a64;
  --tile-orange: #ffa726;

  /* Text */
  --text-primary: #1b5e20;
  /* Dark green for clear readability on light backgrounds */
  --text-secondary: #388e3c;
  /* Medium green for secondary text */
  --text-muted: #81c784;
  /* Muted green */

  /* Misc */
  --border-subtle: rgba(27, 94, 32, 0.15);
  /* Darker border for light theme */
  --shadow-lg: 0 20px 60px rgba(27, 94, 32, 0.15);
  --shadow-md: 0 8px 30px rgba(27, 94, 32, 0.1);
  --shadow-sm: 0 2px 10px rgba(27, 94, 32, 0.05);
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 8px;
  --transition-fast: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Base */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  min-height: -webkit-fill-available;
  overflow-y: auto;
  overflow-x: hidden;
  line-height: 1.6;
}

/* ============================
   Screen System
   ============================ */
.screen {
  display: none;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
}

.screen.active {
  display: flex;
}

/* 非表示画面のアニメーションを停止（GPU負荷軽減） */
.screen:not(.active) * {
  animation-play-state: paused !important;
}

/* ============================
   Top Screen
   ============================ */
.top-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  width: 100%;
  padding: 2rem;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(79, 195, 247, 0.06) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(255, 138, 101, 0.05) 0%, transparent 50%),
    var(--bg-primary);
}

.top-hero {
  text-align: center;
  margin-bottom: 3rem;
  animation: fadeInUp 0.8s ease-out;
  color: var(--text-primary);
  text-shadow: 0 2px 4px rgba(255, 255, 255, 0.8);
}

/* Logo tiles animation */
.logo-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.logo-tiles {
  display: flex;
  gap: 6px;
  margin-bottom: 0.5rem;
}

.logo-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 60px;
  border-radius: var(--radius-sm);
  font-size: 1.5rem;
  font-weight: 900;
  color: #333;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.4) 0%, transparent 40%, rgba(0, 0, 0, 0.1) 100%),
    linear-gradient(90deg, transparent, rgba(0, 0, 0, 0.02) 2px, transparent 4px),
    #e8d5b5;
  border: 1px solid #d0ba96;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3), inset 0 2px 4px rgba(255, 255, 255, 0.8);
  animation: tileFloat 3s ease-in-out infinite;
  position: relative;
  overflow: hidden;
}

.logo-tile::after {
  content: '';
  position: absolute;
  top: 0;
  left: -50%;
  width: 200%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.15), transparent);
  animation: shimmer 4s ease-in-out infinite;
}

.logo-tile.red {
  color: #d32f2f;
  animation-delay: 0s;
}

.logo-tile.blue {
  color: #1976d2;
  animation-delay: 0.1s;
}

.logo-tile.orange {
  color: #f57c00;
  animation-delay: 0.2s;
}

.logo-tile.black {
  color: #212121;
  animation-delay: 0.3s;
}

.app-title {
  font-size: 2.2rem;
  font-weight: 900;
  letter-spacing: 0.05em;
  line-height: 1.3;
}

.title-accent {
  display: block;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent-primary);
  letter-spacing: 0.15em;
}

.app-subtitle {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-top: 0.5rem;
  letter-spacing: 0.1em;
}

/* Mode selection buttons */
.mode-selection {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
  max-width: 420px;
  animation: fadeInUp 0.8s ease-out 0.2s both;
}

.mode-btn {
  display: flex;
  align-items: center;
  gap: 1.2rem;
  width: 100%;
  padding: 1.3rem 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform var(--transition-smooth), background-color var(--transition-smooth), border-color var(--transition-smooth), box-shadow var(--transition-smooth);
  text-align: left;
  position: relative;
  overflow: hidden;
}

.mode-btn::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  border-radius: 4px 0 0 4px;
  transition: width var(--transition-fast);
}

.practice-btn::before {
  background: var(--accent-primary);
}

.reproduce-btn::before {
  background: var(--accent-secondary);
}

.build-btn::before {
  background: #66bb6a;
}

.mode-btn:hover {
  background: var(--bg-card-hover);
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateX(4px);
  box-shadow: var(--shadow-md);
}

.mode-btn:hover::before {
  width: 6px;
}

.mode-btn:active {
  transform: translateX(2px) scale(0.99);
}

.mode-btn-icon {
  font-size: 2rem;
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border-radius: var(--radius-sm);
}

.mode-btn-text {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.mode-btn-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
}

.mode-btn-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

/* Footer */
.top-footer {
  margin-top: 3rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  animation: fadeInUp 0.8s ease-out 0.4s both;
  text-align: center;
}

.top-footer a:hover {
  color: var(--accent-primary) !important;
  text-decoration: none !important;
}

/* 言語選択ボタン */
.lang-selection {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.8rem;
  justify-content: center;
}

.lang-btn {
  padding: 0.5rem 1.2rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  backdrop-filter: blur(4px);
}

.lang-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--text-primary);
}

.lang-btn.active {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 0 15px rgba(79, 195, 247, 0.3);
}

/* ============================
   Modal Overlay
   ============================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.7);
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal-overlay.active {
  display: flex;
  animation: fadeIn 0.25s ease-out;
}

.modal-dialog {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  animation: modalSlideUp 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-heading {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 1.8rem;
  color: var(--text-primary);
  letter-spacing: 0.05em;
}

.modal-body {
  margin-bottom: 2rem;
}

/* Setting row */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.2rem;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.setting-label {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  cursor: pointer;
}

.setting-name {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.setting-desc {
  font-size: 0.8rem;
  color: var(--text-secondary);
  transition: color var(--transition-fast);
}

/* Set count options */
.set-count-options {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  width: 100%;
}

.set-count-btn {
  flex: 1;
  min-width: 40px;
  padding: 0.4rem 0.6rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
  text-align: center;
}

.set-count-btn:hover {
  background: var(--surface-light);
  color: var(--text-primary);
}

.set-count-btn.active {
  background: var(--accent-primary);
  color: #fff;
  border-color: var(--accent-primary);
  box-shadow: 0 2px 8px rgba(79, 195, 247, 0.3);
}

/* Toggle switch */
.toggle-switch {
  position: relative;
  flex-shrink: 0;
}

.toggle-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  display: block;
  width: 52px;
  height: 28px;
  background: #a5d6a7;
  border-radius: 30px;
  position: relative;
  transition: background-color var(--transition-fast);
  cursor: pointer;
}

.toggle-thumb {
  display: block;
  width: 22px;
  height: 22px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: 0 2px 5px rgba(27, 94, 32, 0.2);
}

.toggle-input:checked+.toggle-track {
  background: var(--accent-primary);
  border-color: var(--accent-primary);
}

.toggle-input:checked+.toggle-track .toggle-thumb {
  transform: translateX(24px);
  background: #fff;
}

.toggle-input:focus-visible+.toggle-track {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* Modal actions */
.modal-actions {
  display: flex;
  gap: 0.8rem;
}

.btn-primary,
.btn-secondary {
  flex: 1;
  padding: 0.85rem 1.2rem;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition-fast), background-color var(--transition-fast), box-shadow var(--transition-fast);
  border: none;
  letter-spacing: 0.03em;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent-primary), #039be5);
  color: #fff;
  box-shadow: 0 4px 15px rgba(79, 195, 247, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(79, 195, 247, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
  background: var(--surface-light);
  color: var(--text-primary);
}

/* ============================
   Play Screen
   ============================ */
.build-container {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
}

.play-container {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #2a1811;
}

.play-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  z-index: 10;
}

.play-header-center {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.play-header-right {
  width: 120px;
}

.btn-back {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

.btn-back:hover {
  background: var(--surface-light);
  color: var(--text-primary);
}

.back-arrow {
  font-size: 1rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.7rem;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.badge.joker-on {
  background: rgba(255, 138, 101, 0.15);
  color: var(--accent-secondary);
  border: 1px solid rgba(255, 138, 101, 0.3);
}

.badge.joker-off {
  background: rgba(200, 230, 201, 0.5);
  color: var(--text-primary);
  border: 1px solid rgba(129, 199, 132, 0.5);
}

.stock-badge {
  background: rgba(255, 255, 255, 0.8);
  color: #2e7d32;
  border: 1px solid rgba(76, 175, 80, 0.4);
}

/* ============================
   Tiles
   ============================ */
.tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 48px;
  border-radius: 5px;
  font-size: 1.1rem;
  font-weight: 800;
  color: #333;
  cursor: grab;
  user-select: none;
  position: relative;
  flex-shrink: 0;
  background-color: #e8d5b5;
  border: 1px solid #c9bda8;
}

.tile:hover {
  z-index: 5;
}

.tile:active {
  cursor: grabbing;
}

.tile.dragging {
  opacity: 0.4;
}

/* Tile colors */
.tile.tile-red {
  color: #d32f2f;
}

.tile.tile-blue {
  color: #1976d2;
}

.tile.tile-black {
  color: #212121;
}

.tile.tile-orange {
  color: #f57c00;
}

.tile.tile-joker {
  color: #7b1fa2;
  font-size: 1.4rem;
}

/* Selected tile highlight */
.tile.selected {
  outline: 2.5px solid #fdd835;
  outline-offset: 1px;
  z-index: 5;
}

/* Selection rectangle */
.selection-rect {
  position: fixed;
  border: 2px dashed rgba(79, 195, 247, 0.7);
  background: rgba(79, 195, 247, 0.1);
  pointer-events: none;
  z-index: 9999;
  border-radius: 3px;
}

/* Drag ghost for multiple tiles */
.drag-ghost {
  position: fixed;
  top: -9999px;
  left: -9999px;
  display: flex;
  gap: 2px;
  background: rgba(15, 25, 35, 0.7);
  border-radius: 6px;
  z-index: 99999;
  pointer-events: none !important;
  will-change: transform;
}

.ghost-tile {
  box-shadow: none !important;
  transition: none !important;
  transform: none !important;
  opacity: 0.9 !important;
}

/* ============================
   Field Area
   ============================ */
.field-area {
  flex: 1;
  padding: 0.8rem;
  overflow-y: scroll;
  min-height: 0;
}

.field-sets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-start;
}

.field-set {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0.35rem 0.5rem;
  background: var(--surface);
  border: 2px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  min-height: 52px;
}

.field-set.drag-over {
  background: rgba(79, 195, 247, 0.12);
  border-color: var(--accent-primary);
  transition: none !important;
}

/* 不成立セットのスタイル */
.field-set.invalid {
  border-color: rgba(239, 83, 80, 0.6);
  background: rgba(239, 83, 80, 0.08);
}

.field-set.invalid .field-set-label {
  color: var(--tile-red);
}

.field-set-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-right: 3px;
  letter-spacing: 0.05em;
  flex-shrink: 0;
  line-height: 1;
  opacity: 0.8;
}

.field-set-type {
  font-size: 0.6rem;
  color: var(--text-muted);
  margin-left: 5px;
  flex-shrink: 0;
  opacity: 0.6;
}

.field-set.invalid .field-set-type {
  color: var(--tile-red);
  opacity: 1;
}

/* Tile drawn highlight - border-color only (no box-shadow for GPU safety) */
.tile.just-drawn {
  border-color: rgba(253, 216, 53, 0.7) !important;
  outline: 2px solid rgba(253, 216, 53, 0.5);
  outline-offset: 1px;
}

/* Dynamic tile sizes based on field density */
.play-container.compact-tiles .tile,
.drag-ghost.compact-tiles .tile {
  width: 30px;
  height: 40px;
  font-size: 0.85rem;
  border-radius: 4px;
}

.play-container.compact-tiles .field-set {
  gap: 2px;
  padding: 0.25rem 0.4rem;
  min-height: 44px;
}

.play-container.compact-tiles .hand-area {
  min-height: 50px;
  gap: 3px;
}

.play-container.tiny-tiles .tile,
.drag-ghost.tiny-tiles .tile {
  width: 26px;
  height: 34px;
  font-size: 0.75rem;
  border-radius: 3px;
}

.play-container.tiny-tiles .field-set {
  gap: 1px;
  padding: 0.2rem 0.3rem;
  min-height: 38px;
}

.play-container.tiny-tiles .hand-area {
  min-height: 42px;
  gap: 2px;
}

/* ============================
   Action Bar
   ============================ */
.action-bar {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}

.action-bar-primary {
  display: flex;
  justify-content: center;
  gap: 0.6rem;
}

.action-bar-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.65rem;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast), color var(--transition-fast), opacity var(--transition-fast);
  white-space: nowrap;
  box-shadow: 0 2px 4px rgba(27, 94, 32, 0.1);
}

.action-btn:hover:not(:disabled) {
  background: var(--surface-light);
  color: var(--text-primary);
  transform: translateY(-1px);
}

.action-btn:active:not(:disabled) {
  transform: translateY(0);
}

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

/* Primary draw buttons - larger and more prominent */
.primary-draw {
  padding: 0.55rem 1.5rem;
  font-size: 0.9rem;
  font-weight: 700;
  background: linear-gradient(135deg, #4caf50, #388e3c);
  border: none;
  border-radius: var(--radius-md);
  color: #ffffff;
  box-shadow: 0 4px 10px rgba(56, 142, 60, 0.4);
}

.primary-draw:hover:not(:disabled) {
  background: linear-gradient(135deg, #66bb6a, #43a047);
  box-shadow: 0 6px 14px rgba(56, 142, 60, 0.5);
  transform: translateY(-2px);
  color: #ffffff;
}

.primary-draw .action-icon {
  font-size: 1.1rem;
}

/* Tile size controls */
.tile-size-controls {
  display: flex;
  gap: 0.2rem;
}

.size-btn {
  padding: 0.35rem 0.5rem;
  font-size: 0.7rem;
}

.action-icon {
  font-size: 0.9rem;
}

.action-text {
  line-height: 1;
}

/* Specific action button styles */
.draw-btn:hover:not(:disabled) {
  border-color: rgba(76, 175, 80, 0.4);
  color: #66bb6a;
}

.reset-btn:hover:not(:disabled) {
  border-color: rgba(255, 167, 38, 0.4);
  color: var(--accent-secondary);
}

.undo-btn:hover:not(:disabled) {
  border-color: rgba(144, 164, 174, 0.4);
}

.ai-btn:hover:not(:disabled) {
  border-color: rgba(79, 195, 247, 0.4);
  color: var(--accent-primary);
}

.ai-answer-btn:hover:not(:disabled) {
  border-color: rgba(255, 235, 59, 0.4);
  color: #fdd835;
}

.save-btn:hover:not(:disabled) {
  border-color: rgba(171, 71, 188, 0.4);
  color: #ba68c8;
}

/* Disabled buttons */
.action-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(0.5);
}

.sort-field-btn:hover:not(:disabled) {
  border-color: rgba(79, 195, 247, 0.4);
  color: var(--accent-primary);
}

.convert-mode-btn.active {
  background: rgba(255, 152, 0, 0.15) !important;
  border-color: #ff9800 !important;
  color: #f57c00 !important;
  box-shadow: 0 0 8px rgba(255, 152, 0, 0.3);
}

.convert-mode-btn:hover:not(:disabled) {
  border-color: rgba(255, 152, 0, 0.4);
  color: #ff9800;
}

/* 組み換えモード中のホバー効果 */
body.convert-mode-active .field-set {
  cursor: pointer;
}

body.convert-mode-active .field-set:hover {
  background: rgba(255, 152, 0, 0.12) !important;
  border-color: #ff9800 !important;
  transition: all var(--transition-fast);
}

/* ============================

   Hand Section
   ============================ */
.hand-section {
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.5);
  border-top: 1px solid var(--border-subtle);
  /* box-shadow Removed: 巨大なエリアへの常駐影はGPU VRAM・TDRクラッシュの原因になるため削除 */
  padding: 0.8rem 1rem 1.2rem;
  width: 100%;
}

.hand-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.hand-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.03em;
}

.hand-label span {
  color: #1565c0;
  /* Darker blue for contrast */
  font-weight: 800;
}

.sort-buttons {
  display: flex;
  gap: 0.4rem;
}

.sort-btn {
  padding: 0.36rem 0.85rem;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
  box-shadow: 0 1px 3px rgba(27, 94, 32, 0.1);
}

.sort-btn:hover {
  background: var(--surface-light);
  color: var(--text-primary);
  border-color: rgba(46, 125, 50, 0.3);
}

.sort-btn:active {
  transform: scale(0.96);
}

.hand-area {
  display: flex;
  align-items: flex-end;
  gap: 5px;
  min-height: 66px;
  padding: 0.4rem 0.6rem;
  background: linear-gradient(180deg, #442410, #5c351b);
  border-top: 3px solid #3c200c;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  /* box-shadow Removed: GPU TDR・白飛びクラッシュの最大要因である巨大なぼかし影を完全廃止 */
  border-radius: 4px;
  overflow-x: auto;
}

.hand-area.drag-over {
  background: rgba(79, 195, 247, 0.06);
  border-color: var(--accent-primary);
  /* GPU TDR Fixed: drag-over時のアニメーション補完（再描画の連鎖）を防止 */
  transition: none !important;
}

.hand-area::-webkit-scrollbar {
  height: 4px;
}

.hand-area::-webkit-scrollbar-track {
  background: transparent;
}

.hand-area::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 2px;
}

/* ============================
   AI Answer Banner
   ============================ */
.ai-answer-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: linear-gradient(135deg, rgba(253, 216, 53, 0.15), rgba(255, 167, 38, 0.1));
  border-bottom: 2px solid rgba(253, 216, 53, 0.4);
  flex-shrink: 0;
}

.ai-banner-text {
  font-size: 0.9rem;
  font-weight: 700;
  color: #fdd835;
}

.ai-revert-btn {
  padding: 0.3rem 0.8rem;
  font-size: 0.78rem;
}

/* AI highlight on tiles */
/* AI highlight on tiles - static outline only (no box-shadow animation for GPU safety) */
.tile.ai-moved {
  border-color: rgba(253, 216, 53, 0.8) !important;
  outline: 2.5px solid rgba(253, 216, 53, 0.6);
  outline-offset: 1px;
  position: relative;
}

/* ============================
   Boards List Modal
   ============================ */
.boards-dialog {
  max-width: 440px;
  width: 90%;
}

.boards-list {
  max-height: 300px;
  overflow-y: scroll;
  margin: 0.8rem 0;
}

.board-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  margin-bottom: 0.4rem;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.board-item:hover {
  border-color: var(--accent-primary);
  background: var(--surface-light);
}

.board-item-info {
  flex: 1;
}

.board-item-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.85rem;
}

.board-item-date {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.board-item-actions {
  display: flex;
  gap: 0.3rem;
}

.board-load-btn,
.board-delete-btn {
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}

.board-load-btn:hover {
  border-color: #66bb6a;
  color: #81c784;
}

.board-delete-btn:hover {
  border-color: #ef5350;
  color: #ef5350;
}

.boards-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 0;
  font-size: 0.85rem;
}

/* ============================
   Notify Modal
   ============================ */
.notify-dialog {
  text-align: center;
  max-width: 340px;
}

.notify-icon {
  font-size: 2.5rem;
  margin-bottom: 0.8rem;
}

.notify-message {
  font-size: 0.95rem;
  color: var(--text-primary);
  margin-bottom: 1.5rem;
  line-height: 1.6;
}

.notify-close-btn {
  min-width: 120px;
}

.notify-dialog.error .notify-icon {
  color: var(--tile-red);
}

.notify-dialog.success .notify-icon {
  color: #66bb6a;
}

/* ============================
   Clear Modal
   ============================ */
.clear-dialog {
  text-align: center;
  max-width: 380px;
  position: relative;
}

.clear-stars {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  animation: clearBounce 0.6s ease-out;
}

.clear-title {
  font-size: 2rem;
  font-weight: 900;
  color: #fdd835;
  margin-bottom: 0.6rem;
  letter-spacing: 0.1em;
  text-shadow: 0 2px 10px rgba(253, 216, 53, 0.3);
}

.clear-message {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  line-height: 1.7;
}

.clear-actions {
  display: flex;
  gap: 0.8rem;
}

@keyframes clearBounce {
  0% {
    transform: scale(0.3);
    opacity: 0;
  }

  50% {
    transform: scale(1.15);
  }

  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ============================
   Animations
   ============================ */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(30px) scale(0.95);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes tileFloat {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-6px);
  }
}

@keyframes shimmer {

  0%,
  100% {
    transform: translateX(-100%);
  }

  50% {
    transform: translateX(100%);
  }
}

/* ============================
   Loading Overlay
   ============================ */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(10, 15, 30, 0.85);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  color: var(--text-primary);
}

.spinner {
  width: 60px;
  height: 60px;
  border: 6px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent-blue);
  border-right-color: var(--accent-orange);
  border-bottom-color: var(--accent-red);
  border-left-color: var(--accent-black);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 20px;
}

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

.loading-text {
  font-size: 1.2rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.5;
  color: #ffffff;
  /* Must be explicitly white due to dark overlay */
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
}

/* ============================
   Responsive Design
   ============================ */
@media (max-width: 480px) {
  .top-container {
    padding: 1.5rem 1rem;
  }

  .logo-tile {
    width: 38px;
    height: 48px;
    font-size: 1.2rem;
  }

  .app-title {
    font-size: 1.7rem;
  }

  .title-accent {
    font-size: 1.1rem;
  }

  .mode-btn {
    padding: 1rem 1.2rem;
    gap: 1rem;
  }

  .mode-btn-icon {
    width: 44px;
    height: 44px;
    font-size: 1.6rem;
  }

  .mode-btn-title {
    font-size: 1rem;
  }

  .modal-dialog {
    padding: 1.5rem;
  }

  /* Play screen mobile */
  .tile {
    width: 36px;
    height: 48px;
    font-size: 1rem;
    border-radius: 5px;
  }

  .action-bar {
    gap: 0.3rem;
    padding: 0.5rem 0.5rem;
  }

  .action-btn {
    padding: 0.35rem 0.5rem;
    font-size: 0.7rem;
  }

  .action-text {
    display: none;
  }

  .action-icon {
    font-size: 1.1rem;
  }

  .field-area {
    padding: 0.6rem;
  }

  .hand-section {
    padding: 0.4rem 0.5rem 0.6rem;
  }

  .field-set {
    padding: 0.4rem;
    gap: 3px;
    min-height: 58px;
  }
}

@media (min-width: 768px) {
  .mode-selection {
    flex-direction: row;
    max-width: 680px;
  }

  .mode-btn {
    flex: 1;
    flex-direction: column;
    text-align: center;
    padding: 1.8rem 1.5rem;
  }

  .mode-btn::before {
    width: 100%;
    height: 4px;
    border-radius: 4px 4px 0 0;
  }

  .mode-btn:hover {
    transform: translateY(-4px);
  }

  .mode-btn:hover::before {
    width: 100%;
    height: 6px;
  }

  .mode-btn:active {
    transform: translateY(-2px) scale(0.99);
  }

  .mode-btn-icon {
    width: 64px;
    height: 64px;
    font-size: 2.2rem;
  }

  .mode-btn-text {
    align-items: center;
  }

  .app-title {
    font-size: 2.6rem;
  }

  .title-accent {
    font-size: 1.6rem;
  }

  /* Play screen tablet+ */
  .tile {
    width: 46px;
    height: 60px;
    font-size: 1.25rem;
  }

  .field-area {
    padding: 1.2rem 1.5rem;
  }

  .hand-area {
    gap: 6px;
  }
}

@media (min-width: 1024px) {
  .logo-tile {
    width: 56px;
    height: 70px;
    font-size: 1.8rem;
  }

  .logo-tiles {
    gap: 8px;
  }

  .tile {
    width: 48px;
    height: 64px;
    font-size: 1.3rem;
  }

  .field-set {
    gap: 5px;
    padding: 0.6rem 0.8rem;
  }
}

/* ============================
   Build Mode - Layout
   ============================ */
.build-badge {
  background: rgba(255, 255, 255, 0.8);
  color: #2e7d32;
  border: 1px solid rgba(76, 175, 80, 0.4);
}

.build-container {
  display: grid !important;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

.build-container>.play-header {
  grid-column: 1 / -1;
}

.build-container>.tile-palette {
  grid-column: 1;
  grid-row: 2;
}

.build-container>.build-right-area {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

/* ============================
   Build Mode - Tile Palette
   ============================ */
.tile-palette {
  padding: 0.5rem 0.6rem;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  flex-shrink: 0;
  overflow-y: scroll;
  overflow-x: hidden;
  max-height: calc(100vh - 50px);
}

.palette-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.08em;
  margin-bottom: 0.3rem;
  text-transform: uppercase;
}

.palette-grid {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.palette-color-group {
  display: flex;
  flex-direction: column;
  gap: 0px;
}

.palette-color-label {
  font-size: 0.55rem;
  font-weight: 800;
  color: var(--text-secondary);
  padding: 0 2px;
  margin-bottom: 0px;
  margin-top: 2px;
  letter-spacing: 0.05em;
}

.palette-row {
  display: flex;
  gap: 1px;
  flex-wrap: nowrap;
}

.palette-tile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 32px;
  border-radius: 3px;
  font-size: 0.7rem;
  font-weight: 800;
  color: #333;
  cursor: grab;
  user-select: none;
  position: relative;
  background-color: #e8d5b5;
  border: 1px solid #c9bda8;
  flex-shrink: 0;
}

.palette-tile:hover:not(.used) {
  transform: translateY(-1px);
  z-index: 2;
}

.palette-tile:active:not(.used) {
  transform: translateY(0);
}

.palette-tile.used {
  opacity: 0.2;
  pointer-events: none;
  filter: grayscale(0.6);
}

.palette-tile.selected {
  outline: 2px solid #fdd835;
  outline-offset: -1px;
  z-index: 3;
}

.palette-tile.tile-red {
  color: #d32f2f;
}

.palette-tile.tile-blue {
  color: #1976d2;
}

.palette-tile.tile-black {
  color: #212121;
}

.palette-tile.tile-orange {
  color: #f57c00;
}

.palette-tile.tile-joker {
  color: #7b1fa2;
  font-size: 0.9rem;
}

/* ============================
   Build Mode - Action Bar
   ============================ */
.build-action-bar {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.build-actions-left {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.build-load-btn:hover:not(:disabled) {
  border-color: rgba(76, 175, 80, 0.4);
  color: #66bb6a;
}

.redo-btn:hover:not(:disabled) {
  border-color: rgba(144, 164, 174, 0.4);
}

/* ============================
   Build Mode - Trash Button (Circle)
   ============================ */
.build-trash-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  background: linear-gradient(145deg, rgba(239, 83, 80, 0.15), rgba(198, 40, 40, 0.1));
  border: 2px solid rgba(239, 83, 80, 0.3);
  color: #ef5350;
  cursor: default;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  position: relative;
}

.build-trash-btn.drag-over,
.trash-btn.drag-over {
  background: linear-gradient(145deg, rgba(239, 83, 80, 0.4), rgba(198, 40, 40, 0.3));
  border-color: #ef5350;
}

.trash-btn {
  /* Transition and base styling setup to allow smooth scaling */
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--radius-sm);
}

@keyframes trashPulse {

  0%,
  100% {
    box-shadow: 0 0 10px rgba(239, 83, 80, 0.3);
  }

  50% {
    box-shadow: 0 0 20px rgba(239, 83, 80, 0.6);
  }
}

/* ============================
   Build Mode - Same-Set Timer Indicator
   ============================ */
/* Build mode accepting-tile indicator - static style only (no box-shadow animation for GPU safety) */
.field-set.accepting-tile {
  border-color: rgba(102, 187, 106, 0.9) !important;
  outline: 2px solid rgba(102, 187, 106, 0.4);
  outline-offset: 1px;
}

.field-set-label .accept-icon {
  margin-left: 3px;
  font-size: 0.6rem;
}

/* ============================
   Build Mode - Responsive
   ============================ */
@media (max-width: 600px) {
  .build-container {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
  }

  .build-container>.tile-palette {
    grid-column: 1;
    grid-row: 2;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    max-height: 35vh;
    overflow-y: auto;
  }

  .build-container>.build-right-area {
    grid-column: 1;
    grid-row: 3;
  }

  .palette-tile {
    width: 22px;
    height: 26px;
    font-size: 0.55rem;
    border-radius: 2px;
  }

  .palette-tile.tile-joker {
    font-size: 0.7rem;
  }

  .tile-palette {
    padding: 0.3rem 0.4rem;
  }

  .build-trash-btn {
    width: 44px;
    height: 44px;
    font-size: 1.1rem;
  }
}

@media (min-width: 768px) {
  .palette-tile {
    width: 32px;
    height: 38px;
    font-size: 0.8rem;
  }

  .palette-tile.tile-joker {
    font-size: 1rem;
  }
}