/* *********** GENERAL ************************************* */

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

:root {
    /* primary colors */
    --m-blue: hsl(238, 40%, 52%);
    --soft-red: hsl(358, 79%, 66%);
    --l-gray-blue: hsl(239, 57%, 85%);
    --pale-red: hsl(357, 100%, 86%);

    /* neutral colors */
    --d-blue: hsl(212, 24%, 26%); /* user name */
    --vl-gray: hsl(228, 33%, 97%); /* bg */
    /* --l-gray: hsl(223, 19%, 93%); based on the style guide */
    --gray-blue: hsl(211, 10%, 45%); /* text */
    --l-gray: hsl(228, 12%, 92%); /* for lines . seems better */
    --l-gray-l-blue: hsl(212, 7%, 64%);
}

body {
    background-color: var(--vl-gray);
    color: var(--gray-blue);
    font-family: Rubik, Arial, Helvetica, sans-serif;
    font-size: 1rem;
    font-size: max(1rem, 0.444vw + 0.6rem); /*fluid typography for large screens*/
    --scalerem: calc((100vw - 375em/16) / (768/16 - 375/16));
    --scalerpx: calc((100vw - 375px) / (768 - 375));
    padding-bottom: 300px;
}

main.post-box {
    margin: 0 auto;
    padding: 0 16px;
    max-width: 48em;
}

/* ********* COMMENTS SECTION  ************************** */

.comments {
    order: 2;
    display: flex;
    flex-direction: column;
    gap: 16px;
    gap: clamp(16px, 16px + var(--scalerpx)*4, 20px);
}

.post-box {
    padding-left: 16px;
    padding-left: clamp(16px, var(--scalerpx)*40, 40px);
    display: flex;
    flex-direction: column;
    gap: 16px;
    gap: clamp(16px, 16px + var(--scalerpx)*4, 20px);
}

.comments > .post-box {
    padding-left: 0px;
}

.post {
    padding: 16px;
    padding: clamp(16px, 16px + var(--scalerpx)*8, 24px);
    display: grid;
    grid-template-columns: 2em auto 1fr auto auto;
    gap: 16px;
    border-radius: 8px;
    align-items: center;
    background-color: white;
}

.post:not(.form) {
    order: 1;
}

.post.form.create.cmmnt {
    order: 3;
}

.post.form.create.cmmnt.reply {
    order: 2;
    margin-top: -8px;
}

.replies {
    order: 3;
    margin-left: clamp(0px, 40*var(--scalerpx), 40px);
    display: flex;
    flex-direction: column;
    gap: 16px;
    gap: clamp(16px, 16px + var(--scalerpx)*4, 20px);
    border-left: 2px solid var(--l-gray);
}

/* ********** COMMENT BOX  ************************** */

a {
    text-decoration: none;
    cursor: pointer;
}

a.avtr {
    width: 2em;
    height: 2em;
    display: block;
    grid-column: 1;
    grid-row: 1;
    border-radius: 20em;
    background-color: var(--pale-red);
}

a.avtr img {
    width: 100%;
}

span.usrnme-box {
    width: min-content;
    display: flex;
    gap: 8px;
    grid-column: 2;
    grid-row: 1;
}

a.usrnme {
    color: var(--d-blue);
    font-weight: 500;
}

a.user-role {
    padding: 2px 6px;
    font-size: 0.8em;
    background-color: var(--m-blue);
    color: white;
    border-radius: 2px;
}

a.user-role:active {
    background-color: var(--l-gray-blue);
}

a:is(.usrnme, .post-date):active {
    text-decoration: underline;
}

a.post-date {
    display: block;
    grid-column: 3 / -1;
    grid-row: 1;
}

p {
    line-height: 150%;
}

.post-main {
    grid-column: 1 / -1;
    grid-row: 2;
}

span.votes {
    width: fit-content;
    min-height: 40px;
    padding: 0px 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    grid-column: 1 / -1;
    grid-row: 3;
    background-color: var(--vl-gray);
    text-align: center;
    border-radius: 12px;
}

span.score {
    padding: 4px;
    display: block;
    color: var(--m-blue);
    font-weight: 500;
}

button {
    font-size: 1em;
    font-family: Rubik, Arial, Helvetica, sans-serif;
    background-color: transparent;
    border: 0.1px solid transparent;
    outline: none;
    box-sizing: border-box;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.vote-btn {
    padding: 4px;
    display: block;
    line-height: 85%;
    font-size: 1.2em;
    font-weight: 700;
    color: var(--l-gray-blue);
}

.vote-btn:active {
    color: var(--m-blue);
}

.small-btn {
    width: fit-content; /* Should I delete this? Check in the modal*/
    display: block;
    font-weight: 500;
    color: var(--m-blue);
}

.small-btn:active {
    color: var(--l-gray-blue);
}

.small-btn.del {
    grid-column: 1 / -2;
    grid-row: 3;
    justify-self: end;
    color: var(--soft-red);
}

.small-btn.del:active {
    color: var(--pale-red);
}

.small-btn.reply, .small-btn.edit {
    grid-column: -2 / -1;
    grid-row: 3;
}

.post:not(.form) :is(.big-btn, .small-btn.cncl, textarea) {
    display: none;
}

.small-btn i {
    font-size: 0.8rem;
    margin-right: 6px;
}

/* ********** COMMENT FORM  ***************************** */

.post.form.create {
    grid-template-columns: 1fr 1fr;
}

.post.form.create a.avtr {
    grid-column: 1;
    grid-row: 2;
}

.post.form textarea {
    width: 100%;
    min-height: 6em;
    padding: 16px 24px;
    background-color: white;
    resize: none;
    font-size: 1em;
    font-family: Rubik, Arial, Helvetica, sans-serif;
    border-radius: inherit;
    border: 1px solid var(--l-gray);
}

.post.form.create textarea {
    grid-column: 1 / -1;
    grid-row: 1;
}

.post.form textarea:is(:focus, :hover) {
    outline: 1px solid var(--m-blue);
}

.big-btn {
    min-width: 104px;
    padding: 16px;
    background-color: var(--m-blue);
    color: white;
    text-align: center;
    font-weight: 500;
    border-radius: 8px;
}

.post.form.create .big-btn {
    grid-column: 2;
    grid-row: 2;
    justify-self: end;
}

.big-btn:active {
    background-color: var(--l-gray-blue);
}

/* ************ UPDATE COMMENT FORM *********************** */

.post.form.updt textarea {
    grid-column: 1 / -1;
    grid-row: 2;
}

.post.form.updt .post-main {
    display: none;
}

.post.form.updt .small-btn.cncl {
    grid-column: -4 / -3;
    grid-row: 3;
    justify-self: end;
}

.post.form.updt .big-btn {
    grid-column: -3 / -1;
    grid-row: 3;
    justify-self: end;
}

.post.form.updt .small-btn:is(.del, .edit) {
    display: none;
}

/* ************** FOR 768px UP ********************************************* */

@media only screen and (min-width: 48em) {

    /* ************ COMMENT BOX ********************* */

    .post {
        grid-template-columns: auto 2em auto 1fr auto auto;
    }

    a.avtr {
        grid-column: 2;
    }

    span.usrnme-box {
        grid-column: 3;
    }

    a.post-date {
        grid-column: 4 / -1;
    }
    
    .post-main {
        grid-column: 2 / -1;
    }
    
    span.votes {
        padding: 4px 0;
        margin-right: 8px;
        flex-direction: column;
        min-width: 40px;
        grid-column: 1;
        grid-row: 1 / 3;
        align-self: start;
    }
    
    .small-btn:is(.del, .reply, .edit) {
        grid-row: 1;
    }

    /* ************ COMMENT FORM ************* */

    .post.form.create {
        display: flex;
        gap: 16px;
        align-items: flex-start;
    }

    .post.form.create textarea {
        flex: 1 0 400px;
        order: 2;
    }

    .post.form.create a.avtr {
        order: 1;
        margin-top: 4px;
    }

    .post.form.create .big-btn {
        order: 3;
    }

    /* ************ UPDATE COMMENT FORM ******************* */

    .post.form.updt .small-btn:is(.del, .edit) {
        display: block;
    }
        
    .post.form.updt textarea {
        grid-column: 2 / -1;
    }

}

@media only screen and (min-width: 62em) {
    .big-btn:hover {
        background-color: var(--l-gray-blue);
    }
    
    a:is(.usrnme, .post-date):hover {
        text-decoration: underline;
    }

    a.user-role:hover {
        background-color: var(--l-gray-blue);
    }

    .vote-btn:hover {
        color: var(--m-blue);
    }

    .small-btn:hover {
        color: var(--l-gray-blue);
    }

    .small-btn.del:hover {
        color: var(--pale-red);
    }

    .modal.del .big-btn.no:hover{
        background-color: var(--l-gray-l-blue);
    }
    
    .modal.del .big-btn.yes:hover{
        background-color: var(--pale-red);
    }
}

/* ************ MODAL ******************** */

.modal-bg {
    width: 100%;
    height: 100vh;
    padding: 16px;
    position: fixed;
    display: flex;
    align-items: center;
    top: 0;
    background-color: rgba(0, 0, 0, 0.6);
    display: none;
}

.modal {
    max-width: 25rem;
    margin: 0 auto;
    padding: 24px;
    padding: clamp(24px, 24px + var(--scalerpx)*8, 32px);
    display: grid;
    grid-template-columns: 1fr 1fr;
    row-gap: 0px;
    column-gap: 12px;
    border-radius: 8px;
    background-color: white;
}

h3 {
    margin-bottom: 1em;
    font-size: 1.4rem;
    font-size: clamp(1.3rem, 1.3rem + var(--scalerem)*0.2, 1.5rem);
    font-weight: 500;
    color: var(--d-blue);
}

.modal h3 {
    grid-column: 1 / -1;
    grid-row: 1;
}

.modal p {
    margin-bottom: clamp(20px, 20px + var(--scalerpx)*4, 24px);
    grid-column: 1 / -1;
    grid-row: 2;
}

.modal .big-btn {
    width: 100%;
    padding: 16px;
    grid-row: 3;
}

.modal.del .big-btn.no{
    grid-column: 1;
    background-color: var(--gray-blue);
}

.modal.del .big-btn.no:active{
    background-color: var(--l-gray-l-blue);
}

.modal.del .big-btn.yes{
    grid-column: 2;
    background-color: var(--soft-red);
}

.modal.del .big-btn.yes:active{
    background-color: var(--pale-red);
}

/* ********** EXTRAS ******************* */
header {
    color: var(--m-blue);
    height: 64px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
}

select {
    font-size: 1em;
    font-family: Rubik, Arial, Helvetica, sans-serif;
    background-color: transparent;
    color: var(--d-blue);
    /* border: 0.1px solid transparent; */
    border: 1px solid var(--d-blue);
    outline: none;
    box-sizing: border-box;
    cursor: pointer;
}

.attribution { font-size: 11px; text-align: center; }
.attribution a { color: hsl(228, 45%, 44%); }