:root {
  --bg: #0f1720;
  --bg-card: #1b2530;
  --bg-input: #0f1720;
  --border: #2c3a48;
  --border-focus: #4f9cf9;
  --text: #e7edf3;
  --text-dim: #92a3b3;
  --accent: #4f9cf9;
  --accent-soft: #1f3a57;
  --error: #ff6b6b;
  --cur-usd: #4ec98a;
  --cur-jpy: #ff6b6b;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f3f6fa;
    --bg-card: #ffffff;
    --bg-input: #f3f6fa;
    --border: #d8e0ea;
    --border-focus: #2f7fe0;
    --text: #16202b;
    --text-dim: #6b7a8a;
    --accent: #2f7fe0;
    --accent-soft: #e3eefb;
    --error: #d64545;
    --cur-usd: #2e9e6a;
    --cur-jpy: #d64545;
    --shadow: 0 10px 30px rgba(20, 40, 70, 0.10);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

/* HEADER */
.app-header {
  border-bottom: 1px solid var(--border);
}
.app-header__inner {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.app-header__brand { display: flex; align-items: center; gap: 8px; }
.app-header__icon { display: block; width: 26px; height: 26px; border-radius: 22%; }
.app-header__name { font-size: 1.25rem; font-weight: 700; letter-spacing: 0.2px; }
.app-header__tagline { color: var(--text-dim); font-size: 0.9rem; font-weight: 600; }

/* MAIN */
.app-main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 28px 20px;
}
.card {
  width: 100%;
  max-width: 520px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* FIELD */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.field__input {
  font: inherit;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-align: left;
  /* iOS Safari's native date control ignores box-sizing and adds its padding
     OUTSIDE width:100%, overflowing the right edge. Stripping the native
     appearance makes it honor border-box. */
  -webkit-appearance: none;
  appearance: none;
}
/* keep the calendar picker button visible/clickable on desktop */
.field__input::-webkit-calendar-picker-indicator {
  margin-left: auto;
  cursor: pointer;
  opacity: 0.7;
}
/* iOS/WebKit centers the date value by default — force left alignment */
.field__input::-webkit-date-and-time-value { text-align: left; }
.field__input::-webkit-datetime-edit { text-align: left; }
.field__input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* CONVERTER */
.converter {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: stretch;
  gap: 12px;
}
.money {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}
.money__currency {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
}
.money__currency--usd { color: var(--cur-usd); }
.money__currency--jpy { color: var(--cur-jpy); }
.money__amount {
  font: inherit;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  background: transparent;
  border: none;
  width: 100%;
  padding: 0;
  min-width: 0;
}
.money__amount:focus { outline: none; }
.money__amount--result {
  display: block;
  white-space: nowrap; /* JS shrinks font-size to keep long results on one line */
}
/* hide number input spinners */
.money__amount[type="number"]::-webkit-outer-spin-button,
.money__amount[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none; margin: 0;
}
.money__amount[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* SWAP */
.swap {
  align-self: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--accent);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease;
  flex-shrink: 0;
}
.swap:hover { background: var(--accent-soft); border-color: var(--border-focus); }
.swap:active { transform: rotate(180deg); }
.swap:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

/* STATUS */
.status {
  margin: 0;
  min-height: 1.2em;
  font-size: 0.9rem;
  color: var(--text-dim);
  text-align: center;
}
.status--error { color: var(--error); }
.status--loading { opacity: 0.7; }

/* FOOTER */
.app-footer {
  border-top: 1px solid var(--border);
  text-align: center;
  padding: 16px 20px;
  font-size: 0.8rem;
  color: var(--text-dim);
}
.app-footer a { color: var(--text-dim); }
.app-footer a:hover { color: var(--accent); }

/* MOBILE */
@media (max-width: 480px) {
  .converter {
    grid-template-columns: 1fr;
  }
  .swap {
    justify-self: center;
  }
  .swap:active { transform: rotate(90deg); }
  .card { padding: 18px; }
  .money__amount { font-size: 1.35rem; }
}
