:root {
  color-scheme: light dark;
  --bg: #eef2f7;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-solid: #ffffff;
  --surface-subtle: #f6f8fb;
  --text: #0b1220;
  --muted: #647084;
  --line: #dfe5ee;
  --primary: #116466;
  --primary-strong: #0a4d4f;
  --primary-soft: #e3f4f1;
  --danger: #b42318;
  --warning: #8a5a00;
  --shadow: 0 24px 70px rgba(15, 23, 42, 0.12);
  --radius-lg: 28px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --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);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #071018;
    --surface: rgba(16, 25, 38, 0.94);
    --surface-solid: #101926;
    --surface-subtle: #162130;
    --text: #f3f7fb;
    --muted: #9ba8b8;
    --line: #263449;
    --primary: #60d4c8;
    --primary-strong: #8fe5dc;
    --primary-soft: #133a39;
    --danger: #ff938a;
    --warning: #ffd27a;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
  }
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  min-height: 100svh;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100svh;
  min-height: var(--app-height, 100dvh);
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0%, rgba(17, 100, 102, 0.16), transparent 35rem),
    radial-gradient(circle at 95% 10%, rgba(69, 118, 164, 0.13), transparent 28rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

button,
input {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent);
  outline-offset: 3px;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  min-height: 100svh;
  min-height: var(--app-height, 100dvh);
  margin: 0 auto;
  padding:
    calc(22px + var(--safe-top))
    calc(28px + var(--safe-right))
    calc(22px + var(--safe-bottom))
    calc(28px + var(--safe-left));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 32px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 50px;
  height: 50px;
  place-items: center;
  border-radius: 16px;
  color: white;
  background: linear-gradient(145deg, var(--primary), var(--primary-strong));
  box-shadow: 0 12px 30px rgba(17, 100, 102, 0.3);
}

.brand-mark svg,
.security-note svg,
.feature-list svg,
.info-visual svg,
button svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand-mark svg {
  width: 29px;
  height: 29px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.25rem, 2vw, 1.55rem);
  line-height: 1.1;
  letter-spacing: -0.025em;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.45rem, 2.4vw, 2rem);
  line-height: 1.15;
  letter-spacing: -0.035em;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.14em;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.8fr);
  gap: 24px;
  align-items: stretch;
}

.generator-card,
.info-card {
  border: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.generator-card {
  padding: clamp(24px, 4vw, 42px);
  border-radius: var(--radius-lg);
}

.info-card {
  display: flex;
  flex-direction: column;
  padding: 30px;
  border-radius: var(--radius-lg);
  background:
    linear-gradient(160deg, color-mix(in srgb, var(--primary-soft) 74%, var(--surface)), var(--surface) 48%);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 32px;
}

.privacy-badge {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid color-mix(in srgb, var(--primary) 22%, var(--line));
  border-radius: 999px;
  color: var(--primary-strong);
  background: var(--primary-soft);
  font-size: 0.79rem;
  font-weight: 750;
}

.privacy-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 15%, transparent);
}

.field-group label {
  display: block;
  margin-bottom: 10px;
  font-size: 0.92rem;
  font-weight: 740;
}

.input-wrap {
  position: relative;
}

.input-wrap input {
  width: 100%;
  min-height: 58px;
  padding: 0 56px 0 17px;
  border: 1px solid var(--line);
  border-radius: 15px;
  color: var(--text);
  background: var(--surface-solid);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 16px;
  letter-spacing: 0.035em;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.input-wrap input:hover {
  border-color: color-mix(in srgb, var(--primary) 32%, var(--line));
}

.input-wrap input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 12%, transparent);
}

.icon-button {
  position: absolute;
  top: 50%;
  right: 8px;
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 11px;
  color: var(--muted);
  background: transparent;
  transform: translateY(-50%);
  cursor: pointer;
}

.icon-button:hover {
  color: var(--text);
  background: var(--surface-subtle);
}

.icon-button svg {
  width: 22px;
  height: 22px;
}

.field-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.secondary-button,
.ghost-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
  background: var(--surface-solid);
  font-size: 0.88rem;
  font-weight: 720;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.secondary-button:hover,
.ghost-button:hover {
  border-color: color-mix(in srgb, var(--primary) 34%, var(--line));
  background: var(--surface-subtle);
}

.secondary-button:active,
.ghost-button:active,
.code-button:active {
  transform: scale(0.985);
}

.secondary-button svg {
  width: 18px;
  height: 18px;
}

.danger-text {
  color: var(--danger);
}

.ghost-button {
  min-height: 44px;
  border-color: color-mix(in srgb, var(--primary) 28%, var(--line));
}

.helper-text,
.error-text {
  min-height: 20px;
  margin: 9px 0 0;
  font-size: 0.8rem;
}

.helper-text {
  color: var(--muted);
}

.error-text {
  color: var(--danger);
  font-weight: 650;
}

.code-panel {
  margin-top: 24px;
  padding: clamp(22px, 4vw, 32px);
  border: 1px solid color-mix(in srgb, var(--primary) 20%, var(--line));
  border-radius: 22px;
  background:
    radial-gradient(circle at 50% 20%, color-mix(in srgb, var(--primary-soft) 82%, transparent), transparent 65%),
    var(--surface-subtle);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.code-panel.is-active {
  border-color: color-mix(in srgb, var(--primary) 42%, var(--line));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--primary) 8%, transparent);
}

.code-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
}

.code-button {
  display: grid;
  width: 100%;
  min-height: 154px;
  margin: 10px 0;
  padding: 18px 10px;
  place-items: center;
  border: 0;
  border-radius: 18px;
  color: var(--text);
  background: transparent;
  cursor: pointer;
  transition: transform 140ms ease, background 160ms ease;
}

.code-button:not(:disabled):hover {
  background: color-mix(in srgb, var(--primary-soft) 68%, transparent);
}

.code-button:disabled {
  cursor: default;
}

.code-value {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: clamp(2.9rem, 8vw, 5.2rem);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.14em;
  text-indent: 0.14em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.copy-hint {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 680;
}

.copy-hint svg {
  width: 17px;
  height: 17px;
}

.timer-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 75%, transparent);
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary-strong), var(--primary));
  transition: width 220ms linear;
}

.progress-bar.is-ending {
  background: linear-gradient(90deg, #b36a00, #f2a93b);
}

.timer-text {
  min-width: 84px;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-align: right;
}

.security-note {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-top: 20px;
  padding: 15px 16px;
  border-radius: 15px;
  color: var(--warning);
  background: color-mix(in srgb, #ffc857 16%, transparent);
}

.security-note svg {
  flex: 0 0 auto;
  width: 22px;
  height: 22px;
  margin-top: 1px;
}

.security-note p {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.55;
}

.info-visual {
  display: grid;
  min-height: 190px;
  margin-bottom: 26px;
  place-items: center;
  border-radius: 22px;
  background:
    radial-gradient(circle, color-mix(in srgb, var(--primary) 18%, transparent), transparent 64%);
}

.shield-ring {
  display: grid;
  width: 118px;
  height: 118px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--primary) 30%, transparent);
  border-radius: 38px;
  color: var(--primary-strong);
  background: color-mix(in srgb, var(--primary-soft) 88%, var(--surface));
  box-shadow:
    0 22px 50px color-mix(in srgb, var(--primary) 16%, transparent),
    inset 0 1px rgba(255, 255, 255, 0.4);
  transform: rotate(-6deg);
}

.shield-ring svg {
  width: 64px;
  height: 64px;
  transform: rotate(6deg);
}

.info-card h2 {
  max-width: 12ch;
}

.feature-list {
  display: grid;
  gap: 16px;
  margin: 28px 0;
  padding: 0;
  list-style: none;
}

.feature-list li {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 12px;
  align-items: start;
}

.feature-list li > span {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 10px;
  color: var(--primary-strong);
  background: var(--primary-soft);
  font-size: 0.72rem;
  font-weight: 820;
}

.feature-list strong,
.feature-list small {
  display: block;
}

.feature-list strong {
  margin-bottom: 3px;
  font-size: 0.9rem;
}

.feature-list small,
.compatibility-note {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.5;
}

.compatibility-note {
  margin: auto 0 0;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

footer {
  padding: 24px 8px 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.76rem;
}

footer p {
  margin: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  z-index: 20;
  max-width: calc(100vw - 32px);
  padding: 12px 16px;
  border: 1px solid color-mix(in srgb, var(--primary) 30%, var(--line));
  border-radius: 999px;
  color: var(--surface-solid);
  background: var(--text);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
  font-size: 0.84rem;
  font-weight: 720;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 860px) {
  .app-shell {
    padding-right: calc(18px + var(--safe-right));
    padding-left: calc(18px + var(--safe-left));
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .info-card {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 22px;
  }

  .info-visual {
    grid-row: span 3;
    min-height: 100%;
    margin: 0;
  }

  .feature-list,
  .compatibility-note {
    grid-column: 2;
  }
}

@media (max-width: 620px) {
  body {
    background: var(--surface-solid);
  }

  .app-shell {
    width: 100%;
    padding:
      calc(14px + var(--safe-top))
      calc(14px + var(--safe-right))
      calc(18px + var(--safe-bottom))
      calc(14px + var(--safe-left));
  }

  .topbar {
    margin-bottom: 14px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 14px;
  }

  .brand-mark svg {
    width: 25px;
    height: 25px;
  }

  .brand .eyebrow {
    display: none;
  }

  .install-button {
    min-width: 44px;
    width: 44px;
    padding: 0;
    overflow: hidden;
    color: transparent;
  }

  .install-button span {
    color: var(--text);
    font-size: 1.25rem;
  }

  .generator-card,
  .info-card {
    border-radius: 24px;
    box-shadow: none;
  }

  .generator-card {
    padding: 22px 18px 20px;
    border-color: var(--line);
  }

  .section-heading {
    display: block;
    margin-bottom: 26px;
  }

  .privacy-badge {
    margin-top: 12px;
  }

  .field-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .secondary-button {
    min-height: 46px;
  }

  .code-panel {
    margin-right: -4px;
    margin-left: -4px;
    padding: 22px 14px;
    border-radius: 20px;
  }

  .code-meta {
    display: grid;
    gap: 4px;
    text-align: center;
  }

  .code-button {
    min-height: 140px;
  }

  .code-value {
    font-size: clamp(2.65rem, 14vw, 4rem);
    letter-spacing: 0.1em;
    text-indent: 0.1em;
  }

  .timer-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .timer-text {
    min-width: 0;
    text-align: center;
  }

  .security-note {
    margin-top: 16px;
  }

  .info-card {
    display: block;
    padding: 22px 20px;
  }

  .info-visual {
    min-height: 156px;
    margin-bottom: 22px;
  }

  .shield-ring {
    width: 98px;
    height: 98px;
    border-radius: 32px;
  }

  .shield-ring svg {
    width: 54px;
    height: 54px;
  }

  .info-card h2 {
    max-width: none;
  }

  .feature-list,
  .compatibility-note {
    grid-column: auto;
  }

  footer {
    padding-top: 20px;
  }
}

@media (max-width: 380px) {
  .code-value {
    font-size: 2.38rem;
  }

  .privacy-badge {
    font-size: 0.73rem;
  }
}





/* Fallback màu cho Safari/WebView cũ chưa hỗ trợ color-mix() */
@supports not (color: color-mix(in srgb, white, black)) {
  button:focus-visible,
  input:focus-visible {
    outline-color: rgba(17, 100, 102, 0.55);
  }

  .generator-card,
  .info-card {
    border-color: var(--line);
  }

  .info-card {
    background: var(--surface);
  }

  .privacy-badge,
  .ghost-button,
  .code-panel,
  .toast {
    border-color: var(--line);
  }

  .privacy-dot {
    box-shadow: 0 0 0 4px rgba(17, 100, 102, 0.15);
  }

  .input-wrap input:hover,
  .secondary-button:hover,
  .ghost-button:hover {
    border-color: var(--primary);
  }

  .input-wrap input:focus {
    box-shadow: 0 0 0 4px rgba(17, 100, 102, 0.12);
  }

  .code-panel {
    background: var(--surface-subtle);
  }

  .code-panel.is-active {
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px rgba(17, 100, 102, 0.08);
  }

  .code-button:not(:disabled):hover,
  .security-note,
  .feature-list li > span {
    background: var(--primary-soft);
  }

  .progress-track {
    background: var(--line);
  }

  .info-visual {
    background: transparent;
  }

  .shield-ring {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: 0 22px 50px rgba(17, 100, 102, 0.16), inset 0 1px rgba(255, 255, 255, 0.4);
  }
}

/* Tối ưu xoay tự do và nhiều kích thước thiết bị */
@media (orientation: landscape) {
  .app-shell {
    padding-top: calc(16px + var(--safe-top));
    padding-bottom: calc(16px + var(--safe-bottom));
  }

  .topbar {
    margin-bottom: 20px;
  }
}

/* Điện thoại nằm ngang: ưu tiên vùng nhập và mã, giảm chiều cao trang */
@media (orientation: landscape) and (max-height: 600px) and (max-width: 960px) {
  body {
    overscroll-behavior: none;
  }

  .app-shell {
    padding:
      calc(8px + var(--safe-top))
      calc(14px + var(--safe-right))
      calc(10px + var(--safe-bottom))
      calc(14px + var(--safe-left));
  }

  .topbar {
    margin-bottom: 8px;
  }

  .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 13px;
  }

  .brand-mark svg {
    width: 23px;
    height: 23px;
  }

  .brand .eyebrow,
  footer {
    display: none;
  }

  .content-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .generator-card {
    padding: 16px 18px;
    border-radius: 20px;
  }

  .section-heading {
    align-items: center;
    margin-bottom: 14px;
  }

  .section-heading .eyebrow {
    margin-bottom: 2px;
  }

  .input-wrap input {
    min-height: 50px;
  }

  .field-actions {
    margin-top: 8px;
  }

  .secondary-button {
    min-height: 38px;
  }

  .helper-text,
  .error-text {
    min-height: 16px;
    margin-top: 5px;
  }

  .code-panel {
    margin-top: 12px;
    padding: 14px 18px;
    border-radius: 18px;
  }

  .code-button {
    min-height: 82px;
    margin: 4px 0;
    padding: 8px;
  }

  .code-value {
    font-size: clamp(2.25rem, 9vw, 3.35rem);
  }

  .copy-hint {
    margin-top: 8px;
  }

  .security-note {
    margin-top: 10px;
    padding: 10px 12px;
  }

  .security-note p {
    font-size: 0.76rem;
  }

  .info-card {
    display: grid;
    grid-template-columns: minmax(180px, 0.7fr) minmax(0, 1.3fr);
    gap: 12px 20px;
    padding: 16px 18px;
    border-radius: 20px;
  }

  .info-visual {
    display: none;
  }

  .info-card h2 {
    max-width: none;
    font-size: 1.15rem;
  }

  .feature-list {
    grid-column: 2;
    grid-row: 1 / span 2;
    grid-template-columns: 1fr 1fr;
    gap: 8px 14px;
    margin: 0;
  }

  .feature-list li {
    grid-template-columns: 30px 1fr;
    gap: 8px;
  }

  .feature-list li > span {
    width: 28px;
    height: 28px;
  }

  .feature-list small {
    display: none;
  }

  .compatibility-note {
    grid-column: 1 / -1;
    margin: 0;
    padding-top: 10px;
  }
}

/* Tablet dọc và màn hình gập */
@media (orientation: portrait) and (min-width: 621px) and (max-width: 1024px) {
  .app-shell {
    width: min(820px, 100%);
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .info-card {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 20px;
  }

  .info-visual {
    grid-row: 1 / span 3;
    min-height: 100%;
    margin: 0;
  }

  .feature-list,
  .compatibility-note {
    grid-column: 2;
  }
}

/* Màn hình rất rộng: tránh kéo giãn nội dung quá mức */
@media (min-width: 1440px) {
  .app-shell {
    width: min(1280px, 100%);
  }

  .content-grid {
    grid-template-columns: minmax(0, 1.65fr) minmax(340px, 0.75fr);
  }
}

/* Khi bàn phím ảo mở, nội dung vẫn cuộn và không bị che */
@media (max-height: 520px) {
  body {
    overscroll-behavior-y: auto;
  }

  .app-shell {
    min-height: var(--app-height, 100dvh);
  }
}

@media (display-mode: standalone) {
  body {
    user-select: none;
    -webkit-user-select: none;
  }

  input,
  .code-value {
    user-select: text;
    -webkit-user-select: text;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
