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

html, body {
  height: 100%;
  overflow: hidden;
  touch-action: manipulation;
}

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #fff;
  color: #333;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
}

.stats-header {
  flex-shrink: 0;
  padding: 8px 12px;
  font-size: 14px;
  background: #f5f5f5;
  border-bottom: 1px solid #ddd;
}

.mode-selector {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
}

.mode-btn {
  flex: 1;
  padding: 6px 8px;
  font-size: 13px;
  border: 1px solid #999;
  border-radius: 6px;
  background: #fff;
  touch-action: manipulation;
}

.mode-btn.active {
  background: #2c3e50;
  color: #fff;
  border-color: #2c3e50;
}

.mode-btn:not(.active):active {
  background: #e8e8e8;
}

.overall-stats .stats-rate {
  color: #666;
  margin-left: 4px;
}

.quiz-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 8px;
}

#quizCanvas {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: auto;
  aspect-ratio: 1;
  display: block;
}

.result-area {
  flex-shrink: 0;
  min-height: 48px;
  padding: 12px 16px;
  font-size: 20px;
  font-weight: bold;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-top: 1px solid #e0e0e0;
}

.result-area.correct {
  color: #2e7d32;
  background: #e8f5e9;
}

.result-area.wrong {
  color: #c62828;
  background: #ffebee;
}

.answer-area {
  flex-shrink: 0;
  padding: 12px 8px 8px;
  background: #f5f5f5;
  border-top: 1px solid #ddd;
}

.answer-buttons {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}

.answer-buttons button {
  min-height: 44px;
  font-size: 16px;
  font-weight: bold;
  border: 1px solid #999;
  border-radius: 6px;
  background: #fff;
  color: #333;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.answer-buttons button:active {
  background: #e0e0e0;
}

.answer-buttons button:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.stats-btn {
  width: 100%;
  min-height: 44px;
  font-size: 16px;
  border: 1px solid #999;
  border-radius: 6px;
  background: #e8e8e8;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.stats-btn:active {
  background: #d0d0d0;
}

/* Stats overlay */
.stats-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  align-items: flex-end;
  z-index: 100;
}

.stats-overlay.visible {
  display: flex;
}

.stats-panel {
  width: 100%;
  max-height: 60vh;
  background: #fff;
  border-radius: 12px 12px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.stats-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #ddd;
}

.stats-panel-header h2 {
  font-size: 18px;
}

.stats-close {
  width: 40px;
  height: 40px;
  font-size: 24px;
  line-height: 1;
  border: none;
  background: transparent;
  color: #666;
  touch-action: manipulation;
}

.stats-panel-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.stats-overall {
  margin-bottom: 20px;
}

.stats-overall h3,
.stats-pieces h3 {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.stats-overall p,
.piece-stats-list p {
  font-size: 16px;
  line-height: 1.6;
}

.piece-stats-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.piece-stats-list .piece-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 8px 12px;
  background: #f9f9f9;
  border-radius: 6px;
  font-size: 15px;
}

.piece-stats-list .piece-name {
  font-weight: bold;
  min-width: 2em;
}

.piece-stats-list .piece-detail {
  color: #666;
  font-size: 14px;
}
