/* Palette from the Bangladeshi flag: green means it fits, red means it doesn't. */
/* light-dark() follows color-scheme: the system's by default, or the saved toggle choice. */
:root {
  color-scheme: light dark;
  --paper: light-dark(#f3f7f4, #0b1913);
  --ink: light-dark(#10241c, #e6f0eb);
  --muted: light-dark(#55685f, #8ea398);
  --line: light-dark(#d3dfd8, #213a2f);
  --slot: light-dark(#e1eae4, #15291f);
  --green: light-dark(#006a4e, #1f9e73);
  --green-alt: light-dark(#2e8b67, #147556);
  --red: light-dark(#e0263b, #ff4d61);
  --red-alt: light-dark(#f2606f, #c23445);
  --amber: light-dark(#a15c00, #f0b24a);
  --on-color: #ffffff;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Anek Bangla", "Kohinoor Bangla", "Noto Sans Bengali", system-ui, sans-serif;
  font-size: 17px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

main {
  position: relative;
  max-width: 640px;
  margin: 0 auto;
  padding: 64px 20px 40px;
}

.theme {
  position: absolute;
  top: 16px;
  right: 20px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--muted);
}
.theme:hover { color: var(--green); }
.theme svg { width: 20px; height: 20px; }
[data-theme="light"] .theme .sun,
[data-theme="dark"] .theme .moon { display: none; }

h1 {
  margin: 0 0 12px;
  font-size: clamp(2.5rem, 8vw, 4rem);
  font-stretch: 75%;
  font-weight: 750;
  line-height: 0.95;
  letter-spacing: -0.01em;
}

header p { margin: 0; color: var(--muted); max-width: 46ch; }

h2 {
  margin: 0 0 8px;
  font-size: 1.4rem;
  font-stretch: 87.5%;
  font-weight: 700;
  line-height: 1.15;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  background: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 12px;
}
button:hover { border-color: var(--green); }

:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

a { color: var(--green); text-underline-offset: 3px; }

/* Checker */
.check { margin-top: 44px; }

.field {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 3px solid var(--ink);
}
.field:focus-within { border-bottom-color: var(--green); }

input {
  flex: 1;
  min-width: 0;
  padding: 6px 0 8px;
  font: inherit;
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 500;
  color: var(--ink);
  background: none;
  border: 0;
}
input::placeholder { color: var(--muted); opacity: 0.6; }
input:focus-visible { outline: none; }

#copy-name { border-color: transparent; color: var(--muted); }
#copy-name:hover { color: var(--green); }

.try {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 12px 0 0;
  font-size: 0.95rem;
  color: var(--muted);
}
.try button { color: var(--ink); }

.readout {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-top: 36px;
}

.verdict { margin: 0; font-weight: 600; font-size: 1.1rem; color: var(--muted); }

.count {
  margin: 0;
  font-size: 2.75rem;
  font-stretch: 75%;
  font-weight: 750;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.count .of { color: var(--muted); font-weight: 400; }

[data-level="ok"] .verdict, [data-level="ok"] #bytes { color: var(--green); }
[data-level="warn"] .verdict, [data-level="warn"] #bytes { color: var(--amber); }
[data-level="error"] .verdict, [data-level="error"] #bytes { color: var(--red); }

/* The strip: one block per character, width = its bytes. */
.strip {
  position: relative;
  display: flex;
  height: 64px;
  margin-top: 14px;
}

.block, .slot {
  flex: 1 1 0;
  min-width: 0;
  border-right: 3px solid var(--paper);
  border-radius: 6px;
}
.slot { background: var(--slot); }

.block {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--green);
  color: var(--on-color);
}
.block.alt { background: var(--green-alt); }
.block.over { background: var(--red); }
.block.over.alt { background: var(--red-alt); }

.block { container-type: inline-size; }
.glyph { font-size: 1.25rem; font-weight: 600; white-space: nowrap; }

/* One-byte blocks get narrow; shrink, then drop, the glyph rather than let it collide. */
@container (max-width: 26px) {
  .glyph { font-size: 0.8rem; }
  .size { display: none; }
}
@container (max-width: 11px) {
  .glyph { display: none; }
}
.size {
  position: absolute;
  right: 5px;
  bottom: 2px;
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
}

/* Limit marker; its label hangs below so it never collides with the count above. */
.strip.is-over::after {
  content: "";
  position: absolute;
  top: -6px;
  bottom: -6px;
  left: var(--limit);
  width: 2px;
  margin-left: -2px;
  background: var(--ink);
}
.strip.is-over::before {
  content: "32";
  position: absolute;
  top: calc(100% + 6px);
  left: var(--limit);
  transform: translateX(-50%);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.2;
}
.strip.is-over + .notes { margin-top: 28px; }

.notes { list-style: none; margin: 16px 0 0; padding: 0; font-size: 0.95rem; }
.notes li { padding-left: 12px; border-left: 3px solid var(--line); margin-bottom: 6px; color: var(--muted); }
.notes .error { border-left-color: var(--red); color: var(--ink); }
.notes .warn { border-left-color: var(--amber); color: var(--ink); }

.suggest { margin: 14px 0 0; color: var(--muted); }
.suggest button { margin-left: 4px; border-color: var(--green); color: var(--green); font-weight: 600; }

/* Unlock */
.unlock {
  margin-top: 64px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}
.unlock p { margin: 0; max-width: 60ch; }

.bookmarklet {
  display: inline-block;
  padding: 1px 12px 2px;
  border-radius: 999px;
  background: var(--green);
  color: var(--on-color);
  font-weight: 600;
  text-decoration: none;
  cursor: grab;
}
.bookmarklet:active { cursor: grabbing; }

.unlock .alt {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 14px;
  font-size: 0.95rem;
  color: var(--muted);
}

/* Key */
.key {
  margin-top: 48px;
  padding-top: 28px;
  border-top: 1px solid var(--line);
}
.key h2 { font-size: 1.1rem; }

.key dl {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin: 12px 0 16px;
}
.key dl div { padding: 10px 0 8px; border-top: 3px solid var(--green); }
.key dl div:nth-child(n + 4) { border-top-color: var(--green-alt); }
.key dt { font-size: 1.2rem; white-space: nowrap; }
.key dd {
  margin: 0;
  font-size: 1.6rem;
  font-stretch: 75%;
  font-weight: 750;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.key p { margin: 0; color: var(--muted); font-size: 0.95rem; }

code { font-family: inherit; font-weight: 700; color: var(--red); letter-spacing: 0.1em; }

footer { margin-top: 56px; color: var(--muted); font-size: 0.85rem; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.95rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.18s, transform 0.18s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 520px) {
  main { padding-top: 40px; }
  .strip { height: 52px; }
  .size { display: none; }
  .count { font-size: 2.2rem; }
  .key dl { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .toast { transition: none; }
}
