:root {
    --bg: #0f0f0f;
    --bg-card: #1a1a1a;
    --bg-input: #252525;
    --text: #e0e0e0;
    --text-muted: #888;
    --accent: #6c9bff;
    --accent-hover: #8bb2ff;
    --danger: #ff6b6b;
    --danger-hover: #ff8a8a;
    --block-color: #444;
    --peek-color: #6c9bff;
    --border: #333;
    --progress-bg: #252525;
    --progress-fill: #6c9bff;
    --radius: 8px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100dvh;
}

.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 16px;
}

/* Header */
.header {
    text-align: center;
    padding: 24px 0 16px;
}

.header__title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
    letter-spacing: 0.02em;
}

/* Views */
.view[hidden] {
    display: none;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 24px;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn--primary {
    background: var(--accent);
    color: #000;
    width: 100%;
}

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

.btn--primary:disabled {
    opacity: 0.5;
    cursor: default;
}

.btn--secondary {
    background: var(--bg-input);
    color: var(--text);
    width: 100%;
    border: 1px solid var(--border);
}

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

.btn--ghost {
    background: none;
    color: var(--text-muted);
    padding: 10px 12px;
}

.btn--ghost:hover {
    color: var(--text);
}

.btn--small {
    min-height: 36px;
    font-size: 0.875rem;
    padding: 6px 12px;
}

.btn--danger {
    color: var(--danger);
}

.btn--danger:hover {
    color: var(--danger-hover);
}

/* Code Entry */
.code-form {
    padding-top: 32px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.code-form__about {
    color: var(--text-muted);
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 8px;
}

.code-form__label {
    font-size: 1.125rem;
    font-weight: 600;
}

.code-form__hint {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-top: -4px;
    padding-left: 1.2em;
    list-style: disc;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.code-form__input {
    font-size: 1rem;
    padding: 12px 16px;
    min-height: 44px;
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
}

.code-form__input:focus {
    border-color: var(--accent);
}

/* Text List */
.list-header {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
}

.text-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.text-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: border-color 0.15s;
    -webkit-tap-highlight-color: transparent;
    display: flex;
    align-items: center;
    gap: 12px;
}

.text-card:hover {
    border-color: var(--accent);
}

.text-card__handle {
    flex-shrink: 0;
    cursor: grab;
    color: var(--text-muted);
    font-size: 1.2rem;
    padding: 4px;
    line-height: 1;
    user-select: none;
    touch-action: none;
}

.text-card__handle:hover {
    color: var(--text);
}

.text-card__handle:active {
    cursor: grabbing;
}

.text-card__body {
    flex: 1;
    min-width: 0;
}

.text-card__title {
    font-weight: 600;
    margin-bottom: 8px;
}

/* SortableJS states */
.sortable-ghost {
    opacity: 0.3;
}

.sortable-drag {
    opacity: 1;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

.text-card__progress {
    display: flex;
    align-items: center;
    gap: 10px;
}

.text-card__bar {
    flex: 1;
    height: 6px;
    background: var(--progress-bg);
    border-radius: 3px;
    overflow: hidden;
}

.text-card__fill {
    height: 100%;
    background: var(--progress-fill);
    border-radius: 3px;
    transition: width 0.3s;
}

.text-card__label {
    font-size: 0.8rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.text-list__empty {
    text-align: center;
    color: var(--text-muted);
    padding: 32px 0;
}

/* Add Text */
.add-text {
    margin-top: 8px;
}

.add-text__toggle {
    list-style: none;
    cursor: pointer;
}

.add-text__toggle::-webkit-details-marker {
    display: none;
}

.add-text__form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 16px;
}

.add-text__title,
.add-text__textarea {
    font-size: 1rem;
    padding: 12px 16px;
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    outline: none;
    font-family: inherit;
}

.add-text__title:focus,
.add-text__textarea:focus {
    border-color: var(--accent);
}

.add-text__textarea {
    resize: vertical;
    min-height: 120px;
}

/* Edit Form */
.edit-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.edit-form[hidden] {
    display: none;
}

.edit-form__actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.edit-form__actions .btn--primary {
    flex: 1;
}

/* Memorize View */
.memo-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
}

.memo-header__title {
    font-size: 1.125rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.memo-progress {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--progress-bg);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar__fill {
    height: 100%;
    background: var(--progress-fill);
    border-radius: 4px;
    transition: width 0.3s;
}

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

/* Tokens */
.memo-tokens {
    line-height: 1.6;
    margin-bottom: 24px;
    font-size: 1.25rem;
}

.word {
    display: inline;
    cursor: default;
    padding: 0 2px;
    border-radius: 2px;
}

.word--hidden {
    color: transparent;
    background: var(--block-color);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.word--peeking {
    color: var(--peek-color);
    background: transparent;
    animation: peek-fade 0.6s ease forwards;
}

@keyframes peek-fade {
    0% { color: var(--peek-color); background: transparent; }
    50% { color: var(--peek-color); background: transparent; }
    100% { color: transparent; background: var(--block-color); }
}

.word--complete {
    color: var(--accent);
    background: transparent;
}

.punct {
    display: inline;
    color: var(--text-muted);
}

/* Memo Actions */
.memo-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.memo-actions .btn--primary {
    flex: 1;
}

.memo-actions[hidden] {
    display: none;
}

.memo-actions .btn[hidden] {
    display: none;
}

.memo-actions .btn--ghost {
    flex-shrink: 0;
}

/* Loading state */
.loading {
    text-align: center;
    color: var(--text-muted);
    padding: 24px 0;
}

/* Danger zone (delete) */
.memo-danger-zone {
    margin-top: 32px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    text-align: center;
}

.btn--delete {
    color: var(--danger);
    font-size: 0.85rem;
    min-height: 36px;
}

.btn--delete:hover {
    color: var(--danger-hover);
}
