:root{
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;

  --border: #e5e7eb;
  --border-2: #eef2f7;

  --primary: #111827;
  --primary-2: #0b1220;

  --danger: #dc2626;
  --danger-bg: #fef2f2;

  --success: #16a34a;
  --success-bg: #f0fdf4;

  --shadow: 0 8px 30px rgba(17, 24, 39, .08);
  --radius: 16px;

  --tap: 44px;
}

*{ box-sizing:border-box; }

html, body{ height:100%; }

body{
  margin:0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Noto Sans Thai", sans-serif;
  background: radial-gradient(1200px 500px at 50% -200px, #e9efff 0%, var(--bg) 55%, var(--bg) 100%);
  color: var(--text);
}

.wrap{
  max-width: 980px;
  margin: 0 auto;
  padding: 16px;
}

h1{
  font-size: 20px;
  margin: 8px 0 6px;
  letter-spacing: -0.2px;
}

.sub{
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

/* ---------- Nav ---------- */
.nav{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  margin: 10px 0 14px;
}

.navBtn{
  flex: 1 1 180px;
  min-height: var(--tap);
  border:1px solid var(--border);
  background: rgba(255,255,255,.9);
  padding: 12px 14px;
  border-radius: 14px;
  cursor:pointer;
  font-weight: 900;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  box-shadow: 0 1px 0 rgba(0,0,0,.02);
  transition: transform .08s ease, box-shadow .2s ease, background .2s ease;
}

.navBtn:active{ transform: scale(.99); }

.navBtn.active{
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
  color:#fff;
  box-shadow: 0 12px 30px rgba(17,24,39,.16);
}

.badge{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-width: 30px;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: #eef2ff;
  color: #1f2a44;
  font-weight: 900;
  font-size: 12px;
}

.navBtn.active .badge{
  background: rgba(255,255,255,.15);
  color: #fff;
}

/* ---------- Buttons ---------- */
.row{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  margin: 10px 0 14px;
}

.btn{
  min-height: var(--tap);
  border: 1px solid var(--border);
  background: #fff;
  padding: 11px 14px;
  border-radius: 999px;
  cursor:pointer;
  font-weight: 900;
  user-select:none;
  transition: transform .08s ease, box-shadow .2s ease, background .2s ease;
}

.btn:active{ transform: scale(.99); }

.btn.active{
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-2) 100%);
  color:#fff;
}

.btn.copy{
  border-color: transparent;
  background: linear-gradient(135deg, #111827 0%, #1f2937 100%);
  color:#fff;
}

.btn.danger{
  border-color: rgba(220,38,38,.35);
  background: var(--danger-bg);
  color: var(--danger);
}

/* smaller action buttons */
.smallBtn{
  min-height: 38px;
  border:1px solid var(--border);
  background:#fff;
  padding: 8px 10px;
  border-radius: 12px;
  cursor:pointer;
  font-weight: 900;
  font-size: 13px;
  transition: transform .08s ease, box-shadow .2s ease;
}

.smallBtn:active{ transform: scale(.99); }

.smallBtn.danger{
  border-color: rgba(220,38,38,.35);
  background: var(--danger-bg);
  color: var(--danger);
}

/* ---------- Cards ---------- */
.card{
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.cardTitle{
  margin: 0 0 10px;
  font-size: 16px;
  letter-spacing: -0.2px;
}

.mt12{ margin-top: 12px; }
.hidden{ display:none; }

/* ---------- Form ---------- */
.toolbar{
  display:flex;
  gap:12px;
  flex-wrap:wrap;
  align-items:flex-end;
  margin: 10px 0 12px;
}

.toolField{ flex: 1 1 280px; min-width: 260px; }
.toolButtons{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; }

.lbl{
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 6px;
}

input{
  width:100%;
  min-height: var(--tap);
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  font-size: 16px;
  outline:none;
  background: #fff;
  transition: box-shadow .2s ease, border-color .2s ease;
  -webkit-tap-highlight-color: transparent;
}

input:focus{
  border-color: rgba(17,24,39,.35);
  box-shadow: 0 0 0 4px rgba(17,24,39,.08);
}

.read{
  min-height: var(--tap);
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid var(--border-2);
  background: #f9fafb;
  font-size: 16px;
  color: #0f172a;
  display:flex;
  align-items:center;
}

/* ---------- Grid ---------- */
.grid{
  display:grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 12px;
}

@media (max-width: 900px){
  .grid{ grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 540px){
  .wrap{ padding: 12px; }
  h1{ font-size: 18px; }
  .sub{ font-size: 12px; }

  .grid{ grid-template-columns: 1fr; }

  /* ทำให้ปุ่ม/แถวเต็มจอ กดง่าย */
  .btn, .navBtn{
    width: 100%;
  }

  /* toolbar ให้เรียงลง */
  .toolField{ min-width: 100%; }
  .toolButtons{ width: 100%; justify-content: space-between; }
  #copyBtn{ flex: 1 1 auto; width: 100%; }

  /* ให้ status ไม่ดัน layout */
  .status{ width: 100%; min-width: 0; }
}

/* ---------- Result ---------- */
.resultLine{
  font-size: 15px;
  margin: 8px 0;
  line-height: 1.45;
}

.hint{
  color: var(--muted);
  font-size: 13px;
  margin-top: 8px;
  line-height: 1.5;
}

.topnote{
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-2);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.ok{ color: var(--success); font-weight: 900; }
.no{ color: var(--danger); font-weight: 900; }

/* ---------- History ---------- */
.historyHeader{
  display:flex;
  gap:10px;
  align-items:center;
  justify-content:space-between;
  flex-wrap:wrap;
}

.historyList{
  display:flex;
  flex-direction:column;
  gap:12px;
}

/* Month accordion */
.monthCard{
  border:1px solid var(--border);
  border-radius: 16px;
  background: #fff;
  overflow:hidden;
  box-shadow: 0 8px 24px rgba(17,24,39,.06);
}

.monthCard summary{
  list-style:none;
  cursor:pointer;
  padding: 12px 14px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  font-weight: 900;
  background: linear-gradient(180deg, #ffffff 0%, #fbfbfd 100%);
  -webkit-tap-highlight-color: transparent;
}

.monthCard summary::-webkit-details-marker{ display:none; }

.monthMeta{
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.monthBody{ padding: 0 14px 14px; }

/* Date accordion */
.dateCard{
  border:1px solid var(--border);
  border-radius: 14px;
  background: #fff;
  overflow:hidden;
  margin-top: 10px;
}

.dateCard summary{
  list-style:none;
  cursor:pointer;
  padding: 10px 12px;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:10px;
  font-weight: 900;
  background: #fcfcfe;
  -webkit-tap-highlight-color: transparent;
}

.dateCard summary::-webkit-details-marker{ display:none; }

.dateMeta{
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.dateBody{ padding: 10px 12px 12px; }

/* History item */
.historyItem{
  border:1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: #fff;
  margin-top: 10px;
}

.itemTop{
  display:flex;
  justify-content:space-between;
  gap:10px;
  flex-wrap:wrap;
  margin-bottom: 8px;
}

.itemName{ font-weight: 900; }
.itemMeta{
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.itemButtons{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  margin-top: 10px;
}

.pre{
  white-space:pre-wrap;
  background:#f9fafb;
  border:1px solid var(--border-2);
  padding: 10px;
  border-radius: 14px;
  font-size: 13px;
  margin: 8px 0 0;
  line-height: 1.55;
}

/* Mobile: ทำปุ่มในประวัติเต็มบรรทัด */
@media (max-width: 540px){
  .itemButtons .smallBtn{ width: 100%; }
}

/* Make <details> feel nice */
details > summary{ user-select:none; }

/* ===== iOS app-like + Dark mode (append at end) ===== */

/* Safe-area for iPhone notch/home indicator */
:root{
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

/* Make it feel like an iOS app */
body{
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

.wrap{
  padding-top: calc(16px + var(--safe-top));
  padding-left: calc(16px + var(--safe-left));
  padding-right: calc(16px + var(--safe-right));
  padding-bottom: calc(16px + var(--safe-bottom));
}

/* Make buttons feel iOS */
.btn, .navBtn, input, .read, .smallBtn{
  border-radius: 16px;
}

.btn, .navBtn, .smallBtn{
  touch-action: manipulation;
}

.btn:focus, .navBtn:focus, .smallBtn:focus, input:focus{
  outline: none;
}

/* Floating “app” vibe: slightly tighter spacing on phones */
@media (max-width: 540px){
  .card{ padding: 12px; }
  .cardTitle{ font-size: 15px; }
  .resultLine{ font-size: 15px; }
}

/* ===== Dark mode variables ===== */
:root{
  --dm-bg: #0b1220;
  --dm-bg-2: #0f172a;
  --dm-card: rgba(255,255,255,.06);
  --dm-border: rgba(255,255,255,.10);
  --dm-text: #e5e7eb;
  --dm-muted: rgba(229,231,235,.72);
  --dm-shadow: 0 12px 40px rgba(0,0,0,.45);
}

/* Auto dark if user prefers (can be overridden by toggle) */
@media (prefers-color-scheme: dark){
  body:not(.theme-light){
    background: radial-gradient(1200px 500px at 50% -200px, rgba(59,130,246,.22) 0%, var(--dm-bg) 60%, var(--dm-bg) 100%);
  }
}

/* Manual dark mode */
body.theme-dark{
  background: radial-gradient(1200px 500px at 50% -200px, rgba(59,130,246,.22) 0%, var(--dm-bg) 60%, var(--dm-bg) 100%);
  color: var(--dm-text);
}

body.theme-dark .sub,
body.theme-dark .lbl,
body.theme-dark .hint,
body.theme-dark .itemMeta{
  color: var(--dm-muted);
}

body.theme-dark .card,
body.theme-dark .monthCard,
body.theme-dark .dateCard,
body.theme-dark .historyItem{
  background: var(--dm-card);
  border-color: var(--dm-border);
  box-shadow: var(--dm-shadow);
  backdrop-filter: blur(10px);
}

body.theme-dark input{
  background: rgba(255,255,255,.06);
  border-color: var(--dm-border);
  color: var(--dm-text);
}

body.theme-dark input:focus{
  border-color: rgba(255,255,255,.22);
  box-shadow: 0 0 0 4px rgba(59,130,246,.18);
}

body.theme-dark .read{
  background: rgba(255,255,255,.05);
  border-color: rgba(255,255,255,.08);
  color: var(--dm-text);
}

body.theme-dark .btn{
  background: rgba(255,255,255,.06);
  border-color: var(--dm-border);
  color: var(--dm-text);
}

body.theme-dark .btn.active,
body.theme-dark .btn.copy,
body.theme-dark .navBtn.active{
  border-color: transparent;
}

body.theme-dark .navBtn{
  background: rgba(255,255,255,.06);
  border-color: var(--dm-border);
  color: var(--dm-text);
}

body.theme-dark .badge{
  background: rgba(255,255,255,.10);
  color: var(--dm-text);
}

body.theme-dark .pre{
  background: rgba(255,255,255,.05);
  border-color: rgba(255,255,255,.08);
  color: var(--dm-text);
}

/* Make the theme toggle look like an iOS icon button */
#themeToggle{
  width: 48px;
  min-width: 48px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
@media (max-width: 540px){
  #themeToggle{
    width: 100%;
    min-width: 0;
  }
}


