* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "PingFang TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
  background: linear-gradient(180deg, #fff7e6 0%, #e6f7ff 100%);
  color: #2d2d2d;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh; /* Safari 的 100vh 不會扣掉動態工具列高度，改用 dvh 才不會把下方按鈕擠出可視範圍 */
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

/* ---------- Top bar ---------- */

#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  flex: 0 0 auto;
}

#progress-label {
  font-size: 1.1rem;
  font-weight: bold;
  color: #555;
}

#round-label {
  font-size: 1rem;
  color: #888;
}

#settings-btn {
  font-size: 1.8rem;
  background: none;
  border: none;
  cursor: pointer;
  line-height: 1;
  padding: 0.3rem 0.6rem;
}

/* ---------- Card area ---------- */

#card-area {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  position: relative;
  padding: 0 1rem;
}

#card {
  background: #ffffff;
  border-radius: 2rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12);
  width: min(92vw, 640px);
  max-height: 100%;
  padding: 1.5rem 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  position: relative;
}

#badge {
  position: absolute;
  top: 0.7rem;
  right: 1rem;
  background: #ffe58f;
  color: #7c5a00;
  font-size: 0.9rem;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-weight: bold;
}

#card-image {
  width: min(46vw, 260px);
  height: min(46vw, 260px);
  object-fit: contain;
}

#card-char {
  font-size: min(20vw, 8rem);
  line-height: 1;
  font-weight: bold;
  color: #262626;
}

#card-cue {
  font-size: 1.3rem;
  color: #888;
  min-height: 1.6rem;
}

/* ---------- Summary overlay ---------- */

#summary {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 2rem;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  text-align: center;
  padding: 1rem;
}

#summary.show {
  display: flex;
}

#summary h2 {
  font-size: 2rem;
  margin: 0;
}

/* ---------- Bottom controls ---------- */

#controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1rem;
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  flex-wrap: wrap;
}

.big-btn {
  font-size: 1.6rem;
  padding: 1rem 1.4rem;
  border: none;
  border-radius: 1.2rem;
  background: #40a9ff;
  color: white;
  cursor: pointer;
  min-width: 4rem;
  box-shadow: 0 4px 0 #1677c9;
  transition: transform 0.05s;
}

.big-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #1677c9;
}

.big-btn.secondary {
  background: #b0b0b0;
  box-shadow: 0 4px 0 #7a7a7a;
}

.big-btn.secondary:active {
  box-shadow: 0 1px 0 #7a7a7a;
}

#play-toggle-btn {
  background: #52c41a;
  box-shadow: 0 4px 0 #2d8a0d;
  min-width: 6rem;
}

#play-toggle-btn:active {
  box-shadow: 0 1px 0 #2d8a0d;
}

#play-toggle-btn.playing {
  background: #fa8c16;
  box-shadow: 0 4px 0 #ad5a02;
}

#play-toggle-btn.playing:active {
  box-shadow: 0 1px 0 #ad5a02;
}

/* ---------- Settings panel ---------- */

#settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10;
  padding: 1rem;
}

#settings-overlay.show {
  display: flex;
}

#settings-panel {
  background: white;
  border-radius: 1.5rem;
  padding: 1.5rem;
  width: min(92vw, 480px);
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

#settings-panel h2 {
  margin: 0 0 0.2rem;
  font-size: 1.4rem;
}

.setting-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.setting-row label {
  font-size: 1rem;
  display: flex;
  justify-content: space-between;
  color: #444;
}

.setting-row input[type="range"] {
  width: 100%;
}

.setting-row input[type="number"] {
  font-size: 1.1rem;
  padding: 0.4rem;
  width: 6rem;
  border-radius: 0.5rem;
  border: 1px solid #ccc;
}

.radio-group {
  display: flex;
  gap: 1.2rem;
  font-size: 1.05rem;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

#settings-panel .close-row {
  display: flex;
  justify-content: flex-end;
  gap: 0.8rem;
}

#stats-list {
  max-height: 40vh;
  overflow-y: auto;
  border: 1px solid #eee;
  border-radius: 0.8rem;
  padding: 0.5rem 0.8rem;
  font-size: 0.95rem;
  display: none;
}

#stats-list.show {
  display: block;
}

#stats-list div {
  display: flex;
  justify-content: space-between;
  padding: 0.15rem 0;
  border-bottom: 1px solid #f5f5f5;
}
