/* CSS-переменные для удобного управления цветовой схемой */
:root {
    --primary-color: #2e5c86;
    --primary-hover: #3e6fa6;
    --secondary-color: #ffda82;
    --background-color: #f4f6f8;
    --header-footer-bg: #2e5c86;
    --text-color: #333;
    --light-gray: #f0f0f0;
    --error-bg: #ffb3b3;
    --success-bg: #b3ffb3;
    --button-bg: #2e5c86;
    --button-hover-bg: #3e6fa6;
    --button-active-bg: #2a4e71;
    --input-focus-border: #2e5c86;
    --shadow-color: rgba(0, 0, 0, 0.1);
    --link-visited-color: #4d5cff;
    --border-color: #ccc;

    --block-bg: #fff;
    --example-bg: #f9f9f9;
    --table-bg: #fff;
    --table-header-bg: #f0f0f0;
    --copy-button-bg: #ddd;
    --copy-button-border: #999;
}

/* Сброс и базовые стили */
* {
    box-sizing: border-box;
}

p {
    white-space: pre-line;
}

a {
    color: var(--link-visited-color);
    font-size: 1.2em;
}

a:visited {
    color: var(--link-visited-color);
}

html {
    min-height: 100%;
}

body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--background-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text-color);
    /* Плавное проявление при загрузке */
    animation: fadeInBody 0.6s ease forwards;
    opacity: 0;
}

@keyframes fadeInBody {
    to { opacity: 1; }
}


.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 16px 0;
  background: var(--background-color);
  border-bottom: 1px solid #ddd;
}

.tab {
  padding: 10px 18px;
  text-decoration: none;
  color: #555;
  border-radius: 8px 8px 0 0;
}

.tab:hover { background: #eef0f3; }

.tab.active {
  background: #f4f5f7;
  font-weight: 600;
  color: #000;
}

.page {
  display: flex;
  justify-content: center;
  padding: 32px 16px;
}

.calc {
  width: 100%;
  max-width: 1000px;
  min-width: 200px;
  /* margin: 0 auto;*/

  background: #fff;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 6px 24px rgba(0,0,0,.08);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* строка ввода */
#display {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  font-size: 20px;
  text-align: right;
  border: 1px solid #ccc;
  border-radius: 10px;
  outline: none;
  background: #fff;
}
#display:focus { border-color: #4a90e2; }

/* сетка кнопок */
.grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(7, 46px);
  gap: 6px;
}

.grid button {
  font-size: 16px;
  border: 1px solid #d7d9dd;
  background: #fafbfc;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
  transition: background .12s, transform .05s;
  color: #222;
}
.grid button:hover  { background: #eef2f7; }
.grid button:active { transform: scale(.97); }

/* цвета по категориям */
.grid .num   { background: #fff;     font-size: 18px; }
.grid .num:hover { background: #eef2f7; }

.grid .fn    { background: #f0f4fb;  color: #2a5599; }
.grid .fn:hover  { background: #e2ecfa; }

.grid .op    { background: #fff4e5;  color: #b45f06; font-size: 18px; }
.grid .op:hover  { background: #ffe9c9; }

.grid .clear { background: #fdecec;  color: #b3261e; font-weight: 700; }
.grid .clear:hover { background: #fad9d9; }

.grid .eq {
  background: #4a90e2;
  color: #fff;
  border-color: #4a90e2;
  font-size: 20px;
  font-weight: 700;
}
.grid .eq:hover { background: #3b7dc9; }


#result {
  width: 100%;
  min-height: 130px;
  padding: 10px 14px;
  font-size: 18px;
  line-height: 1.4;
  font-family: inherit;
  resize: vertical;
  border: 1px solid #ccc;
  border-radius: 10px;
  background: #f9fafb;
  text-align: right;
  outline: none;
}

#display,
#result,
.grid {
  width: 100%;
  box-sizing: border-box;
  margin: 0;
}

#display { padding: 0 14px; }
#result  { padding: 10px 14px; }

.precision-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #555;
}

.precision-row label { white-space: nowrap; }

#precision {
  width: 64px;
  height: 32px;
  padding: 0 8px;
  text-align: right;
  border: 1px solid #ccc;
  border-radius: 8px;
  font-size: 22px;
  font-family: inherit;
  outline: none;
}

#precision:focus { border-color: #4a90e2; }

.precision-row .hint {
  color: #888;
  font-size: 14px;
}


/* Шапка */
header {
    background-color: var(--header-footer-bg);
    width: 100%;
    color: #fff;
    padding: 1em 2em;
    margin-bottom: 1em;
    box-shadow: 0 4px 8px var(--shadow-color);
    position: fixed;
    top: 0;
    z-index: 1000;
}

header a,
header a:hover,
header a:visited{
    color: #ffffff;
    text-decoration: none;
}


header h1 {
    margin: 0;
    font-size: 1.8em;
    animation: fadeInDown 0.8s ease forwards;
    opacity: 0;
    transform: translateY(-20px);
}

@keyframes fadeInDown {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

nav {
    margin-top: 0.5em;
}

nav a {
    color: #fff;
    text-decoration: none;
    margin-right: 1.5em;
    font-weight: 500;
    position: relative;
    transition:
        color 0.3s ease,
        opacity 0.3s ease;
    font-size: 1em;
}

nav a::after {
    content: '';
    display: block;
    width: 0;
    height: 2px;
    background: var(--secondary-color);
    transition: width 0.3s;
    position: absolute;
    bottom: -4px;
    left: 0;
}

nav a:hover {
    color: var(--secondary-color);
}

nav a:hover::after {
    width: 100%;
}

nav a:visited {
    color: #fff;
}

/* Основной контент */
main {
    flex: 1;
    transition: margin-top 0.3s ease-out;
    padding: 2em;
    min-height: 70vh;
    /* Лёгкое появление и сдвиг вверх */
    animation: fadeInUp 0.6s ease forwards;
    opacity: 0;
    transform: translateY(30px);
}

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Футер */
footer {
    background: var(--header-footer-bg);
    color: #fff;
    text-align: center;
    padding: 1em 1em;
    margin-top: 1em;
    font-size: 0.9em;
    position: relative;
    animation: fadeInFooter 0.6s ease forwards;
    opacity: 0;
}

@keyframes fadeInFooter {
    to { opacity: 1; }
}

/* Всплывающие сообщения (flash) */
.flashes {
    list-style-type: none;
    padding: 0;
    margin: 1em 0;
    animation: fadeInFlash 0.4s ease forwards;
    opacity: 0;
}

@keyframes fadeInFlash {
    to { opacity: 1; }
}

.flashes li {
    margin: 5px 0;
    padding: 12px 20px;
    border-radius: 4px;
    font-weight: 500;
    animation: slideInFlash 0.4s ease forwards;
    opacity: 0;
}

@keyframes slideInFlash {
    from {
        transform: translateX(-20px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.flashes li.error {
    background-color: var(--error-bg);
    color: var(--text-color);
}

.flashes li.success {
    background-color: var(--success-bg);
    color: var(--text-color);
}

/* Поля ввода / textarea */
input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
    color: var(--text-color);
    width: 100%;
    padding: 0.8em 1em;
    margin: 0.4em 0;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--example-bg);
    transition: border-color 0.3s, box-shadow 0.3s;
    font-size: 1em;
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
select:focus,
textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 8px rgba(46, 92, 134, 0.3);
    outline: none;
}

/* Кнопки */
button {
    padding: 0.7em 1.5em;
    font-size: 1em;
    border: none;
    border-radius: 6px;
    background-color: var(--button-bg);
    color: #000;
    cursor: pointer;
    transition: background-color 0.3s, transform 0.2s, box-shadow 0.3s;
    font-weight: 500;
}

button:hover {
    background-color: var(--button-hover-bg);
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}

button:active {
    background-color: var(--button-active-bg);
    transform: translateY(0);
    box-shadow: none;
}

button:disabled {
    background-color: #aaa;
    cursor: not-allowed;
}

/* Плавное развёртывание details */
details {
    transition: all 0.3s ease;
}

details[open] {
    animation: fadein 0.3s;
}

@keyframes fadein {
    from {opacity: 0;}
    to   {opacity: 1;}
}

/* Мобильная адаптивность */
@media (max-width: 768px) {
    header, main, footer {
        padding: 1em;
    }

    nav a {
        display: block;
        margin: 0.5em 0;
    }

    table th, table td {
        padding: 10px 15px;
    }

    .problem-block, .example-item {
        padding: 1em;
    }

    input[type="text"],
    input[type="password"],
    input[type="number"],
    select,
    textarea {
        max-width: 100%;
    }
}

/* Корректируем цвет текста в шапке и футере */
header,
footer {
    color: #fff; /* Оставляем белый, так как фон темный в обеих темах */
}


.theme-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    z-index: 1001; /* Выше других элементов шапки */

    /* Стилизация */
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--button-bg);
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;

    /* Центрирование иконки */
    display: flex;
    align-items: center;
    justify-content: center;
}

