:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --green: #4ade80;
  --green2: #22c55e;
  --text: #1a1a1a;
  --text-muted: rgba(0, 0, 0, 0.45);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; overflow-x: hidden; }

body {
  min-height: 100vh;
  background: #f2f2f7;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;
}

.container { width: 100%; max-width: 520px; margin: 0 auto; padding: 24px 14px 40px; }

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  gap: 12px;
}

.title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 32px;
  font-weight: 900;
  letter-spacing: -1px;
  color: var(--text);
  line-height: 1.1;
  flex: 1;
  text-align: center;
}
.title span { color: var(--green2); }

/* ปุ่ม + มุมขวาบน (ซ่อนไว้ก่อน) */
.upload-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: #3a3a3c;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform .2s ease, background .2s ease;
  -webkit-tap-highlight-color: transparent;
}
.upload-btn:active { transform: scale(.9); background: #2a2a2c; }
.upload-btn svg {
  width: 22px;
  height: 22px;
  color: #fff;
  stroke-width: 2.5;
}

/* ===== Upload Card (หน้าแรก) ===== */
.upload-card {
  width: 100%;
  padding: 40px 20px;
  border-radius: 24px;
  border: none;
  background: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  cursor: pointer;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  transition: .25s ease;
}
.upload-card:active { transform: scale(.98); }
.upload-icon-wrap { width: 52px; height: 52px; border-radius: 50%; background: #3a3a3c; display: flex; align-items: center; justify-content: center; }
.upload-icon-wrap svg { width: 26px; height: 26px; color: #fff; stroke-width: 2.5; }
.upload-label { font-size: 16px; font-weight: 600; color: #3a3a3c; }

/* ===== Stats ===== */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }
.stat-card { background: #fff; border-radius: 20px; padding: 16px; box-shadow: 0 2px 12px rgba(0,0,0,0.06); }
.stat-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.stat-label { font-size: 13px; font-weight: 500; color: var(--text-muted); line-height: 1.4; }
.stat-icon { width: 32px; height: 32px; border-radius: 50%; border: 2px solid var(--green2); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.stat-icon svg { width: 16px; height: 16px; color: var(--green2); stroke-width: 2.5; }
.stat-value { margin-top: 10px; font-size: 36px; font-weight: 900; color: #1a1a1a; }

/* ===== Entries ===== */
.entries { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; }
.entry-row {
  display: flex; align-items: center; justify-content: space-between; padding: 16px 18px;
  background: #fff; border: 1px solid rgba(0,0,0,0.06); border-radius: 16px;
  cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,0.04); transition: .2s ease;
}
.entry-row:active { transform: scale(.99); }
.entry-row.selected { border-color: rgba(74,222,128,0.3); }
.entry-price { font-size: 18px; font-weight: 700; color: rgba(0,0,0,0.3); transition: color .2s ease; }
.entry-price.selected { color: #1a1a1a; }

/* ===== Toggle ===== */
.toggle { position: relative; width: 51px; height: 31px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track { position: absolute; inset: 0; border-radius: 999px; background: rgba(0,0,0,0.15); transition: background .25s ease; }
.toggle input:checked + .toggle-track { background: #4ade80; }
.toggle-thumb { position: absolute; top: 3px; left: 3px; width: 25px; height: 25px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.35); transition: transform .25s ease; pointer-events: none; }
.toggle input:checked ~ .toggle-thumb { transform: translateX(20px); }

/* ===== Result (กดคัดลอกได้) ===== */
.result {
  margin-top: 14px;
  background: #fff;
  border-radius: 24px;
  padding: 32px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
  cursor: pointer;
  transition: all .25s ease;
  position: relative;
  user-select: none;
}
.result:active { transform: scale(.98); }
.result-number { font-size: 52px; font-weight: 900; color: #1a1a1a; line-height: 1.1; letter-spacing: -1px; text-align: center; }

/* ไอคอนคัดลอกมุมขวาบน */
.copy-icon {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(0,0,0,0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .25s ease;
}
.copy-icon svg {
  width: 18px;
  height: 18px;
  color: rgba(0,0,0,0.4);
  transition: color .25s ease;
}

/* สถานะเมื่อกดคัดลอกแล้ว (สีเขียวทั้งกล่อง) */
.result.copied {
  background: #22c55e;
}
.result.copied .result-number {
  color: #fff;
}
.result.copied .copy-icon {
  background: rgba(255,255,255,0.2);
}
.result.copied .copy-icon svg {
  color: #fff;
}

.hidden { display: none !important; }

/* ===== Spinner ===== */
.spinner { width: 36px; height: 36px; border: 4px solid rgba(74,222,128,0.2); border-top: 4px solid #4ade80; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.result-update { animation: pop .25s ease; }
@keyframes pop { 0% { transform: scale(.95); opacity: .7; } 100% { transform: scale(1); opacity: 1; } }

@media (max-width: 768px) {
  .container { padding: 16px 12px 32px; }
  .title { font-size: 28px; }
  .result-number { font-size: 42px; }
  .stat-value { font-size: 30px; }
}

