:root {
    --gradient-bg: #1e1e1e;
    --gradient-header: linear-gradient(135deg, #2a2a2a, #1e1e1e);
    --gradient-btn: linear-gradient(135deg, #3a3f51, #2c2f3a);
    --gradient-btn-hover: linear-gradient(135deg, #4b5168, #343845);
    --hover-glow: 0 0 25px rgba(0, 200, 255, 0.6);
    --text: #f5f5f5;
}

* {
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    margin: 0;
    background: var(--gradient-bg);
    scroll-behavior: smooth;
    color: var(--text);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 0;
    box-sizing: border-box;
}

canvas#background-stars {
    position: fixed;
    top: 0;
    left: 0;
    z-index: -2;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.container {
    text-align: center;
    background: linear-gradient(
        145deg,
        rgba(20, 20, 20, 0.7) 0%,
        rgba(30, 30, 30, 0.6) 40%,
        rgba(40, 40, 40, 0.5) 70%,
        rgba(60, 60, 60, 0.4) 100%
    );
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    max-width: 400px;
    width: 100%;
    padding: 30px;
    margin: auto;
    transition: padding 0.3s ease;
}

@media (min-width: 768px) {
    .container {
        padding: 30px;
        max-width: 600px;
    }
}

h1 {
    margin-bottom: 20px;
    font-size: 2.2em;
    font-weight: 700;
    color: var(--text);
    text-shadow: 0 0 10px rgba(0, 200, 255, 0.6);
}

h2 {
    color: var(--text);
    margin-top: 25px;
    margin-bottom: 15px;
    font-size: 1.5em;
    font-weight: 600;
}

h3 {
    color: var(--text);
    margin-top: 25px;
    margin-bottom: 10px;
    font-size: 1.1em;
}

h4 {
    color: var(--text);
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 1em;
}

.input-group {
    margin-bottom: 15px;
}

label {
    font-weight: 600;
    margin-bottom: 8px;
    display: block;
    font-size: 1rem;
    color: var(--text);
}

input,
select {
    padding: 14px;
    font-size: 1rem;
    width: 100%;
    border: 1px solid #555;
    border-radius: 12px;
    text-align: center;
    background-color: #333;
    color: var(--text);
}

input:focus,
select:focus {
    outline: none;
    border-color: #00c8ff;
}

button {
    padding: 10px 20px;
    background: var(--gradient-btn);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.3s, transform 0.3s;
    margin: 10px 5px 0;
    font-size: 1rem;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

button:hover {
    background: var(--gradient-btn-hover);
    transform: scale(1.05);
}

button:active {
    transform: scale(0.98);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

button:disabled {
    background: #555;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
}

button#resetBtn {
    background: linear-gradient(135deg, #ff4e50, #c0392b);
    box-shadow: 0 5px 15px rgba(255, 78, 80, 0.3);
}

button#resetBtn:hover {
    background: linear-gradient(135deg, #c0392b, #ff4e50);
}

/* Original Output section - now controlled by key-gen-output-section */
.output {
    /* Removed display: none; and opacity: 0; here */
    transition: opacity 0.5s ease;
    margin-top: 20px;
    position: relative;
    /* .output.show is no longer needed */
}

.key-output {
    font-size: 0.9rem;
    background-color: #111;
    color: #dcdcdc;
    padding: 1rem;
    border-radius: 5px;
    max-height: 300px;
    display: block;
    overflow-y: auto;
    overflow-x: auto;
    margin: 10px auto;
    white-space: pre;
    word-break: normal;
    text-align: left;
}

#errorMsg {
    color: red;
    font-size: 0.95rem;
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    padding: 0;
    transition: max-height 0.4s ease-in-out, opacity 0.4s ease-in-out, padding 0.4s ease-in-out;
    text-align: center;
}

#errorMsg.show {
    max-height: 100px;
    opacity: 1;
    padding-top: 10px;
    padding-bottom: 10px;
}

#advancedSection {
    display: none;
    margin: 15px 0 20px;
    padding: 10px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
}

#advancedSection.show {
    display: block;
}

#advancedToggleContainer {
    display: flex;
    justify-content: center;
    margin: 15px 0 10px;
}

#advancedToggleLabel {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    color: #00c8ff;
    margin-bottom: 0;
}

#advancedToggle {
    width: 14px;
    height: 14px;
    margin: 0 8px 0 0;
    padding: 0;
    border: 1px solid #00c8ff;
    border-radius: 3px;
    background-color: #444;
    vertical-align: middle;
    flex-shrink: 0;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.2);
    appearance: checkbox;
    -webkit-appearance: checkbox;
    -moz-appearance: checkbox;
}

#advancedToggle:checked {
    background-color: #00c8ff;
    border-color: #00c8ff;
}

.blurred {
    filter: blur(8px);
    cursor: pointer;
    transition: filter 0.3s ease;
}

.private-key-wrapper {
    position: relative;
}

#toggleKeyBtn {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 0.8rem;
    padding: 6px 16px;
    background: rgba(85, 85, 85, 0.9);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: white;
    z-index: 1;
}

.key-note {
    font-size: 0.85rem;
    color: #aaa;
    margin-top: 6px;
    text-align: center;
}

#generateBtn {
    margin-top: 15px;
}

/* --- Main Section Toggling Styles --- */
.main-content-wrapper {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
}

.key-generation-wrapper {
    max-height: 2000px;
    opacity: 1;
    overflow: hidden;
    transform: translateY(0);
    transition: max-height 0.7s ease-in-out, opacity 0.7s ease-in-out, transform 0.7s ease-in-out;
}

.pgp-tool-wrapper {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transform: translateY(0);
    transition: max-height 0.7s ease-in-out, opacity 0.7s ease-in-out, transform 0.7s ease-in-out;
    margin-top: 0;
    padding-top: 0;
}

/* State when PGP Tools are active */
.key-generation-wrapper.hidden-section {
    max-height: 0;
    opacity: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    transform: translateY(-100%);
}

.pgp-tool-wrapper.visible-section {
    max-height: 2500px;
    opacity: 1;
    transform: translateY(0);
}


/* Styling for the main toggle button (Show PGP Tools / Hide PGP Tools) */
.toggle-section-btn {
    background: linear-gradient(135deg, #00c8ff, #007bff);
    box-shadow: 0 5px 15px rgba(0, 200, 255, 0.3);
    margin: 20px auto;
    padding: 12px 25px;
    font-size: 1.1em;
    width: auto;
    display: block;
}

.toggle-section-btn:hover {
    background: linear-gradient(135deg, #007bff, #00c8ff);
}

/* Styles for the 5 black box category buttons */
.tools-content-area {
    max-height: 100%;
    display: flex;
    flex-direction: column;
    width: 100%;
}

.tools-category-selector {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 20px;
    max-height: 1000px;
    opacity: 1;
    transition: max-height 0.5s ease-out, opacity 0.5s ease-out;
    overflow: hidden;
}

/* State when category selector is hidden */
.tools-category-selector.hidden-buttons {
    max-height: 0;
    opacity: 0;
    margin-bottom: 0;
    pointer-events: none;
}


.tool-category-btn {
    padding: 15px;
    background-color: #222;
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    cursor: pointer;
    font-size: 1.1rem;
    font-weight: 500;
    transition: background-color 0.3s, transform 0.3s, border-color 0.3s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    width: 100%;
}

.tool-category-btn:hover {
    background-color: #333;
    transform: translateY(-2px);
    border-color: #00c8ff;
}

.tool-category-btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}


/* Individual Tool Containers (Encrypt, Decrypt, etc.) */
.tool-item-container {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.7s ease-in-out, opacity 0.7s ease-in-out;
    margin-top: 15px;
}

.tool-item-container.visible-tool {
    max-height: 1000px;
    opacity: 1;
}

.tool-group {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 20px;
    border-radius: 10px;
    margin-bottom: 25px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.tool-group h3 {
    margin-top: 0;
    margin-bottom: 15px;
    color: #00c8ff;
    text-shadow: none;
}

.tool-group h4 {
    margin-top: 20px;
    margin-bottom: 10px;
    font-size: 1em;
    color: var(--text);
}

textarea {
    min-height: 100px;
    resize: vertical;
    padding: 14px;
    font-size: 1rem;
    width: 100%;
    border: 1px solid #555;
    border-radius: 12px;
    background-color: #333;
    color: var(--text);
    margin-bottom: 10px;
    text-align: left;
}

textarea.key-input {
    min-height: 80px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
}

/* Styling for the new single "Back to Tools" button */
#singleBackToToolsBtn {
    background: #444;
    font-size: 0.9em;
    padding: 8px 15px;
    margin: 20px auto;
    box-shadow: none;
    transition: background 0.2s, opacity 0.5s ease, max-height 0.5s ease;
    display: block;
    max-height: 50px;
    opacity: 1;
    overflow: hidden;
    cursor: pointer;
}

#singleBackToToolsBtn:hover {
    background: #666;
    transform: none;
}

#singleBackToToolsBtn.hidden {
    max-height: 0;
    opacity: 0;
    margin-top: 0;
    margin-bottom: 0;
    pointer-events: none;
}

/* --- New Styles for Tool Input/Output Sections (also used for Key Gen) --- */
.tool-input-section,
.tool-output-section,
.key-gen-input-section, /* NEW */
.key-gen-output-section /* NEW */
{
    /* Base for transition */
    max-height: 1000px; /* Sufficient height for content */
    opacity: 1;
    overflow: hidden;
    transition: max-height 0.5s ease-in-out, opacity 0.5s ease-in-out, padding 0.5s ease-in-out;
    padding: 0; /* Will be managed by content */
    margin: 0; /* Will be managed by content */
    box-sizing: border-box;
    display: block; /* Ensure it behaves as a block for max-height */
}

.tool-input-section.hidden-input,
.key-gen-input-section.hidden-input /* NEW */
{
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
    margin-bottom: 0;
    pointer-events: none;
}

.tool-output-section.hidden-output,
.key-gen-output-section.hidden-output /* NEW */
{
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
    margin-top: 0;
    margin-bottom: 0;
    pointer-events: none;
}

/* Style for the new "Back to Input" button within each tool */
.back-to-tool-input-btn {
    background: #555;
    font-size: 0.9em;
    padding: 8px 15px;
    margin-top: 15px; /* Add some space above */
    margin-bottom: 5px;
    box-shadow: none;
}

.back-to-tool-input-btn:hover {
    background: #777;
    transform: none;
}

.key-info {
    font-size: 0.9em;
    color: #bbb;
    margin-top: 10px;
    margin-bottom: 10px;
}

.key-info p {
    margin: 5px 0;
}

.helper-btn {
    background: linear-gradient(135deg, #008266, #005248);
    box-shadow: 0 5px 15px rgba(0, 130, 102, 0.3);
    font-size: 0.9em;
    padding: 8px 15px;
    margin: 5px auto 10px;
    display: block;
    width: auto;
}

.helper-btn:hover {
    background: linear-gradient(135deg, #009c7a, #00695c);
    transform: scale(1.05);
}