:root {
  color-scheme: light;
  --page: #fafafa;
  --surface: #fafafa;
  --panel: #d9d9d9;
  --tab: #e8e8e8;
  --input: #ffffff;
  --text: #101010;
  --muted: #626262;
  --line: #bdbdbd;
  --focus: #111111;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.12);
  --space-1: clamp(6px, 1.3vw, 10px);
  --space-2: clamp(14px, 2.8vw, 22px);
  --space-3: clamp(20px, 3.8vw, 30px);
  --space-4: clamp(26px, 5vw, 40px);

  --radius: clamp(24px, 6vw, 40px);

  --text-small: clamp(1rem, 3.8vw, 1.4rem);
  --text-body: clamp(1.45rem, 5.2vw, 2.35rem);
  --text-large: clamp(2.35rem, 8.8vw, 4.6rem);
  --text-result: clamp(3.15rem, 12vw, 6.4rem);
  --text-input: clamp(2.45rem, 9vw, 4.8rem);
  --text-tab: clamp(2.15rem, 7.6vw, 3.8rem);

  --control-height: clamp(66px, 11.2vw, 98px);
  --dialog-width: min(calc(100% - 24px), 480px);
  --app-height: 100svh;
  --app-height: 100dvh;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #111111;
  --surface: #1b1b1b;
  --panel: #292929;
  --tab: #222222;
  --input: #101010;
  --text: #f5f5f5;
  --muted: #b8b8b8;
  --line: #454545;
  --focus: #ffffff;
  --shadow: 0 18px 55px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

html {
  background: var(--page);
}

body {
  min-width: 280px;
  height: var(--app-height);
  background: var(--page);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-weight: 650;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  overflow-y: hidden;
}

button,
input,
summary {
  color: inherit;
  font: inherit;
  -webkit-appearance: none;
  appearance: none;
}

button {
  border: 0;
  background: transparent;
  -webkit-tap-highlight-color: transparent;
  box-shadow: none;
}

.app-shell {
  width: min(100%, 510px);
  height: var(--app-height);
  margin: 0 auto;
  padding:
    max(var(--space-2), env(safe-area-inset-top))
    clamp(10px, 4.5vw, 34px)
    max(var(--space-1), env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  background: transparent;
}

.toolbar {
  flex: 0 0 auto;
  min-height: clamp(46px, 10vw, 62px);
  margin-bottom: var(--space-1);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.icon-button {
  width: clamp(46px, 10vw, 62px);
  height: clamp(46px, 10vw, 62px);
  padding: 0;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

.icon-button:hover {
  background: var(--tab);
}

.icon-button:active {
  transform: scale(0.94);
}

.icon-button svg {
  width: clamp(26px, 5.8vw, 35px);
  height: clamp(26px, 5.8vw, 35px);
  display: block;
  flex-shrink: 0;
  color: currentColor;
}

#themeButton .moon-icon,
#themeButton .sun-icon {
  display: none;
}

:root:not([data-theme="dark"]) #themeButton .moon-icon {
  display: block;
}

:root[data-theme="dark"] #themeButton .sun-icon {
  display: block;
}

.tabs {
  flex: 0 0 auto;
  min-height: clamp(72px, 14vw, 104px);
  margin-bottom: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: end;
}

.tab {
  min-width: 0;
  min-height: clamp(72px, 14vw, 104px);
  padding: var(--space-1) 8px;
  border: 0;
  outline: none;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--tab);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-tab);
  font-weight: 780;
  line-height: 1.05;
  white-space: nowrap;
  cursor: pointer;
}

.tab.is-active {
  background: var(--panel);
}

.panels {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
}

.tab:focus-visible,
.icon-button:focus-visible,
.footer button:focus-visible,
summary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--line);
}

.panel {
  grid-area: 1 / 1;
  flex: 1 1 0;
  min-height: 0;
  padding: var(--space-3) clamp(14px, 6.5vw, 36px);
  border-radius: 0 0 var(--radius) var(--radius);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-content: center;
  gap: var(--space-3);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 20px 34svh;
  background: var(--panel);
}

.panel[data-active="true"] {
  z-index: 1;
  visibility: visible;
}

.panel[data-active="false"] {
  z-index: 0;
  visibility: hidden;
  pointer-events: none;
}

.panel-content {
  width: 100%;
}

.calculate-content {
  margin-block: auto;
  display: grid;
  gap: var(--space-3);
}

.topup-content {
  width: 100%;
  min-height: 100%;
  display: grid;
  grid-template-rows: 1fr auto 1fr auto;
}

.topup-main {
  grid-row: 2;
  display: grid;
  gap: var(--space-3);
}

.field-group {
  flex: none;
  width: 100%;
  min-height: max-content;
  margin-bottom: 0;
  display: grid;
  grid-template-rows: auto auto auto;
  gap: clamp(7px, 1.6vw, 12px);
  text-align: center;
  scroll-margin-block: 16px 34svh;
}

.field-group:last-child {
  margin-bottom: 0;
}

.field-group label {
  display: block;
  font-size: var(--text-large);
  font-weight: 840;
  line-height: 1.05;
}

.field-group small {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 1.1em;
  margin-top: 0;
  color: var(--muted);
  font-size: var(--text-small);
  font-weight: 700;
  line-height: 1;
}

.field-group small:empty::before {
  content: "\00a0";
  visibility: hidden;
}

.money-input {
  margin-top: 0;
  width: 100%;
}

.money-input input {
  width: 100%;
  height: var(--control-height);
  min-height: 0;
  padding: clamp(2px, 0.7vw, 6px) clamp(16px, 5vw, 28px);
  border: 3px solid transparent;
  border-radius: 999px;
  outline: none;
  background: var(--input);
  font-size: var(--text-input);
  font-weight: 820;
  line-height: 1;
  text-align: center;
  font-variant-numeric: tabular-nums;
  box-sizing: border-box;
}

.money-input input:focus {
  border-color: var(--focus);
}

.topup-panel .field-group {
  width: 100%;
  margin-bottom: 0;
}

.result-block {
  flex: 0 0 auto;
  width: 100%;
  margin-top: 0;
  padding: var(--space-3) var(--space-2);
  border: 2px solid var(--line);
  border-radius: clamp(18px, min(6vw, 3.6dvh), 28px);
  text-align: center;
}

.result-block span {
  display: block;
  color: var(--muted);
  font-size: var(--text-input);
  font-weight: 780;
  line-height: 1.1;
}

.result-block strong {
  display: block;
  margin: var(--space-1) 0;
  font-size: var(--text-result);
  font-weight: 850;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.total-hint {
  flex: 0 0 auto;
  grid-row: 4;
  align-self: end;
  margin: 0;
  padding-top: var(--space-4);
  color: var(--muted);
  font-size: var(--text-body);
  font-weight: 700;
  text-align: center;
}

.total-hint strong {
  color: var(--text);
}

/* dialogs */

dialog {
  width: var(--dialog-width);
  max-height: min(84dvh, 720px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: clamp(18px, 5vw, 26px);
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(3px);
}

dialog article {
  position: relative;
  max-height: min(84dvh, 720px);
  padding: clamp(24px, 5dvh, 34px) clamp(20px, 6vw, 28px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

dialog h2 {
  margin: 0 44px var(--space-4) 0;
  font-size: clamp(22px, 3dvh, 28px);
  font-weight: 700;
  line-height: 1.1;
}

dialog h3 {
  margin: var(--space-4) 0 var(--space-1);
  font-size: var(--text-body);
}

dialog p {
  margin: var(--space-2) 0;
  color: var(--muted);
  font-size: var(--text-body);
  font-weight: 560;
}

.close-button {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  width: clamp(42px, 6dvh, 48px);
  height: clamp(42px, 6dvh, 48px);
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  font-size: clamp(1.7rem, 4dvh, 2rem);
  line-height: 1;
  cursor: pointer;
}

.close-button:focus,
.close-button:focus-visible,
.close-button:hover,
.close-button:active {
  outline: none;
  background: transparent;
  box-shadow: none;
}

/* accordion */

.help-accordion > h2 {
  font-size: clamp(22px, 3dvh, 28px);
  font-weight: 700;
}

.help-accordion details {
  border-bottom: 1px solid var(--line);
  padding: clamp(8px, 1.8dvh, 16px) 0;
}

.help-accordion details:last-of-type {
  border-bottom: 0;
}

.help-accordion summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  user-select: none;
}

.help-accordion summary::-webkit-details-marker {
  display: none;
}

.help-accordion > details > summary {
  font-size: clamp(18px, 2.4dvh, 22px);
  font-weight: 650;
  color: var(--text);
  opacity: 0.96;
}

.help-accordion details details > summary {
  font-size: clamp(16px, 2.1dvh, 18px);
  font-weight: 560;
  color: var(--text);
  opacity: 0.81;
}

.help-accordion summary::after {
  content: "▸";
  flex: 0 0 auto;
  transition: transform 0.2s ease;
}

.help-accordion details[open] > summary::after {
  transform: rotate(90deg);
}

.help-accordion details p,
.help-accordion details ol,
.help-accordion details ul {
  margin: clamp(8px, 1.5dvh, 14px) 0 0;
  padding-left: 1.2em;
  color: var(--muted);
  font-size: clamp(15px, 2dvh, 17px);
  font-weight: 560;
}

.help-accordion details p {
  padding-left: 0;
}

.help-accordion li + li {
  margin-top: 0.35em;
}

dialog article a {
  color: inherit;
  font-weight: 700;
  text-decoration-color: currentColor;
  text-underline-offset: 0.14em;
}

dialog article {
  position: relative;
}

/* footer */

.footer {
  flex: 0 0 clamp(38px, 5.8dvh, 54px);
  min-width: 0;
  padding-top: var(--space-1);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: clamp(3px, 1.4vw, 8px);
  overflow: hidden;
  color: var(--muted);
  opacity: 0.81;
  font-size: clamp(0.9rem, min(2.75vw, 1.5dvh), 1.2rem);
  font-weight: 560;
  white-space: nowrap;
}

.footer button {
  min-width: 0;
  min-height: 34px;
  padding: 4px 1px;
  border: 0;
  overflow: hidden;
  background: transparent;
  color: inherit;
  font-size: inherit;
  text-decoration: underline;
  text-overflow: ellipsis;
  text-underline-offset: 3px;
  white-space: nowrap;
  cursor: pointer;
}

.tip-placeholder {
  margin-top: var(--space-2);
  padding: var(--space-3);
  border: 2px dashed var(--line);
  border-radius: 18px;
  font-size: var(--text-body);
}

.tip-placeholder small {
  color: var(--muted);
  font-weight: 550;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: fixed;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
  inset: 0 auto auto 0;
  pointer-events: none;
}

@media (max-width: 699px) {
  .tabs {
    margin-top: auto;
  }

  .panels {
    flex: 0 1 auto;
  }

  .panel {
    flex: 0 1 auto;
    min-height: 0;
    padding-block: var(--space-3);
    scroll-padding-block: 20px;
  }

  .topup-content {
    block-size: 100%;
    min-height: 0;
    grid-template-rows:
      minmax(var(--space-1), 0.55fr)
      auto
      minmax(var(--space-3), 1fr)
      auto;
  }

  .topup-main {
    gap: clamp(14px, 2.8dvh, 24px);
  }

  .calculate-content {
    padding-top: var(--space-1);
  }

  .total-hint {
    padding-top: 0;
  }

  .footer {
    margin-top: auto;
  }
}

@media (max-height: 640px) and (max-width: 699px) {
  :root {
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --text-small: clamp(0.92rem, 2.6vw, 1.1rem);
    --text-body: clamp(1.2rem, 3.6vw, 1.5rem);
    --text-large: clamp(1.9rem, 6.6vw, 2.9rem);
    --text-result: clamp(2.3rem, 8.6vw, 3.5rem);
    --text-input: clamp(1.95rem, 6.9vw, 3rem);
    --text-tab: clamp(1.75rem, 5.8vw, 2.5rem);
    --control-height: clamp(54px, 9.8vw, 72px);
  }

  .app-shell {
    padding-inline: clamp(8px, 3.5vw, 20px);
  }

  .toolbar {
    min-height: 42px;
  }

  .icon-button {
    width: 42px;
    height: 42px;
  }

  .field-group small {
    min-height: 1em;
  }

  .footer {
    flex-basis: 34px;
    font-size: 0.84rem;
  }
}

@media (max-width: 390px) and (max-height: 760px) {
  :root {
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 10px;
    --space-4: 14px;
    --text-small: clamp(0.86rem, 3.2vw, 0.98rem);
    --text-body: clamp(1.05rem, 3.9vw, 1.28rem);
    --text-large: clamp(1.72rem, 6.2vw, 2.4rem);
    --text-result: clamp(2.1rem, 8.2vw, 3.1rem);
    --text-input: clamp(1.84rem, 6.6vw, 2.5rem);
    --text-tab: clamp(1.52rem, 5.6vw, 2rem);
    --control-height: clamp(52px, 9.8vw, 68px);
  }

  .app-shell {
    padding-inline: 8px;
  }

  .toolbar {
    min-height: 40px;
    margin-bottom: 4px;
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

  .tabs,
  .tab {
    min-height: 50px;
  }

  .panel {
    gap: 8px;
    padding-inline: 10px;
    justify-content: center;
  }

  .result-block {
    padding: 12px 10px;
  }

  .topup-content {
    block-size: 100%;
    min-height: 0;
  }

  .footer {
    flex-basis: auto;
    padding-top: 6px;
    padding-bottom: 2px;
    font-size: 0.78rem;
    line-height: 1.2;
  }
}

@media (min-width: 700px) {
  :root {
    --space-1: clamp(4px, 0.8dvh, 8px);
    --space-2: clamp(7px, 1.25dvh, 13px);
    --space-3: clamp(10px, 1.8dvh, 18px);
    --space-4: clamp(14px, 2.5dvh, 26px);
    --radius: clamp(24px, min(8vw, 5dvh), 40px);
    --text-small: clamp(0.9rem, min(3.1vw, 1.65dvh), 1.2rem);
    --text-body: clamp(0.98rem, min(3.9vw, 2.05dvh), 1.28rem);
    --text-large: clamp(1.9rem, min(8.5vw, 5.1dvh), 3rem);
    --text-result: clamp(2.4rem, min(11.8vw, 6.8dvh), 4.6rem);
    --text-input: clamp(1.95rem, min(8.6vw, 5.2dvh), 3.05rem);
    --text-tab: clamp(1.6rem, min(7vw, 4.4dvh), 2.8rem);
    --control-height: clamp(54px, 7.8dvh, 78px);
  }

  :root:not([data-theme="dark"]) {
    --page: #ececec;
  }

  body {
    height: auto;
    min-height: 100svh;
    padding: clamp(18px, 4dvh, 34px);
    background: var(--page);
    overflow-y: auto;
  }

  .app-shell {
    width: min(100%, 510px);
    min-height: min(860px, calc(100svh - clamp(36px, 8dvh, 68px)));
    height: auto;
    padding:
      max(var(--space-2), env(safe-area-inset-top))
      clamp(10px, 4.5vw, 34px)
      max(var(--space-1), env(safe-area-inset-bottom));
    background: var(--surface);
    border-radius: 10px;
    box-shadow: var(--shadow);
  }

  .toolbar {
    min-height: clamp(46px, 7.5dvh, 62px);
  }

  .icon-button {
    width: clamp(46px, 7.5dvh, 62px);
    height: clamp(46px, 7.5dvh, 62px);
  }

  .icon-button svg {
    width: clamp(27px, 4.4dvh, 35px);
    height: clamp(27px, 4.4dvh, 35px);
  }

  .tabs {
    flex: 0 0 clamp(84px, 12.5dvh, 122px);
    min-height: 0;
  }

  .tab {
    min-height: 0;
    padding: clamp(12px, 2.2dvh, 18px) 8px clamp(16px, 3dvh, 24px);
  }

  .panel {
    padding: var(--space-2) clamp(12px, 6.5vw, 36px);
    gap: var(--space-2);
    justify-content: center;
    overflow: hidden;
  }

  .field-group {
    margin-bottom: 0;
    gap: clamp(2px, 0.45dvh, 6px);
  }

  .field-group label {
    margin-bottom: 0;
  }

  .field-group small {
    min-height: 1.1em;
    margin-top: 0;
    font-size: var(--text-small);
    font-weight: 560;
    line-height: 1.2;
  }

  .money-input {
    margin-top: 0;
  }

  .money-input input {
    padding: 4px clamp(12px, 5vw, 22px);
  }

  .topup-panel .field-group {
    margin-bottom: var(--space-3);
  }

  .topup-content {
    min-height: 0;
    grid-template-rows: auto auto;
    gap: var(--space-4);
  }

  .topup-main {
    gap: var(--space-3);
  }

  .result-block {
    margin-top: var(--space-1);
  }

  .result-block span {
    font-size: var(--text-large);
  }

  .total-hint {
    margin: 0;
    padding-top: 0;
    font-size: var(--text-body);
  }
}

.note {
  font-size: var(--text-small);
  opacity: 0.81;
}

@media (prefers-reduced-motion: no-preference) {
  .icon-button,
  .tab,
  dialog,
  summary::after {
    transition:
      transform 0.16s ease,
      background-color 0.2s ease,
      color 0.2s ease,
      opacity 0.2s ease;
  }

  dialog[open] {
    animation: appear 0.18s ease-out;
  }

  @keyframes appear {
    from {
      opacity: 0;
      transform: translateY(8px) scale(0.98);
    }
  }
}
