/* Reset and Base Styles */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary-color: #5a8a7a;
    --primary-hover: #4a7a6a;
    --text-color: #2d3436;
    --text-muted: #636e72;
    --bg-color: #f8faf9;
    --card-bg: #ffffff;
    --border-color: #e0e4e2;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    --font-family: Georgia, 'Times New Roman', serif;
}

[data-theme="dark"] {
    --primary-color: #7eb8a5;
    --primary-hover: #9ecbbb;
    --text-color: #e4e4e4;
    --text-muted: #a0a0a0;
    --bg-color: #1a1a1a;
    --card-bg: #2d2d2d;
    --border-color: #404040;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-color);
    background: var(--bg-color);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
    flex: 1;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 2rem;
}

header h1 {
    font-size: 2rem;
    font-weight: normal;
    margin-bottom: 0.5rem;
    color: var(--text-color);
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
}

.subtitle-hint {
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* Grid */
.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-bottom: 2rem;
}

@media (min-width: 600px) {
    .grid {
        grid-template-columns: 1fr 1fr;
    }
}

@media (min-width: 1000px) {
    .grid {
        grid-template-columns: 1fr 1fr 1fr;
    }
}

/* Cards */
.card {
    background: var(--card-bg);
    border-radius: 8px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
}

.card-header {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
}

.card h2 {
    font-size: 1.25rem;
    font-weight: normal;
    color: var(--text-muted);
    margin-right: auto;
}

.copy-btn,
.explain-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.copy-btn:hover,
.explain-btn:hover {
    color: var(--primary-color);
}

.copy-btn:disabled,
.explain-btn:disabled {
    opacity: 0;
    pointer-events: none;
}

.copy-btn .icon-check {
    display: none;
}

.copy-btn.copied .icon-clipboard {
    display: none;
}

.copy-btn.copied .icon-check {
    display: block;
    color: var(--primary-color);
}

.sentence {
    font-size: 1.1rem;
    line-height: 1.8;
    min-height: 80px;
}

.loading {
    color: var(--text-muted);
    font-style: italic;
}

/* Links in sentences - Dexonline hover effect */
.sentence a {
    color: var(--primary-color);
    text-decoration: none;
    position: relative;
}

.sentence a:hover,
.sentence a:focus {
    text-decoration: underline;
}

/* Dexonline bottom drawer */
.dex-drawer-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--drawer-height, 50vh);
    z-index: 200;
    background: var(--card-bg);
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.3s ease, visibility 0.3s;
    visibility: hidden;
    pointer-events: none;
}

.dex-drawer:not(.dex-drawer-hidden) .dex-drawer-panel {
    transform: translateY(0);
    visibility: visible;
    pointer-events: auto;
}

.dex-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.dex-drawer-header:active {
    cursor: grabbing;
}

.dex-drawer-handle {
    position: absolute;
    top: 6px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-color);
}

.dex-drawer-title {
    font-weight: bold;
    color: var(--text-color);
}

.dex-drawer-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0 0.5rem;
    line-height: 1;
}

.dex-drawer-body {
    flex: 1;
    overflow: hidden;
}

.dex-drawer-body iframe {
    width: 100%;
    height: calc(100% + 300px);
    border: none;
    margin-top: -300px;
}

/* Buttons */
.controls {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: center;
}

.rarity-label {
    color: var(--text-color);
    font-size: 1rem;
}

.rarity-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    max-width: 620px;
}

.dual-range {
    flex: 1;
    position: relative;
    height: 28px;
}

.dual-range input[type='range'] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    pointer-events: none;
    z-index: 2;
}

.dual-range input[type='range']::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    border: 2px solid var(--card-bg);
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.dual-range input[type='range']::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--primary-color);
    border: 2px solid var(--card-bg);
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.dual-range-track {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 4px;
    transform: translateY(-50%);
    border-radius: 2px;
    background: var(--border-color);
    z-index: 1;
    pointer-events: none;
}

.scale-label {
    color: var(--text-muted);
    font-size: 0.875rem;
    white-space: nowrap;
}

.rarity-value {
    color: var(--text-muted);
    font-size: 0.95rem;
}

@media (max-width: 640px) {
    .scale-text {
        display: none;
    }
}

.actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.btn {
    font-family: var(--font-family);
    font-size: 1rem;
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Dark mode toggle */
.theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 44px;
    height: 44px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    box-shadow: var(--shadow);
    transition: background-color 0.2s, transform 0.1s;
    z-index: 1000;
}

.theme-toggle:hover {
    transform: scale(1.05);
}

.theme-toggle .icon-sun,
.theme-toggle .icon-moon {
    display: none;
}

:root .theme-toggle .icon-moon {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-sun {
    display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
    display: none;
}

/* Messages */
.message {
    padding: 1rem;
    border-radius: 4px;
    margin-top: 1rem;
    text-align: center;
}

.message.error {
    background: #fee;
    color: #c00;
}

.message.info {
    background: #e8f4fd;
    color: #0066cc;
}

[data-theme="dark"] .message.error {
    background: #4a2020;
    color: #ff9090;
}

[data-theme="dark"] .message.info {
    background: #1a3a4a;
    color: #80c0ff;
}

.hidden {
    display: none;
}

/* Footer */
footer {
    text-align: center;
    padding: 1.5rem 1rem;
    border-top: 1px solid var(--border-color);
    color: var(--text-muted);
    font-size: 0.9rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
}

footer a:hover {
    text-decoration: underline;
}

footer .tech {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    opacity: 0.7;
}

/* Loading animation */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.loading {
    animation: pulse 1.5s ease-in-out infinite;
}
