:root {
    --bg-color: #000000;
    --text-primary: #ffffff;
    --text-secondary: #8e8e93;
    --highlight: #ff9500;
    --separator: #38383a;
    --modal-bg: #1c1c1e;
    --search-bg: #2c2c2e;
    --danger: #ff453a;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    padding-top: max(16px, env(safe-area-inset-top));
    border-bottom: 1px solid var(--separator);
    position: sticky;
    top: 0;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    z-index: 10;
}

.header-title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.header-btn {
    background: none;
    border: none;
    color: var(--highlight);
    font-size: 17px;
    cursor: pointer;
    min-width: 80px;
    text-align: left;
}

#edit-btn {
    text-align: left;
}

.header-btn.highlight {
    font-size: 32px;
    font-weight: 300;
    line-height: 1;
    text-align: right;
}

/* Clock List */
.clock-list {
    padding: 0 20px;
    padding-bottom: 80px;
}

.clock-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Center items vertically */
    padding: 20px 0;
    border-bottom: 1px solid var(--separator);
    position: relative;
    transition: transform 0.3s ease;
    user-select: none;
    -webkit-user-select: none;
    flex-wrap: nowrap;
    /* Prevent wrapping completely */
}

.clock-item:last-child {
    border-bottom: none;
}

.clock-info {
    display: flex;
    flex-direction: column;
    transition: transform 0.3s;
    flex-grow: 1;
    max-width: calc(50% - 70px);
    /* 中央の日付と重なるのを防ぐため */
}

.offset-date {
    font-size: 15px;
    color: var(--text-secondary);
}

.city-name {
    font-size: 20px;
    /* 少し小さく */
    font-weight: 400;
    letter-spacing: -0.5px;
}

.top-row-info {
    display: flex;
    align-items: center;
    gap: 8px;
    /* 時差と気温の間隔 */
}

.temp-display {
    font-size: 15px;
    /* 時差文字列（.offset-date）に合わせる */
    font-weight: 400;
    color: var(--text-secondary);
}

.right-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    /* 右端に揃える */
    justify-content: center;
    flex-shrink: 0;
    margin-top: -6px;
}

.offset-container {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: -4px;
    /* 時刻との間に僅かな空間を作る */
    position: relative;
    z-index: 1;
    /* 時刻の数字の上にくるように */
}

.small-flag {
    font-size: 13px;
    /* 小さめ */
}

.date-display {
    position: absolute;
    left: 50%;
    transform: translateX(calc(-50% + 35px));
    /* 全体の中央から右に寄せて時間とのまとまりを出す */
    font-size: 24px;
    font-weight: 400;
    /* Match city-name */
    letter-spacing: -0.5px;
    white-space: nowrap;
    margin-top: 14px;
    /* 時計のベースラインと体感的に揃える */
    transition: transform 0.3s ease;
    /* 編集モードでのスライドを滑らかにするため */
}

.time-display {
    font-size: 40px;
    /* 日付よりは大きく、以前より小さく */
    font-weight: 200;
    font-variant-numeric: tabular-nums;
    letter-spacing: -1px;
}

.city-flag {
    margin-left: 8px;
    font-size: 24px;
    vertical-align: middle;
}

/* Delete button in edit mode */
.delete-btn {
    position: absolute;
    left: -50px;
    width: 24px;
    height: 24px;
    background-color: var(--danger);
    color: white;
    border-radius: 50%;
    border: none;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease, left 0.3s ease;
}

.edit-mode .clock-item {
    transform: translateX(40px);
}

.edit-mode .delete-btn {
    opacity: 1;
    left: -40px;
}

/* Edit Mode Toggles for iOS style reordering */
.drag-handle {
    position: absolute;
    right: 20px;
    font-size: 24px;
    color: #666;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    cursor: grab;
    touch-action: none;
    /* iOSでのスクロール干渉を防ぐ */
}

.drag-handle:active {
    cursor: grabbing;
}

.edit-mode .drag-handle {
    opacity: 1;
    pointer-events: auto;
}

.edit-mode .date-display,
.edit-mode .right-container {
    opacity: 0;
    pointer-events: none;
}

/* Responsiveness for smaller phones (e.g. iPhone 12 Pro, SE) */
@media (max-width: 400px) {
    .header-title {
        font-size: 15px;
        white-space: nowrap;
    }

    .clock-item {
        padding: 12px 14px;
    }

    .city-name {
        font-size: 16px;
    }

    .date-display {
        font-size: 18px;
        transform: translateX(calc(-50% + 20px));
        margin-top: 10px;
    }

    .time-display {
        font-size: 32px;
    }

    .offset-date,
    .temp-display {
        font-size: 13px;
    }

    .edit-mode .date-display {
        transform: translateX(0);
        /* Hide better on small screens */
    }
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--modal-bg);
    z-index: 100;
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
}

.modal.hidden {
    transform: translateY(100%);
}

.modal-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    padding-top: max(16px, env(safe-area-inset-top));
    background-color: var(--modal-bg);
}

.modal-title {
    font-size: 17px;
    font-weight: 600;
    text-align: center;
}

#cancel-add-btn {
    color: var(--highlight);
    text-align: left;
}

.search-bar-container {
    padding: 10px 20px;
    background-color: var(--modal-bg);
    border-bottom: 1px solid var(--separator);
}

.search-bar {
    width: 100%;
    background-color: var(--search-bg);
    border: none;
    border-radius: 10px;
    padding: 10px 36px 10px 12px;
    color: var(--text-primary);
    font-size: 17px;
    outline: none;
}

.search-bar::placeholder {
    color: var(--text-secondary);
}

.city-search-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    padding: 0 20px;
}

.search-list-item {
    padding: 16px 0;
    border-bottom: 1px solid var(--separator);
    font-size: 17px;
    cursor: pointer;
}

/* iOS-style Section Headers */
.search-section-header {
    position: sticky;
    top: 0;
    background-color: var(--modal-bg);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    padding: 8px 0;
    margin-top: 10px;
    border-bottom: 1px solid var(--separator);
    z-index: 2;
    /* slightly transparent to blur underneath like iOS */
    backdrop-filter: blur(10px);
    background-color: rgba(28, 28, 30, 0.85);
}



/* Footer (Edit Mode) */
.edit-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 16px 20px;
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    text-align: center;
    color: var(--text-secondary);
    font-size: 13px;
    z-index: 10;
    border-top: 1px solid var(--separator);
}

.edit-footer.hidden {
    display: none;
}

/* --- SortableJS iOS Drag-and-Drop Styles --- */
/* The placeholder left behind in the list while dragging */
.sortable-ghost {
    opacity: 0.3;
    background-color: var(--hover-color);
}

/* The element currently following the user's finger/cursor */
.sortable-drag {
    background-color: var(--card-bg) !important;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5) !important;
    opacity: 0.95 !important;
    z-index: 9999 !important;
    border-radius: 8px;
    cursor: grabbing !important;
    /* Styles needed because fallbackOnBody places this outside the clock-list container */
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    padding: 20px 20px !important;
    box-sizing: border-box !important;
}

/* Required for forceFallback to ensure the original doesn't look weird while cloning */
.sortable-fallback {
    transition: none !important;
}