:root {
  --bg0: #0c1a24;
  --bg1: #143044;
  --ink: #e8f1f6;
  --muted: #8aa3b5;
  --accent: #2bb673;
  --warn: #e0a106;
  --danger: #d64545;
  --panel: rgba(20, 42, 58, 0.88);
  --line: rgba(232, 241, 246, 0.12);
  --font-display: "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  --font-body: "Segoe UI", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
  --tap: 44px;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(1200px 600px at 10% -10%, #1e4d6b 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #0f3d32 0%, transparent 50%),
    linear-gradient(160deg, var(--bg0), var(--bg1));
}

.page {
  max-width: 820px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3.5rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(3.5rem, env(safe-area-inset-bottom));
}

.auth-page {
  max-width: 420px;
  padding-top: 2.5rem;
}

.hero {
  margin-bottom: 1.35rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.user-name {
  font-size: 0.8rem;
  color: var(--muted);
  max-width: min(52vw, 14rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-form { margin: 0; }

a.link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  min-height: 36px;
  font-weight: 600;
  font-size: 0.8rem;
  -webkit-tap-highlight-color: transparent;
}

.danger-zone h2 {
  color: var(--danger);
}

.brand {
  margin: 0;
  font-size: clamp(1.45rem, 5vw, 1.75rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--accent);
  font-family: var(--font-display);
}

.hero h1 {
  margin: 0 0 0.5rem;
  font-size: clamp(1.15rem, 4.2vw, 1.35rem);
  font-weight: 600;
}

.lede {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
  max-width: 36rem;
  font-size: 0.95rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.1rem 1.15rem;
  margin-bottom: 1rem;
  backdrop-filter: blur(6px);
}

.panel h2 {
  margin: 0 0 0.9rem;
  font-size: 1.05rem;
}

.row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.row-head h2 { margin: 0; }

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 1rem;
  line-height: 1.45;
  word-break: keep-all;
}

.add-form,
.inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
}

.grow { flex: 1 1 10rem; min-width: 0; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

input {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
  color: var(--ink);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  min-width: 0;
  width: 100%;
  font-size: 16px;
  max-width: 100%;
}

input:focus {
  outline: 2px solid rgba(43, 182, 115, 0.45);
  border-color: var(--accent);
}

button {
  background: var(--accent);
  color: #062016;
  border: none;
  border-radius: 8px;
  padding: 0.7rem 1rem;
  min-height: var(--tap);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:hover { filter: brightness(1.08); }

button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(214, 69, 69, 0.45);
}

button.small {
  min-height: 36px;
  padding: 0.35rem 0.7rem;
  font-size: 0.8rem;
}

button.btn-block {
  width: 100%;
  margin-top: 0.35rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.auth-switch {
  margin: 1.1rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.auth-switch a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

.stock-list,
.alert-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.stock-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--line);
}

.time-row {
  justify-content: space-between;
  align-items: center;
}

.ticker {
  font-weight: 700;
  min-width: 4.5rem;
  letter-spacing: 0.03em;
  word-break: break-word;
}

.alert-list li {
  padding: 0.85rem 0;
  border-top: 1px solid var(--line);
}

.alert-list p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  word-break: break-word;
  white-space: pre-wrap;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: rgba(43, 182, 115, 0.2);
  color: var(--accent);
  margin-right: 0.4rem;
}

.when {
  color: var(--muted);
  font-size: 0.8rem;
  margin-left: 0.5rem;
  word-break: break-all;
}

.empty { color: var(--muted); margin: 0; }

.banner {
  padding: 0.65rem 0.9rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
  word-break: keep-all;
}

.banner.ok {
  background: rgba(43, 182, 115, 0.15);
  border: 1px solid rgba(43, 182, 115, 0.35);
}

.banner.err {
  background: rgba(214, 69, 69, 0.12);
  border: 1px solid rgba(214, 69, 69, 0.35);
}

.tag {
  display: inline-block;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-size: 0.75rem;
}

.tag.ok { background: rgba(43, 182, 115, 0.2); color: var(--accent); }
.tag.warn { background: rgba(224, 161, 6, 0.2); color: var(--warn); }

.fx-rate {
  margin: 0 0 0.5rem;
  font-size: clamp(1.05rem, 4vw, 1.25rem);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: baseline;
}

.stock-main {
  min-width: 0;
  flex: 1 1 100%;
}

.sym-sub {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 0.1rem;
}

.price-line {
  margin-top: 0.35rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.65rem;
  align-items: baseline;
}

.price {
  font-weight: 700;
  font-size: 1.1rem;
}

.chg {
  font-size: 0.95rem;
  font-weight: 600;
}

.chg.up { color: #ff6b6b; }
.chg.down { color: #6db3ff; }

body.modal-open { overflow: hidden; }

.modal[hidden] { display: none; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
  padding: 0;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(4, 12, 18, 0.72);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: min(88dvh, 640px);
  overflow: auto;
  background: #122838;
  border: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  padding: 1.1rem 1.1rem max(1.25rem, env(safe-area-inset-bottom));
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  -webkit-overflow-scrolling: touch;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.modal-head h2 {
  margin: 0;
  font-size: 1.1rem;
}

.search-label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.search-label input {
  width: 100%;
}

.search-results {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}

.search-results li {
  border-top: 1px solid var(--line);
}

.search-item {
  width: 100%;
  display: grid;
  grid-template-columns: 5.5rem 1fr auto;
  gap: 0.6rem;
  align-items: center;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border: none;
  border-radius: 0;
  padding: 0.85rem 0.25rem;
  min-height: var(--tap);
  font-weight: 500;
  cursor: pointer;
}

.search-item:hover {
  background: rgba(43, 182, 115, 0.1);
  filter: none;
}

.search-item .sym {
  font-weight: 700;
  color: var(--accent);
}

.search-item .nm {
  color: var(--ink);
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-item .ex {
  color: var(--muted);
  font-size: 0.75rem;
}

@media (min-width: 640px) {
  .page { padding: 2.5rem 1.25rem 4rem; }
  .modal { place-items: center; padding: 1rem; }
  .modal-card {
    border-radius: 14px;
    width: min(520px, 100%);
  }
  .stock-main {
    flex: 1 1 10rem;
    min-width: 9rem;
  }
}

@media (max-width: 639px) {
  .stack-mobile {
    flex-direction: column;
    align-items: stretch;
  }

  .stack-mobile .btn-row,
  .stack-mobile button {
    width: 100%;
  }

  .stock-card {
    flex-direction: column;
    align-items: stretch;
  }

  .stock-card .delete-form button {
    width: 100%;
  }

  .search-item {
    grid-template-columns: 1fr;
    gap: 0.15rem;
  }

  .user-name { max-width: 5.5rem; }
}

/* ── mail-like mobile UI ───────────────────────────────────────── */

.mail-ui {
  max-width: 440px;
  padding-top: 1rem;
}

.mail-header {
  margin-bottom: 1rem;
}

.mail-header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.mail-sub {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.9rem 1rem 1rem;
  margin-bottom: 0.85rem;
}

.mail-card h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
}

.mail-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.55rem;
}

.mail-card-row.fx {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
}

.mail-label {
  color: var(--muted);
  font-size: 0.85rem;
}

.mail-value {
  font-size: 1.15rem;
}

.mail-hint {
  margin: 0.4rem 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  word-break: break-all;
}

.time-add {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
}

.time-add input {
  flex: 1;
  min-width: 0;
}

.time-add button {
  flex-shrink: 0;
  min-height: 40px;
  padding: 0.5rem 0.9rem;
}

.chip-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.35rem 0.35rem 0.35rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: 0.9rem;
}

.chip form { margin: 0; }

.chip-x {
  background: transparent !important;
  color: var(--muted) !important;
  border: none !important;
  min-height: 28px !important;
  padding: 0 0.45rem !important;
  font-size: 1.1rem !important;
  font-weight: 500 !important;
  line-height: 1;
}

.chip-x:hover { color: var(--danger) !important; filter: none; }

.inbox {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
}

.inbox-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 0;
  border-top: 1px solid var(--line);
}

.inbox-row:first-child { border-top: none; padding-top: 0.35rem; }

.inbox-main { min-width: 0; flex: 1; }

.inbox-title {
  font-weight: 700;
  font-size: 1rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.inbox-title .name-link {
  color: inherit;
  font-weight: inherit;
}

.inbox-sub {
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 0.15rem;
}

.ticker-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.ticker-link:hover,
.ticker-link:active {
  text-decoration: underline;
}

.inbox-right {
  text-align: right;
  flex-shrink: 0;
  position: relative;
  padding-right: 1.4rem;
}

.inbox-price {
  font-weight: 700;
  font-size: 0.95rem;
}

.inbox-chg {
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 0.15rem;
}

.inbox-chg.up { color: #ff6b6b; }
.inbox-chg.down { color: #6db3ff; }

.inbox-del {
  position: absolute;
  top: -0.15rem;
  right: -0.35rem;
  margin: 0;
}

.inbox-row.compact { padding: 0.65rem 0; }
.alert-inbox .inbox-title { font-size: 0.9rem; font-weight: 600; }
