/* ============================================================
   Re:Turn Dashboard — Light / Fresh Theme
   Accent: #06C755 (LINE Green)
   ============================================================ */

/* --- CSS Variables -------------------------------------- */
:root {
  --main-green: #06c755;
  --light-green: #f0fdf4;
  --border-green: #b9f6ca;
  --bg-color: #f7f9fa;
  --panel-bg: #ffffff;
  --text-main: #111111;
  --text-muted: #666666;
  --border-light: #edf2f7;
  --tab-bar-h: 64px;
}

/* --- Reset & Base --------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Montserrat', 'Noto Sans JP', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
}

img {
  display: block;
  max-width: 100%;
}

/* --- Utility: Hidden ------------------------------------ */
.hidden {
  display: none !important;
}

/* --- Loading Overlay ------------------------------------ */
#loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--panel-bg);
  z-index: 9999;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-light);
  border-top-color: var(--main-green);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

.loading-text {
  margin-top: 18px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.04em;
}

/* --- App Shell ------------------------------------------ */
#app {
  max-width: 480px;
  margin: 0 auto;
  /* bottom padding = tab bar height + safe area */
  padding: 20px 18px calc(var(--tab-bar-h) + 16px);
}

/* --- Header --------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0 18px;
  border-bottom: 2px solid var(--main-green);
  margin-bottom: 24px;
}

.header-brand {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.brand-title {
  font-size: 1.7rem;
  font-weight: 900;
  color: var(--main-green);
  letter-spacing: 0.06em;
  font-family: 'Montserrat', sans-serif;
  text-shadow: 0 6px 16px rgba(6, 199, 85, 0.15);
  line-height: 1;
}

.header-subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1;
  padding-bottom: 2px;
}

.btn-lang-toggle {
  background: none;
  border: 1px solid var(--border-green);
  border-radius: 99px;
  padding: 5px 12px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  font-family: 'Montserrat', 'Noto Sans JP', sans-serif;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  transition: color 0.2s, border-color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.btn-lang-toggle:hover {
  color: var(--main-green);
  border-color: var(--main-green);
}

/* --- Tab Panels ----------------------------------------- */
.tab-panel {
  /* visible by default unless .hidden */
}

/* --- Bottom Tab Bar ------------------------------------- */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-bar-h);
  background: var(--panel-bg);
  border-top: 1px solid var(--border-light);
  display: flex;
  align-items: stretch;
  z-index: 100;
  /* safe area for notch phones */
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.06);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 4px;
  color: var(--text-muted);
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}

.tab-btn.active {
  color: var(--main-green);
}

.tab-btn.active::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 2px;
  background: var(--main-green);
  border-radius: 2px 2px 0 0;
}

.tab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  line-height: 1;
}

.tab-label {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* --- Cards (shared) ------------------------------------- */
.card {
  background: var(--panel-bg);
  border-radius: 20px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.03);
  border: 1px solid var(--border-light);
  transition: box-shadow 0.3s;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0.01em;
}

/* --- Profile Card --------------------------------------- */
.profile-card {
  background: var(--light-green);
  border: 2px solid var(--border-green);
}

.profile-top {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.avatar-wrapper {
  flex-shrink: 0;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  overflow: hidden;
  border: 3px solid var(--main-green);
  background: #d4fcdc;
  box-shadow: 0 8px 20px rgba(6, 199, 85, 0.12);
}

.avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-info {
  min-width: 0;
}

.name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-edit-name {
  background: var(--panel-bg);
  border: 1px solid var(--border-green);
  border-radius: 99px;
  cursor: pointer;
  font-size: 0.6rem;
  font-weight: 700;
  color: var(--text-muted);
  padding: 3px 8px;
  line-height: 1.4;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: 'Montserrat', sans-serif;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.2s, border-color 0.2s;
}

.btn-edit-name:hover {
  color: var(--main-green);
  border-color: var(--main-green);
}

.user-name {
  font-size: 1.25rem;
  font-weight: 900;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.02em;
}

.user-id {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Stats row — now 3 items */
.stats-row {
  display: flex;
  align-items: center;
  background: var(--panel-bg);
  border-radius: 14px;
  padding: 16px 0;
}

.stat-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.stat-value {
  font-size: 1.55rem;
  font-weight: 900;
  color: var(--main-green);
  font-family: 'Montserrat', sans-serif;
  line-height: 1.1;
}

.stat-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-divider {
  width: 1px;
  height: 36px;
  background: var(--border-green);
}

/* --- Eco Impact Card ------------------------------------ */
.eco-card {
  border: 1px solid var(--border-green);
}

/* Two-stat row: CO2 + Plastic */
.eco-stats-row {
  display: flex;
  align-items: center;
  background: var(--light-green);
  border-radius: 14px;
  padding: 16px 0;
  margin-bottom: 16px;
}

.eco-stat-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}

.eco-stat-value {
  font-size: 1.45rem;
  font-weight: 900;
  color: var(--main-green);
  font-family: 'Montserrat', sans-serif;
  line-height: 1.1;
}

.eco-stat-unit {
  font-size: 0.9rem;
  font-weight: 700;
  margin-left: 2px;
}

.eco-stat-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.eco-stat-divider {
  width: 1px;
  height: 36px;
  background: var(--border-green);
}

/* Metaphor block */
.eco-main {
  text-align: center;
  padding: 4px 0 16px;
}

.eco-metaphor-value {
  font-size: 2.8rem;
  font-weight: 900;
  color: var(--main-green);
  font-family: 'Montserrat', sans-serif;
  line-height: 1.1;
}

.eco-metaphor-label {
  font-size: 0.88rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 0;
}

/* Lifecycle progress */
.eco-bar-wrap {
  background: var(--border-light);
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
  margin-bottom: 8px;
}

.eco-bar {
  height: 100%;
  background: var(--main-green);
  border-radius: 99px;
  width: 0%;
  transition: width 1s ease-out;
}

.eco-cycle-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--main-green);
  font-family: 'Montserrat', sans-serif;
  margin-bottom: 10px;
}

.eco-caption {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
}

/* --- Borrow Card ---------------------------------------- */
.borrow-card {
  background: var(--panel-bg);
}

.borrow-empty {
  text-align: center;
  padding: 24px 10px;
}

.borrow-empty-icon {
  font-size: 2rem;
  font-weight: 900;
  color: var(--main-green);
  margin-bottom: 10px;
  font-family: 'Montserrat', sans-serif;
  line-height: 1;
}

.borrow-empty-text {
  font-size: 0.95rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.02em;
}

.borrow-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.borrow-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--light-green);
  border-radius: 14px;
  padding: 16px 18px;
  border: 1px solid var(--border-green);
  transition: transform 0.2s, box-shadow 0.2s;
}

.borrow-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(6, 199, 85, 0.08);
}

.borrow-item-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.borrow-container-id {
  font-size: 1.05rem;
  font-weight: 900;
  color: var(--text-main);
  letter-spacing: 0.02em;
  font-family: 'Montserrat', sans-serif;
}

.borrow-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
}

.borrow-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: #05a045;
  background: var(--panel-bg);
  padding: 5px 12px;
  border-radius: 20px;
  white-space: nowrap;
  border: 1px solid var(--border-green);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* --- Leaderboard Card ----------------------------------- */
.leaderboard-card {
  background: var(--panel-bg);
}

.btn-refresh {
  background: var(--light-green);
  border: 1px solid var(--border-green);
  color: #05a045;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 20px;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: background 0.2s;
}

.btn-refresh:hover {
  background: var(--border-green);
}

.lb-loading {
  text-align: center;
  padding: 32px 0;
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
}

.lb-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lb-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-color);
  border-radius: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border-light);
}

.lb-item.is-me {
  background: var(--light-green);
  border: 1px solid var(--border-green);
}

.lb-rank {
  font-size: 1.1rem;
  font-weight: 900;
  font-family: 'Montserrat', sans-serif;
  color: var(--text-muted);
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.lb-item:nth-child(1) .lb-rank { color: #f59e0b; }
.lb-item:nth-child(2) .lb-rank { color: #94a3b8; }
.lb-item:nth-child(3) .lb-rank { color: #b45309; }

.lb-name {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: 0.02em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lb-score {
  font-size: 1rem;
  font-weight: 900;
  color: var(--main-green);
  font-family: 'Montserrat', sans-serif;
  white-space: nowrap;
}

.lb-score-label {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-left: 3px;
}

.lb-total {
  text-align: center;
  margin-top: 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* --- Map Card ------------------------------------------- */
.map-card {
  background: var(--panel-bg);
}

/* Grid for photo cards — add more .map-photo-item as needed */
.map-photo-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.map-photo-item img {
  width: 100%;
  border-radius: 12px;
  display: block;
  object-fit: cover;
}

.map-photo-caption {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  margin-top: 6px;
  letter-spacing: 0.02em;
}

.map-placeholder-text {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
  text-align: center;
  padding: 24px 0;
}

/* --- Toast ---------------------------------------------- */
.toast {
  position: fixed;
  bottom: calc(var(--tab-bar-h) + 12px);
  left: 16px;
  right: 16px;
  max-width: 480px;
  margin: 0 auto;
  background: #111111;
  color: #ffffff;
  padding: 15px 20px;
  border-radius: 14px;
  font-size: 0.88rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.15);
  animation: slideUp 0.3s ease-out;
  z-index: 1000;
  cursor: pointer;
}

@keyframes slideUp {
  from { transform: translateY(24px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

/* --- Responsive ----------------------------------------- */
@media (min-width: 481px) {
  #app {
    padding: 24px 24px calc(var(--tab-bar-h) + 20px);
  }
  .user-name { font-size: 1.35rem; }
  .card { padding: 28px; }
  .stat-value { font-size: 1.75rem; }
}

@media (min-width: 768px) {
  #app {
    padding: 32px 0 calc(var(--tab-bar-h) + 32px);
  }
}

/* --- Inline Spinner (borrow / leaderboard loading) ------ */
.inline-loading {
  display: flex;
  justify-content: center;
  padding: 32px 0;
}

.inline-spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border-light);
  border-top-color: var(--main-green);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

/* --- Edit Name Modal ------------------------------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(240, 253, 244, 0.92);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  opacity: 0;
  transition: opacity 0.2s ease-out;
}

.modal-overlay.visible {
  opacity: 1;
}

.modal-card {
  background: var(--panel-bg);
  border-radius: 20px;
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 60px rgba(6, 199, 85, 0.15);
  border: 1px solid var(--border-green);
  transform: translateY(16px);
  transition: transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.modal-overlay.visible .modal-card {
  transform: translateY(0);
}

.modal-title {
  font-size: 1rem;
  font-weight: 900;
  color: var(--text-main);
  margin-bottom: 16px;
  letter-spacing: 0.02em;
}

.modal-input {
  width: 100%;
  border: 2px solid var(--border-green);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  font-weight: 700;
  font-family: 'Montserrat', sans-serif;
  color: var(--text-main);
  background: var(--light-green);
  outline: none;
  box-sizing: border-box;
  margin-bottom: 18px;
  transition: border-color 0.2s;
}

.modal-input:focus {
  border-color: var(--main-green);
  background: #fff;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

.modal-btn-cancel {
  flex: 1;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border-light);
  background: var(--bg-color);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
  letter-spacing: 0.03em;
  transition: background 0.2s;
}

.modal-btn-cancel:hover {
  background: var(--border-light);
}

.modal-btn-confirm {
  flex: 2;
  padding: 12px;
  border-radius: 12px;
  border: none;
  background: var(--main-green);
  font-size: 0.85rem;
  font-weight: 900;
  color: #fff;
  cursor: pointer;
  font-family: 'Montserrat', sans-serif;
  letter-spacing: 0.04em;
  transition: opacity 0.2s;
}

.modal-btn-confirm:hover {
  opacity: 0.88;
}

.modal-btn-confirm:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
