/* ========== Root Variables ========== */
:root {
    --font-family: 'Vazirmatn', Tahoma, Arial, sans-serif;
    --bg-color: #ffffff;
    --text-color: #3E3D3B;
    --highlight-color: #FE2828;
    --secondary-color: #929292;
    --clock-color: #34445A;
}

/* ========== Global Styles & Resets ========== */
*,
*::before,
*::after {
    /* A good practice for more predictable layouts */
    box-sizing: border-box;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-color);
    text-align: center;
    margin: 0;
    /* FIX 1: Added horizontal padding.
      This creates space between the content and the edges of the screen,
      which is especially important on smaller devices. I've used 1.5rem 
      for a flexible space that scales with the root font size.
    */
    padding: 1rem 1.5rem;
    min-height: 100vh;
    /* Ensures body takes full viewport height */
}

/* ========== Typography ========== */

.header {
    font-size: 2.5rem;
    font-weight: bold;
    margin: 0 0 30px;
}

.display1 {
    font-size: 3.5rem;
    font-weight: bold;
    color: var(--highlight-color);
    margin-bottom: 10px;
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
    transition: all 0.3s ease-out;
    /*
      FIX 2: Prevent the number from wrapping to a new line.
      If the number is too long for the screen, it will be hidden
      and an ellipsis (...) will be shown.
    */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.currency,
.unit {
    font-size: 1.4rem;
    color: var(--secondary-color);
    margin-bottom: 10px;
}

.date-time {
    font-size: 1.2rem;
    color: var(--clock-color);
    margin-bottom: 10px;
    font-variant-numeric: tabular-nums;
}

.spelled-out-number {
    font-size: 1.5rem;
    color: var(--secondary-color);
    margin-top: 5px;
    min-height: 1.5em;
    /* Prevents layout shift when content appears */
    font-variant-numeric: tabular-nums;
    /*
      FIX 3: Added overflow-wrap.
      This will allow long words (like a large number spelled out)
      to break and wrap onto the next line, preventing horizontal scrollbars.
    */
    overflow-wrap: break-word;
    word-wrap: break-word;
    /* for older browser compatibility */
}

.spelled-out-number .num-part {
    display: inline-block;
    min-width: 3.5ch;
    text-align: right;
    direction: ltr;
}

/* ========== Layout ========== */

.date-time {
    display: flex;
    align-items: center;
    justify-content: center;
    /* Ensures it stays centered in all layouts */
    gap: 12px;
}

.title-container {
    margin-top: 20px;
}

.top-bar {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 80px;
    font-size: 1rem;
    padding-top: 10px;
    flex-wrap: wrap;
    /* Allows items to wrap on smaller screens if needed */
}

.value-row {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    direction: rtl;
}

.value-row .currency {
    order: 2;
}

.value-row .display1 {
    order: 1;
}


/* ========== Responsive ========== */

/* For Large Desktops */
@media screen and (max-width: 1200px) {
    .header {
        font-size: 1.8rem;
    }

    .display1 {
        font-size: 2.5rem;
    }
}

/* For Desktops and Laptops */
@media screen and (max-width: 992px) {
    .header {
        font-size: 1.6rem;
    }

    .display1 {
        font-size: 2.2rem;
    }

    .currency,
    .unit,
    .date-time {
        font-size: 1.2rem;
    }
}

/* For Tablets */
@media screen and (max-width: 768px) {
    .header {
        font-size: 1.5rem;
    }

    .display1 {
        /* FIX: Reduced font size */
        font-size: 1.8rem;
    }

    .currency,
    .unit,
    .date-time {
        font-size: 1.1rem;
    }

    .spelled-out-number {
        font-size: 1rem;
    }
}

/* For Mobile Phones */
@media screen and (max-width: 480px) {
    body {
        /* Reduce padding slightly on the smallest screens to maximize space */
        padding: 1rem 1rem;
    }

    .top-bar {
        flex-direction: column;
        gap: 8px;
    }

    .header {
        font-size: 1.3rem;
    }

    .display1 {
        /* FIX: Reduced font size */
        font-size: 1.4rem;
    }

    .currency,
    .unit,
    .date-time {
        font-size: 1rem;
    }

    .spelled-out-number {
        font-size: 0.8rem;
    }
}

/* For Small Mobile Phones */
@media screen and (max-width: 320px) {
    .header {
        font-size: 1.2rem;
    }

    .display1 {
        /* FIX: Reduced font size */
        font-size: 1.2rem;
    }

    .currency,
    .unit,
    .date-time {
        font-size: 0.9rem;
    }
}