:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --bg: #f3f4f6;
  --card-bg: #ffffff;
  --text: #1f2937;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: linear-gradient(135deg, #fdf2f8 0%, #ede9fe 50%, #e0f2fe 100%);
  background-attachment: fixed;
  color: var(--text);
  margin: 0;
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 100vh;
  box-sizing: border-box;
}

.container {
  max-width: 640px;
  width: 100%;
  background: var(--card-bg);
  padding: 24px 20px;
  border-radius: 20px;
  box-shadow: 0 10px 30px -8px rgba(79, 70, 229, 0.18);
  box-sizing: border-box;
}

.top-row {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.btn {
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: white;
  border: none;
  padding: 13px 24px;
  font-size: 1rem;
  font-weight: bold;
  border-radius: 12px;
  cursor: pointer;
  width: 100%;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease,
    background 0.15s ease;
  box-shadow: 0 4px 12px -2px rgba(79, 70, 229, 0.4);
}

.btn:hover {
  background: linear-gradient(135deg, var(--primary-hover), #6d28d9);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px -2px rgba(79, 70, 229, 0.5);
}

.cards-container {
  display: flex;
  gap: 15px;
  margin-top: 20px;
  overflow-x: auto;
  padding-bottom: 10px;
  -webkit-overflow-scrolling: touch;
}

.card-option {
  border: 2px solid #e5e7eb;
  border-radius: 14px;
  padding: 12px;
  cursor: pointer;
  background: #fff;
  transition:
    border-color 0.2s,
    transform 0.1s;
  flex: 0 0 240px;
}

.card-option:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.card-option .cell {
  font-size: 0.85rem;
  font-weight: bold;
}

.bingo-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 20px 0;
}

.cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f9fafb;
  border: 2px solid #d1d5db;
  border-radius: 12px;
  font-size: 1.3rem;
  font-weight: bold;
  transition: transform 0.15s ease;
}

.cell.opened {
  background-color: #fef08a;
  border-color: #eab308;
  color: #854d0e;
}

.cell.bingo {
  background-color: #4ade80;
  border-color: #16a34a;
  color: #14532d;
}

.cell.selectable-target {
  border-color: #f59e0b !important;
  background-color: #fef3c7 !important;
  animation: pulse-border 0.8s infinite alternate;
  cursor: pointer;
}

.cell.candidate-1 {
  border: 2px solid #f97316 !important;
  background-color: #fff7ed !important;
  box-shadow: 0 0 8px rgba(249, 115, 22, 0.5);
  animation: pulse-candidate-1 1s infinite alternate;
}

.cell.candidate-2 {
  border: 2px solid #3b82f6 !important;
  background-color: #eff6ff !important;
  box-shadow: 0 0 6px rgba(59, 130, 246, 0.3);
}

.cell.candidate-3 {
  border: 2px dashed #06b6d4 !important;
  background-color: #ecfeff !important;
}

.cell-condition {
  font-size: 0.62rem !important;
  font-weight: bold;
  line-height: 1.15;
  padding: 4px;
  text-align: center;
  white-space: normal;
  word-break: break-word;
  overflow-wrap: break-word;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
  background-color: #fdf4ff !important;
  border-color: #c026d3 !important;
  color: #701a75 !important;
}

.cell-condition.opened {
  background-color: #f5d0fe !important;
  border-color: #a21caf !important;
  color: #581c87 !important;
}

.cell-condition-tappable {
  cursor: pointer;
  animation: pulse-condition 1s infinite alternate;
}

.input-section {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.score-input {
  flex: 1;
  padding: 10px;
  font-size: 1.1rem;
  border: 2px solid #d1d5db;
  border-radius: 8px;
  text-align: center;
}

.status-panel {
  background-color: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 15px;
  text-align: center;
}

.hidden {
  display: none !important;
}

.message {
  font-size: 1.2rem;
  font-weight: bold;
  text-align: center;
  margin: 15px 0;
}

.msg-clear {
  color: #16a34a;
}

.msg-over {
  color: #dc2626;
}

.msg-reach {
  color: #d97706;
}

.start-visual {
  display: none;
}

.placeholder-grid {
  opacity: 0.7;
}

.placeholder-cell {
  background-color: #f3f4f6;
  border: 2px dashed #d1d5db;
  color: #9ca3af;
  font-weight: 400;
}

.placeholder-caption {
  text-align: center;
  color: #9ca3af;
  font-size: 0.9rem;
  margin-top: 4px;
}

.mode-selector {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}

.mode-btn {
  flex: 1;
  padding: 10px;
  border: 2px solid #d1d5db;
  border-radius: 12px;
  background: #fff;
  color: #374151;
  font-weight: bold;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-btn.active {
  border-color: var(--primary);
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  color: white;
  box-shadow: 0 3px 10px -2px rgba(79, 70, 229, 0.4);
}

#screen-start,
#screen-game {
  margin-top: 24px;
}

.right-column {
  display: flex;
  flex-direction: column;
  gap: 8px !important;
  width: 100%;
}

.rules-container {
  margin: 0 !important;
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  text-align: left;
  overflow: hidden;
  transition: all 0.2s ease;
  box-sizing: border-box;
}

.rules-summary {
  height: 40px !important;
  padding: 0 12px !important;
  font-size: 13.5px !important;
  font-weight: 700;
  color: #334155;
  cursor: pointer;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  list-style: none !important;
  user-select: none;
  line-height: 1 !important;
  box-sizing: border-box !important;
  margin: 0 !important;
}

.rules-summary::-webkit-details-marker {
  display: none !important;
}

.rules-summary > span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.rules-icon {
  font-size: 11px;
  color: #64748b;
  transition: transform 0.2s ease;
  line-height: 1;
}

.rules-container[open] .rules-summary {
  border-bottom: 1px solid #e2e8f0;
  background-color: #f1f5f9;
}

.rules-container[open] .rules-icon {
  transform: rotate(180deg);
}

.rules-list {
  list-style: none;
  padding: 16px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.rules-list li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  color: #475569;
  line-height: 1.4;
}

.rule-num {
  background-color: #4f46e5;
  color: #ffffff;
  font-size: 11px;
  font-weight: 700;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.reset-btn {
  background: none;
  border: none;
  color: #ef4444;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.share-area {
  margin-bottom: 15px;
  text-align: center;
}

.btn-share {
  background-color: #10b981;
  color: white;
  border: none;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: bold;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: auto;
}

.btn-share:hover {
  background-color: #059669;
}

.sync-badge {
  display: inline-block;
  font-size: 0.75rem;
  background-color: #d1fae5;
  color: #065f46;
  padding: 2px 8px;
  border-radius: 12px;
  margin-bottom: 8px;
}

.app-footer {
  margin-top: 32px;
  padding-top: 16px;
  border-top: 1px solid #e2e8f0;
  text-align: center;
}

.app-footer p {
  margin: 0;
  font-size: 0.8rem;
  color: #94a3b8;
  font-weight: 500;
  letter-spacing: 0.5px;
}

body.secret-playing .secret-banner {
  display: block;
}

body.secret-playing #reach-indicator {
  display: none !important;
}

#bingo-board.secret-hidden .cell:not(.opened) {
  position: relative !important;
  color: transparent !important;
  background-color: #1e1b4b !important;
  border-color: #4338ca !important;
  box-shadow: none !important;
  animation: none !important;
}

#bingo-board.secret-hidden .cell:not(.opened)::after {
  content: '🔒';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.2rem;
  color: #a5b4fc;
}

#bingo-board.secret-hidden .cell.candidate-1:not(.opened),
#bingo-board.secret-hidden .cell.candidate-2:not(.opened),
#bingo-board.secret-hidden .cell.candidate-3:not(.opened) {
  border-color: #4338ca !important;
  background-color: #1e1b4b !important;
  box-shadow: none !important;
  animation: none !important;
}

#bingo-board.secret-hidden .cell.selectable-target:not(.opened) {
  color: transparent !important;
  border: 3px solid #f59e0b !important;
  background-color: #312e81 !important;
  animation: pulse-border 0.8s infinite alternate !important;
  cursor: pointer !important;
}

#bingo-board.secret-hidden .cell.selectable-target::after {
  content: '🔒' !important;
  position: absolute !important;
  top: 50% !important;
  left: 50% !important;
  transform: translate(-50%, -50%) !important;
  font-size: 1.3rem !important;
}

.cube-viewport {
  perspective: 1000px;
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 44px 0 64px;
}

.cube-board {
  position: relative;
  width: 220px;
  height: 220px;
  transform-style: preserve-3d;
  transform: rotateX(-18deg) rotateY(-28deg);
  transition: transform 0.5s ease;
}

.cube-layer {
  position: absolute;
  top: 0;
  left: 0;
  width: 220px;
}

.cube-layer[data-layer='0'] {
  transform: translateZ(92px);
}

.cube-layer[data-layer='1'] {
  transform: translateZ(0px);
}

.cube-layer[data-layer='2'] {
  transform: translateZ(-92px);
}

.cube-layer-label {
  font-size: 0.7rem;
  font-weight: bold;
  color: #6b7280;
  text-align: center;
  margin-bottom: 4px;
}

.cube-layer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 6px;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.15);
}

.cube-layer-grid .cell {
  font-size: 0.95rem;
}

.cube-rotate-btn {
  display: block;
  margin: 0 auto;
  max-width: 220px;
  font-size: 0.85rem;
  padding: 8px 16px;
}

#recent-games-container {
  display: grid !important;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

#recent-games-container .history-card {
  margin-bottom: 0 !important;
  padding: 8px !important;
  border-radius: 10px !important;
  min-width: 0;
  transition:
    transform 0.15s ease,
    box-shadow 0.15s ease;
}

#recent-games-container .history-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px -2px rgba(0, 0, 0, 0.12);
}

#recent-games-container .history-card img {
  border-radius: 6px !important;
}

#recent-games-container .history-card strong {
  font-size: 0.8rem !important;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#recent-games-container .history-card p {
  font-size: 0.7rem !important;
  margin: 3px 0 !important;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

#recent-games-container .history-card span {
  font-size: 0.65rem !important;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@keyframes pulse-border {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(245, 158, 11, 0);
  }
  100% {
    transform: scale(1.03);
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.6);
  }
}

@keyframes pulse-candidate-1 {
  0% {
    transform: scale(1);
    box-shadow: 0 0 4px rgba(249, 115, 22, 0.4);
  }
  100% {
    transform: scale(1.03);
    box-shadow: 0 0 10px rgba(249, 115, 22, 0.8);
  }
}

@keyframes pulse-condition {
  0% {
    box-shadow: 0 0 4px rgba(192, 38, 211, 0.3);
  }
  100% {
    box-shadow: 0 0 10px rgba(192, 38, 211, 0.7);
  }
}

@media (min-width: 480px) {
  .top-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 16px;
    align-items: start;
  }

  .app-header {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    width: 100%;
  }

  .right-column {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    width: 100%;
  }

  .header-logo-svg {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
  }
}

@media (min-width: 600px) {
  #recent-games-container {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 768px) {
  .cards-container {
    overflow-x: visible;
  }
  .card-option {
    flex: 1;
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: 1200px;
  }
  .header-logo-svg {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    margin: 0 auto;
  }
  #screen-start {
    display: grid;
    grid-template-columns: 1fr 360px;
    column-gap: 32px;
    align-items: start;
  }
  .start-visual {
    display: block;
  }
  #screen-game {
    display: grid;
    grid-template-columns: 1fr 320px;
    grid-template-areas:
      'board side-top'
      'board side-bottom';
    column-gap: 32px;
    row-gap: 16px;
    align-items: start;
  }
  .game-side-top {
    grid-area: side-top;
  }
  .game-side-bottom {
    grid-area: side-bottom;
  }
  .game-main {
    grid-area: board;
  }
  .game-main .bingo-grid {
    max-width: 760px;
    margin: 0 auto;
  }
  #custom-bingo-input-grid {
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
  }
  #recent-games-container {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 380px) {
  #recent-games-container {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  #recent-games-container .history-card {
    padding: 6px !important;
  }
}
