@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

html, body {
    height: 100%;
    /* iOS safe area support */
    height: 100vh;
    height: -webkit-fill-available;
    overflow: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain; /* Prevents pull-to-refresh */
    overscroll-behavior-x: contain;
    /* Prevent iOS bounce effect */
    position: fixed;
    width: 100%;
    -webkit-tap-highlight-color: transparent; /* Remove tap highlight on iOS */
}

:root {
    --primary-color: #FFCD09;
    --background-color: #f4f4f4;
    --card-bg-color: #ffffff;
    --text-color: #333333;
    --light-text-color: #777777;
}

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

body {
    font-family: 'Roboto', sans-serif;
    /* background-color: #cccccc; */ /* No longer needed */
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.mobile-container {
    width: 100%;
    max-width: 400px;
    height: 100%; /* Changed from min-height: 100vh */
    height: 100vh;
    height: -webkit-fill-available;
    background-color: var(--background-color);
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

/* Header */
.header {
    background-color: var(--primary-color);
    padding: 15px;
    /* iOS safe area support for notch */
    padding-top: max(15px, env(safe-area-inset-top));
    padding-left: max(15px, env(safe-area-inset-left));
    padding-right: max(15px, env(safe-area-inset-right));
    display: flex;
    align-items: center;
    /* 基于测量: 488px / 2868px ≈ 17vh, 减去下方内容上移的遮挡效果 */
    min-height: calc(17vh + env(safe-area-inset-top));
    height: calc(17vh + env(safe-area-inset-top));
    position: relative;
    z-index: 1;
}

.header .logo {
    flex: 1;
    display: flex;
    justify-content: center;
}

.header .logo img {
    height: 35px;
    opacity: 0.2;
    object-fit: contain;
    filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.3));
}


.menu-btn {
    background: none;
    border: none;
    color: #000000;
    cursor: pointer;
    position: absolute;
    right: max(15px, env(safe-area-inset-right));
    z-index: 1002;
    transition: all 0.2s ease;
}

/* 卡片打开时按钮为浅黑色 */
.menu-btn.card-open {
    color: #888888;
}

.menu-btn:active {
    transform: scale(0.95);
}

.menu-btn svg {
    width: 28px;
    height: 28px;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.1));
}

/* Main Content */
.main-content {
    flex-grow: 1;
    padding: 20px;
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    /* 让内容向上覆盖黄色header */
    margin-top: -8vh;
    position: relative;
    z-index: 10;
}

.profile-card {
    background-color: var(--card-bg-color);
    border-radius: 16px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    /* 浅灰色边框 */
    border: 1px solid #cccccc;
    /* 基于测量: 宽度90.6% (1196/1320) */
    width: 90.6%;
    max-width: 100%;
    margin: 0 auto;
    /* 基于测量: 高度约21vh (603/2868) */
    min-height: 21vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.profile-pic {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    overflow: hidden;
    margin: 0 auto 15px;
    border: 3px solid var(--primary-color);
}

.profile-pic img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-card h1 {
    font-size: 1.2rem;
    color: var(--text-color);
    margin-bottom: 5px;
}

.profile-card p {
    font-size: 0.9rem;
    color: var(--light-text-color);
}

.balance-card {
    background-color: var(--card-bg-color);
    border-radius: 16px;
    margin-top: 15px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    overflow: hidden;
    /* 浅灰色边框 */
    border: 1px solid #cccccc;
    /* 基于测量: 宽度90.6% (1196/1320) */
    width: 90.6%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    /* 基于测量: 高度约6.5vh (186/2868) */
    min-height: 6.5vh;
}

.balance-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    font-size: 1rem;
    color: var(--text-color);
}

.balance-label {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-color);
}

.balance-value-container {
    display: flex;
    align-items: center;
    gap: 8px;
}

.balance-amount {
    color: #427B00;
    font-weight: 600;
    font-size: 1.1rem;
}

.balance-arrow {
    color: #666666;
    font-size: 1.5rem;
    font-weight: 300;
}

/* Bottom Navigation */
.bottom-nav {
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    background-color: var(--primary-color);
    border-top: none;
    /* 基于测量: 总高度约9vh (255/2868), 内容区5vh (144/2868) */
    min-height: calc(5vh + env(safe-area-inset-bottom));
    padding-top: 12px;
    /* iOS safe area support for home indicator - 额外空白区域 */
    padding-bottom: max(calc(4vh), env(safe-area-inset-bottom));
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
    box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
    position: relative;
    z-index: 1001;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: rgba(0, 0, 0, 0.4);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 10px 24px;
    border-radius: 16px;
    transition: all 0.3s ease;
    position: relative;
    min-width: 90px;
}

.nav-item.active {
    color: #000000;
    background-color: rgba(0, 0, 0, 0.15);
}

.nav-item:hover {
    background-color: rgba(0, 0, 0, 0.08);
}

.nav-item.active:hover {
    background-color: rgba(0, 0, 0, 0.2);
}

.nav-item svg {
    margin-bottom: 6px;
    width: 24px;
    height: 24px;
}

/* Card Overlay */
.card-overlay {
    position: fixed;
    /* 基于测量: 展开时顶部黄色304px / 2868px ≈ 10.6vh */
    top: calc(10.6vh + env(safe-area-inset-top));
    left: 0;
    width: 100%;
    /* 计算高度: 总高度 - 顶部 - 导航栏，确保不被导航栏遮挡 */
    /* 减去额外的2vh作为安全边距，确保底部文字完全可见 */
    height: calc(100vh - 10.6vh - env(safe-area-inset-top) - 9vh - env(safe-area-inset-bottom) - 2vh);
    max-height: 80.5vh;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    z-index: 900;
    /* 初始状态：向上隐藏在顶部黄色栏后面 */
    transform: translateY(-100%);
    transition: transform 0.4s ease-out;
    /* 隐藏所有溢出，防止翻转时出现滚动条 */
    overflow: hidden;
    box-sizing: border-box;
    /* 隐藏状态下完全不可见 */
    visibility: hidden;
    opacity: 0;
    transition: transform 0.4s ease-out, visibility 0s 0.4s, opacity 0.3s ease-out;
    /* 底部留出额外空间，确保文字完全在导航栏上方 */
    padding-bottom: 2vh;
}

.card-overlay.show {
    /* 显示状态：下拉到正常位置 */
    transform: translateY(0);
    visibility: visible;
    opacity: 1;
    transition: transform 0.4s ease-out, visibility 0s 0s, opacity 0.3s ease-out;
}


.flip-instruction {
    color: var(--text-color);
    background-color: transparent;
    width: 100%;
    text-align: center;
    font-size: 0.95rem;
    line-height: 1.3;
    padding: 0 20px;
    /* 基于测量: 底部文字区域122px / 2868px ≈ 4.3vh */
    min-height: 3.5vh;
    /* 改用block布局，避免flex吞掉空格 */
    display: block;
    /* 垂直居中 */
    padding-top: 1vh;
    padding-bottom: 1vh;
    flex-shrink: 0;
    box-sizing: border-box;
    /* 确保文字区域始终固定在底部 */
    margin-top: auto;
    /* 留出额外的底部边距 */
    margin-bottom: 1vh;
    /* 确保文字在卡片翻转时不被遮挡 */
    position: relative;
    z-index: 10;
}

.flip-instruction strong {
    font-weight: 700;
}

/* Flip Card Mechanics */
.flip-card {
    background-color: transparent;
    perspective: 1000px;
    padding: 0;
    box-sizing: border-box;
    /* 卡片占据剩余空间，但留出底部文字区域 */
    flex-grow: 1;
    flex-shrink: 1;
    min-height: 0;
    /* 基于测量: 上边距37px / 2868px ≈ 1.3vh */
    padding-top: 1.3vh;
    /* 底部留出间距，避免翻转时压住文字 */
    padding-bottom: 1.5vh;
    /* 居中显示卡片 */
    display: flex;
    justify-content: center;
    align-items: flex-start;
    width: 100%;
    /* 防止翻转时溢出 */
    overflow: hidden;
}

.flip-card-inner {
    position: relative;
    /* 基于测量: 卡片比例 2148px / 1320px ≈ 1.627:1 */
    aspect-ratio: 1320 / 2148;
    /* 尽可能放大：使用height填满，width由aspect-ratio自动计算 */
    height: 100%;
    width: auto;
    max-width: 100%;
    transition: transform 0.6s;
    transform-style: preserve-3d;
    transform-origin: center center;
    display: grid;
    /* 移除阴影和圆角，保持卡片原始样式 */
    /* 防止翻转时超出边界 */
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.flip-card.flipped .flip-card-inner {
    transform: rotateY(180deg);
}

.flip-card-front, .flip-card-back {
    grid-area: 1 / 1; /* This stacks the elements in the same cell */
    width: 100%;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    /* border-radius: 10px; */ /* Removed */
    overflow: hidden;
}

.flip-card-front {
    background-color: #bbb;
    color: black;
}

.flip-card-back {
    background-color: #ccc;
    color: white;
    transform: rotateY(180deg);
}

.card-bg {
    width: 100%;
    height: auto; /* Changed */
    object-fit: cover;
    display: block; /* Fix small gap issue */
}

/* Settings Overlay Styles */
.settings-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--background-color);
    z-index: 2000;
    display: none; /* Hidden by default */
    flex-direction: column;
}

.settings-overlay.show {
    display: flex;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    background-color: var(--card-bg-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    flex-shrink: 0;
}

.settings-header h2 {
    font-size: 1.2rem;
    margin: 0;
}

#settings-close-btn {
    background: none;
    border: none;
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    color: var(--light-text-color);
}

.settings-content {
    padding: 20px;
    overflow-y: auto;
    flex-grow: 1;
}

.settings-group {
    margin-bottom: 30px;
    background-color: var(--card-bg-color);
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

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

.settings-group h3 {
    margin-top: 0;
    margin-bottom: 20px;
    font-size: 1rem;
    color: var(--text-color);
    border-bottom: 1px solid var(--background-color);
    padding-bottom: 10px;
}

/* Image Uploader */
.image-uploader {
    margin-bottom: 20px;
}
.image-uploader label {
    display: block;
    font-weight: 500;
    margin-bottom: 10px;
}
.image-uploader input[type="file"] {
    display: block;
    margin-bottom: 10px;
}
.image-uploader img {
    max-width: 100px;
    height: auto;
    border: 1px solid #ddd;
    border-radius: 5px;
    margin-bottom: 5px;
}
.image-uploader small {
    color: var(--light-text-color);
    font-size: 0.8rem;
}

/* Text Input */
.text-input {
    margin-bottom: 15px;
}
.text-input label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}
.text-input input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1rem;
}

/* Balance Hint */
.balance-hint {
    color: var(--light-text-color);
    font-size: 0.85rem;
    font-style: italic;
    margin: 0 0 15px 0;
    padding: 8px 12px;
    background-color: rgba(250, 185, 0, 0.1);
    border-left: 3px solid var(--primary-color);
    border-radius: 4px;
}

/* Reset Button and Hint */
.reset-hint {
    color: #e74c3c;
    font-size: 0.85rem;
    margin: 0 0 15px 0;
    padding: 8px 12px;
    background-color: rgba(231, 76, 60, 0.1);
    border-left: 3px solid #e74c3c;
    border-radius: 4px;
}

.reset-btn {
    width: 100%;
    padding: 12px 20px;
    background-color: #e74c3c;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.reset-btn:hover {
    background-color: #c0392b;
}

.reset-btn:active {
    transform: scale(0.98);
}

/* Setting Item (for toggle) */
.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.setting-item label {
    font-weight: 500;
}

/* Toggle Switch CSS */
.switch {
  position: relative;
  display: inline-block;
  width: 50px;
  height: 28px;
}

.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
}

.slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: .4s;
}

input:checked + .slider {
  background-color: var(--primary-color);
}

input:focus + .slider {
  box-shadow: 0 0 1px var(--primary-color);
}

input:checked + .slider:before {
  transform: translateX(22px);
}

.slider.round {
  border-radius: 34px;
}

.slider.round:before {
  border-radius: 50%;
}

/* Permanent Install Tip (always visible in Settings) */
.install-tip-permanent {
    background: linear-gradient(135deg, rgba(250, 185, 0, 0.15) 0%, rgba(255, 215, 0, 0.15) 100%);
    border-bottom: 2px solid rgba(250, 185, 0, 0.3);
    padding: 12px 15px;
    display: none; /* Hidden by default, shown only on iOS non-standalone */
}

.install-tip-permanent.show {
    display: block;
}

.install-tip-permanent p {
    margin: 0;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-color);
    text-align: center;
}

.install-tip-permanent strong {
    color: var(--primary-color);
    font-weight: 600;
}

.install-tip-permanent a {
    color: var(--primary-color);
    text-decoration: underline;
    font-weight: 500;
    cursor: pointer;
}

.install-tip-permanent a:hover {
    color: #d9a500;
}

