*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: 'Source Sans 3', system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    color: #1a1a2e;
    background: #f4f6fb;
}

.header {
    background: linear-gradient(135deg, #c0392b 0%, #922b21 100%);
    color: #fff;
    padding: 1.5rem 1rem 1.25rem;
    text-align: center;
}

.header h1 {
    margin: 0;
    font-size: 1.6rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.subtitle {
    margin: 0.35rem 0 0;
    opacity: 0.9;
    font-size: 0.95rem;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.25rem 1rem 2.5rem;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    align-items: flex-end;
    background: #fff;
    border-radius: 10px;
    padding: 1rem 1.1rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    margin-bottom: 1rem;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.field select,
.field input {
    font: inherit;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    padding: 0.45rem 0.6rem;
    border: 1px solid #ccd;
    border-radius: 6px;
    background: #fff;
    min-width: 220px;
}

.field-search {
    flex: 1;
    min-width: 180px;
}

.field-search input {
    width: 100%;
}

.view-toggle {
    display: flex;
    gap: 0;
    border: 1px solid #ccd;
    border-radius: 6px;
    overflow: hidden;
}

.view-toggle button {
    font: inherit;
    padding: 0.45rem 0.9rem;
    border: none;
    background: #fff;
    cursor: pointer;
    color: #555;
}

.view-toggle button.active {
    background: #c0392b;
    color: #fff;
}

.view-toggle button:not(.active):hover {
    background: #f0f0f5;
}

.count {
    margin: 0 0 0.75rem;
    font-size: 0.85rem;
    color: #666;
}

.status {
    text-align: center;
    padding: 2rem 1rem;
    color: #666;
}

.status.error {
    color: #c0392b;
}

.table-wrap {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead th {
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #666;
    padding: 0.75rem 1rem;
    border-bottom: 2px solid #eee;
    background: #fafbfc;
}

tbody td {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid #f0f0f4;
    vertical-align: middle;
}

tbody tr:hover {
    background: #fafbfd;
}

tr.row-color-rojo {
    background: rgba(192, 57, 43, 0.07);
}

tr.row-color-rojo td:first-child {
    border-left: 3px solid #c0392b;
}

tr.row-color-rojo:hover {
    background: rgba(192, 57, 43, 0.13);
}

tr.row-color-naranja {
    background: rgba(230, 126, 34, 0.08);
}

tr.row-color-naranja td:first-child {
    border-left: 3px solid #e67e22;
}

tr.row-color-naranja:hover {
    background: rgba(230, 126, 34, 0.14);
}

tr.row-color-amarillo {
    background: rgba(241, 196, 15, 0.10);
}

tr.row-color-amarillo td:first-child {
    border-left: 3px solid #f1c40f;
}

tr.row-color-amarillo:hover {
    background: rgba(241, 196, 15, 0.16);
}

tr.row-color-verde-claro {
    background: rgba(130, 201, 30, 0.08);
}

tr.row-color-verde-claro td:first-child {
    border-left: 3px solid #82c91e;
}

tr.row-color-verde-claro:hover {
    background: rgba(130, 201, 30, 0.14);
}

tr.row-color-verde {
    background: rgba(39, 174, 96, 0.07);
}

tr.row-color-verde td:first-child {
    border-left: 3px solid #27ae60;
}

tr.row-color-verde:hover {
    background: rgba(39, 174, 96, 0.13);
}

.col-jp {
    min-width: 140px;
    display: flex;
    align-items: center;
}

.jp-cell-text {
    display: flex;
    flex-direction: column;
}

.jp-text {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 1.15rem;
    font-weight: 700;
}

.col-es {
    min-width: 120px;
}

.col-pista {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 0.9rem;
    color: #777;
    min-width: 180px;
}

.cell-sub {
    display: block;
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 0.78rem;
    color: #999;
    margin-top: 0.15rem;
}

.btn-speak {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.4rem;
    height: 1.4rem;
    padding: 0;
    margin-left: 0.35rem;
    font-size: 0.6rem;
    line-height: 1;
    border: 1px solid #dde;
    border-radius: 4px;
    background: #f4f6fb;
    color: #888;
    cursor: pointer;
    vertical-align: middle;
    flex-shrink: 0;
}

.btn-speak:hover {
    background: #e8ebf5;
    color: #c0392b;
    border-color: #c0392b;
}

.btn-speak-card {
    font-size: 0.55rem;
    width: 1.2rem;
    height: 1.2rem;
}

.col-select {
    width: 2.5rem;
    text-align: center;
}

.col-select input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
    accent-color: #c0392b;
}

.thumb {
    width: 36px;
    height: 36px;
    object-fit: contain;
    vertical-align: middle;
    margin-right: 0.5rem;
}

.thumb-placeholder {
    display: inline-block;
    width: 36px;
    height: 36px;
    vertical-align: middle;
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.85rem;
}

.field-cards-option .checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    color: #1a1a2e;
    cursor: pointer;
    white-space: nowrap;
}

.field input[type="checkbox"] {
    min-width: 0;
    width: 1rem;
    height: 1rem;
    padding: 0;
    border: none;
    background: none;
    accent-color: #c0392b;
}

.card {
    position: relative;
    background: #fff;
    border-radius: 10px;
    padding: 1rem;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
    text-align: center;
}

.card:not(.card-revealed) {
    cursor: pointer;
}

.card-select {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    cursor: pointer;
}

.card-select input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: #c0392b;
    cursor: pointer;
}

.card-img {
    width: 48px;
    height: 48px;
    object-fit: contain;
    margin-bottom: 0.5rem;
}

.card-img-placeholder {
    display: inline-block;
    width: 48px;
    height: 48px;
    margin-bottom: 0.5rem;
}

.card-jp {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0 0 0.15rem;
}

.card-pron {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 0.85rem;
    color: #777;
    margin: 0 0 0.4rem;
}

.card-es {
    font-size: 1rem;
    font-weight: 600;
    margin: 0 0 0.5rem;
    color: #c0392b;
}

.card-es-hidden {
    color: #aaa;
    font-weight: 400;
    font-style: italic;
}

.card-pista {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 0.8rem;
    color: #888;
    margin: 0;
    line-height: 1.4;
}

.card-reverso-lectura {
    margin-top: 0.1rem;
    margin-bottom: 0.4rem;
}

.cards-empty {
    grid-column: 1 / -1;
}

.field-direction select {
    min-width: 180px;
}

.practice-mode {
    font-size: 0.8rem;
    opacity: 0.75;
    white-space: nowrap;
}

.practice-es-front {
    color: #1a1a2e;
    margin: 0;
}

.practice-jp-light {
    color: #fff;
}

.practice-pron-light {
    color: rgba(255, 255, 255, 0.85);
}

.practice-back .practice-pista {
    margin-top: 1rem;
}

.btn-reload {
    font: inherit;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.45rem 0.6rem;
    border: 1px solid #ccd;
    border-radius: 6px;
    background: #fff;
    color: #555;
    cursor: pointer;
    align-self: flex-end;
}

.btn-reload:hover:not(:disabled) {
    background: #f0f0f5;
    color: #c0392b;
    border-color: #c0392b;
}

.btn-reload:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-practice {
    font: inherit;
    font-weight: 600;
    padding: 0.45rem 1.1rem;
    border: none;
    border-radius: 6px;
    background: #27ae60;
    color: #fff;
    cursor: pointer;
    margin-left: auto;
}

.btn-practice:hover:not(:disabled) {
    background: #219a52;
}

.btn-practice:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

body.practice-active {
    overflow: hidden;
}

.practice-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    background: linear-gradient(160deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    color: #fff;
    outline: none;
}

.practice-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1.25rem;
    background: rgba(0, 0, 0, 0.25);
}

.practice-progress {
    font-weight: 600;
    font-size: 0.95rem;
    min-width: 4rem;
}

.practice-lesson {
    flex: 1;
    text-align: center;
    font-size: 0.9rem;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.practice-close {
    font: inherit;
    font-size: 1.25rem;
    line-height: 1;
    padding: 0.25rem 0.5rem;
    border: none;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    cursor: pointer;
}

.practice-close:hover {
    background: rgba(255, 255, 255, 0.22);
}

.practice-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    gap: 2rem;
    overflow: hidden;
}

.practice-card-slide {
    width: min(90vw, 520px);
    height: min(60vh, 420px);
}

.practice-card-slide.slide-entering {
    animation: slideInFromRight 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

.practice-card-slide.slide-exiting {
    animation: slideOutToLeft 0.45s cubic-bezier(0.55, 0.06, 0.68, 0.19) both;
}

.practice-card-slide.slide-entering-back {
    animation: slideInFromLeft 0.45s cubic-bezier(0.25, 0.46, 0.45, 0.94) both;
}

.practice-card-slide.slide-exiting-back {
    animation: slideOutToRight 0.45s cubic-bezier(0.55, 0.06, 0.68, 0.19) both;
}

@keyframes slideInFromRight {
    from {
        transform: translateX(110%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutToLeft {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(-110%);
        opacity: 0;
    }
}

@keyframes slideInFromLeft {
    from {
        transform: translateX(-110%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOutToRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(110%);
        opacity: 0;
    }
}

.practice-card {
    width: 100%;
    height: 100%;
    perspective: 1200px;
    cursor: pointer;
}

.practice-card.is-advancing,
.practice-card.is-exiting {
    pointer-events: none;
}

.practice-card.is-exiting .practice-card-inner {
    transition: none;
    transform: rotateY(0deg);
}

.practice-card-inner {
    position: relative;
    width: 100%;
    height: 100%;
    transition: transform 0.55s cubic-bezier(0.4, 0.2, 0.2, 1);
    transform-style: preserve-3d;
}

.practice-card.flipped .practice-card-inner {
    transform: rotateY(180deg);
}

.practice-face {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1.5rem;
    border-radius: 20px;
    backface-visibility: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.practice-front {
    background: #fff;
    color: #1a1a2e;
}

.practice-back {
    background: linear-gradient(135deg, #c0392b, #922b21);
    color: #fff;
    transform: rotateY(180deg);
}

.practice-img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin-bottom: 1.25rem;
}

.practice-jp {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: clamp(2.5rem, 10vw, 4rem);
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
    text-align: center;
}

.practice-pron {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: clamp(1.1rem, 4vw, 1.6rem);
    color: #666;
    margin: 0.75rem 0 0;
    text-align: center;
}

.practice-hint-label {
    position: absolute;
    bottom: 1.25rem;
    font-size: 0.8rem;
    color: #999;
    margin: 0;
}

.practice-hint-back {
    color: rgba(255, 255, 255, 0.65);
}

.practice-es {
    font-size: clamp(1.8rem, 6vw, 2.8rem);
    font-weight: 600;
    margin: 0;
    text-align: center;
    line-height: 1.3;
}

.practice-pista {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: clamp(0.95rem, 3vw, 1.2rem);
    opacity: 0.85;
    margin: 1.25rem 0 0;
    text-align: center;
    line-height: 1.5;
    max-width: 90%;
}

.practice-actions {
    display: flex;
    gap: 0.75rem;
}

.practice-btn {
    font: inherit;
    font-weight: 600;
    font-size: 1rem;
    padding: 0.65rem 1.75rem;
    border: 2px solid rgba(255, 255, 255, 0.35);
    border-radius: 999px;
    background: transparent;
    color: #fff;
    cursor: pointer;
}

.practice-btn:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.12);
}

.practice-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.practice-btn-primary {
    background: #27ae60;
    border-color: #27ae60;
}

.practice-btn-primary:hover {
    background: #219a52;
    border-color: #219a52;
}

.practice-btn-danger {
    background: #c0392b;
    border-color: #c0392b;
}

.practice-btn-danger:hover {
    background: #a93226;
    border-color: #a93226;
}

.practice-done {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
}

.practice-done-title {
    font-size: clamp(1.6rem, 5vw, 2.2rem);
    font-weight: 600;
    margin: 0 0 0.5rem;
}

.practice-done-count {
    font-size: 1rem;
    opacity: 0.8;
    margin: 0 0 2rem;
}

.practice-done-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
}

@media (max-width: 600px) {
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .field select,
    .field input {
        min-width: 0;
        width: 100%;
    }

    .view-toggle {
        align-self: flex-start;
    }

    .btn-practice {
        margin-left: 0;
        width: 100%;
    }

    .field-direction select {
        min-width: 0;
        width: 100%;
    }

    .practice-mode {
        display: none;
    }

    .practice-card-slide {
        height: min(55vh, 380px);
    }
}

.help-overlay {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 15, 30, 0.55);
    padding: 1rem;
}

.help-panel {
    position: relative;
    background: #fff;
    border-radius: 12px;
    max-width: 480px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 1.75rem 1.5rem 1.5rem;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
}

.help-panel h2 {
    margin: 0 0 1rem;
    font-size: 1.25rem;
}

.help-panel h3 {
    margin: 1.1rem 0 0.4rem;
    font-size: 1rem;
    color: #922b21;
}

.help-panel h3:first-of-type {
    margin-top: 0;
}

.help-panel p,
.help-panel ul {
    margin: 0.4rem 0;
    font-size: 0.92rem;
    color: #333;
}

.help-panel ul {
    padding-left: 1.2rem;
}

.help-panel .checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.92rem;
    font-weight: 400;
    color: #1a1a2e;
    cursor: pointer;
    margin: 0.75rem 0;
}

.help-panel .checkbox-label input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: #c0392b;
    cursor: pointer;
}

.help-panel li {
    margin: 0.3rem 0;
}

.help-panel kbd {
    background: #f0f0f4;
    border: 1px solid #d5d5e0;
    border-radius: 4px;
    padding: 0.05rem 0.4rem;
    font-family: inherit;
    font-size: 0.85em;
}

.help-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    border: none;
    background: transparent;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    color: #666;
    padding: 0.25rem;
}

.help-close:hover {
    color: #1a1a2e;
}

.help-dont-show {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 1.25rem;
    font-size: 0.85rem;
    color: #555;
    cursor: pointer;
}

.help-dont-show input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: #c0392b;
    cursor: pointer;
}

.help-actions {
    margin-top: 1rem;
    display: flex;
    justify-content: center;
}

.help-color-scale {
    list-style: none;
    padding-left: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.help-color-scale li {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0;
}

.color-dot {
    display: inline-block;
    width: 0.85rem;
    height: 0.85rem;
    border-radius: 50%;
}

.color-dot-rojo {
    background: #c0392b;
}

.color-dot-naranja {
    background: #e67e22;
}

.color-dot-amarillo {
    background: #f1c40f;
}

.color-dot-verde-claro {
    background: #82c91e;
}

.color-dot-verde {
    background: #27ae60;
}
