.material-symbols-rounded {
  font-family: 'Material Symbols Rounded';
  font-style: normal;
  font-size: 1em;
  line-height: 1;
  vertical-align: -0.125em;
  user-select: none;
}

:root {
  --bg: #f0f0f0;
  --surface: #f7f7f7;
  --border: #dedede;
  --text: #2c2c2c;
  --text-muted: #888;
  --accent: #555;
  --accent-light: #eaeaea;
  --stripe: #f2f2f2;
  --shadow: rgba(0, 0, 0, 0.07);
  --highlight: #d8d8d8;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 24px 16px;
  isolation: isolate;
}

body::before {
  content: '';
  position: fixed;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  z-index: -1;
  pointer-events: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='480' height='240'%3E%3Ctext x='30' y='70' font-size='56' font-family='Georgia,serif' fill='%23000'%3E$%3C/text%3E%3Ctext x='150' y='70' font-size='56' font-family='Georgia,serif' fill='%23000'%3E¥%3C/text%3E%3Ctext x='270' y='70' font-size='56' font-family='Georgia,serif' fill='%23000'%3E₩%3C/text%3E%3Ctext x='390' y='70' font-size='56' font-family='Georgia,serif' fill='%23000'%3E€%3C/text%3E%3Ctext x='90' y='180' font-size='56' font-family='Georgia,serif' fill='%23000'%3E₫%3C/text%3E%3Ctext x='210' y='180' font-size='56' font-family='Georgia,serif' fill='%23000'%3E฿%3C/text%3E%3Ctext x='330' y='180' font-size='56' font-family='Georgia,serif' fill='%23000'%3E₱%3C/text%3E%3Ctext x='450' y='180' font-size='56' font-family='Georgia,serif' fill='%23000'%3E៛%3C/text%3E%3C/svg%3E");
  background-size: 480px 240px;
  transform: rotate(-20deg);
  opacity: 0.04;
  animation: bg-drift 80s linear infinite;
}

body.dark::before {
  filter: invert(1);
  opacity: 0.06;
}

h1 {
  text-align: center;
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 2px;
  line-height: 1.1;
}

.subtitle {
  text-align: center;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-top: 12px;
  margin-bottom: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  max-width: 520px;
  margin: 20px auto 20px;
  box-shadow: 0 2px 12px var(--shadow);
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: end;
  margin-bottom: 16px;
}

.swap-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
  margin-bottom: 1px;
}

.swap-btn:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

.swap-btn:active {
  transform: scale(0.92);
}

.swap-btn.swapping .material-symbols-rounded {
  animation: swap-spin 0.35s ease-in-out;
}

@keyframes swap-spin {
  to {
    transform: rotate(180deg);
  }
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.control-group.full {
  grid-column: 1 / -1;
}

label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

select,
input[type="number"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
  appearance: none;
  -webkit-appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238a8178' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

select:focus,
input[type="number"]:focus {
  border-color: var(--accent);
}

.rate-badge {
  background: var(--accent-light);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 16px;
}

.rate-badge .rate-value {
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
}

.rate-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rate-badge .rate-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.refresh-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.75rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
}

.refresh-btn:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.refresh-btn.spinning .spin-icon {
  display: inline-block;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes bg-drift {
  to {
    background-position: 480px 240px;
  }
}

.segments-section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.segments-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.segments-toggle span:first-child {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.segments-toggle .toggle-icon {
  font-size: 1.1rem;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.segments-section.open .toggle-icon {
  transform: rotate(180deg);
}

.segments-body {
  display: none;
  margin-top: 8px;
}

.segments-section.open .segments-body {
  display: block;
}

.segments-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  margin-top: 4px;
}

.segments-actions button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 0.72rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
}

.segments-actions button:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.segment-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.segment-row input {
  font-size: 0.82rem;
  padding: 7px 8px;
  text-align: center;
  -moz-appearance: textfield;
  appearance: textfield;
}

.segment-row input::-webkit-outer-spin-button,
.segment-row input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.seg-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0;
  margin-bottom: 4px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 28px;
  gap: 8px;
}

.remove-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
  padding: 0;
}

.remove-btn:hover {
  background: #f5e6e6;
  border-color: #d9b5b5;
  color: #a05050;
}

body.dark .remove-btn:hover {
  background: #3a2525;
  border-color: #5a3a3a;
  color: #d07070;
}

.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 520px;
  margin: 0 auto;
  box-shadow: 0 2px 12px var(--shadow);
  overflow: hidden;
}

.table-header {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  background: var(--accent);
  color: #faf8f5;
  padding: 12px 20px;
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.04em;
}

.table-header span:nth-child(2) {
  text-align: right;
  padding-right: 16px;
  border-right: 1px solid rgba(255, 255, 255, 0.25);
}

.table-header span:nth-child(3) {
  padding-left: 16px;
}

.table-header span:last-child {
  text-align: right;
}

.table-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  align-items: center;
  padding: 7px 20px;
  font-size: 0.88rem;
  border-bottom: 1px solid transparent;
  transition: background 0.1s;
}

.table-row:nth-child(odd) {
  background: var(--stripe);
}

.table-row:hover {
  background: var(--highlight);
}

.table-row:last-child {
  border-bottom: none;
}

.table-row .amount {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.table-row .result {
  text-align: right;
  padding-right: 16px;
  border-right: 1px solid var(--border);
  font-weight: 600;
  color: var(--text);
}

.table-row .amount-r {
  color: var(--text-muted);
  font-size: 0.82rem;
  padding-left: 16px;
}

.table-row .result-r {
  text-align: right;
  font-weight: 600;
  color: var(--text);
}

.segment-divider {
  height: 1px;
  background: var(--border);
  margin: 4px 20px;
}

.status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding: 12px;
}

.table-note {
  border-top: 1px solid var(--border);
}

.loading-spin {
  display: inline-block;
  animation: spin 1.2s linear infinite;
  font-size: 1.1em;
  vertical-align: -0.15em;
}

.error {
  color: #a05050;
}

.loading {
  color: var(--accent);
}

body.dark {
  --bg: #1a1a1a;
  --surface: #222;
  --border: #3a3a3a;
  --text: #e0e0e0;
  --text-muted: #888;
  --accent: #aaa;
  --accent-light: #2d2d2d;
  --stripe: #252525;
  --shadow: rgba(0, 0, 0, 0.4);
  --highlight: #383838;
}

body.dark .table-header {
  background: #1a1a1a;
}

body.dark select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23999' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
}

.footer-controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 8px;
}

.toggle-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 0.72rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
}

.toggle-btn:hover {
  background: var(--accent-light);
  color: var(--accent);
}

.site-footer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 12px;
  padding-bottom: 4px;
  line-height: 1.6;
}

.site-footer a {
  color: var(--accent);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

@media (max-width: 400px) {
  .controls-grid {
    grid-template-columns: 1fr;
  }

  .swap-btn {
    justify-self: center;
    transform: rotate(90deg);
  }

  .swap-btn.swapping .material-symbols-rounded {
    animation: swap-spin-v 0.35s ease-in-out;
  }

  @keyframes swap-spin-v {
    to {
      transform: rotate(180deg);
    }
  }

  .segment-row,
  .seg-label {
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 5px;
  }
}