* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #f5a623 0%, #f76b1c 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1800px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    padding: 30px;
}

h1 {
    color: #333;
    margin-bottom: 24px;
    font-size: 1.8em;
    border-bottom: 3px solid #f76b1c;
    padding-bottom: 14px;
}

/* ===== Controls ===== */
.controls {
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.control-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 120px;
}

.control-item.stretch {
    flex: 1;
}

.control-item label {
    font-size: 11px;
    font-weight: 700;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.control-item input[type="text"],
.control-item select {
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 14px;
    background: white;
    transition: border-color 0.2s;
    height: 38px;
}

.control-item input[type="text"]:focus,
.control-item select:focus {
    outline: none;
    border-color: #f76b1c;
}

.reset-btn {
    padding: 0 20px;
    height: 38px;
    background: #e53935;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.reset-btn:hover {
    background: #c62828;
}

/* ===== Tag Checkboxes ===== */
.tag-clear-btn {
    color: #f76b1c;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    text-transform: none;
    letter-spacing: 0;
    margin-left: 4px;
}

.tag-clear-btn:hover {
    text-decoration: underline;
}

.tag-checkboxes {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    padding: 8px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    background: white;
    align-items: flex-start;
}

.tag-category {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 180px;
    gap: 4px;
    padding: 2px 12px;
}

.tag-category + .tag-category {
    border-left: 1px solid #e8e8e8;
}

.tag-category-label {
    font-size: 11px;
    font-weight: 700;
    color: #f76b1c;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
    margin-bottom: 4px;
    padding-bottom: 3px;
    border-bottom: 2px solid #f76b1c;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tag-category-label::after {
    content: '';
    display: none;
    font-size: 10px;
    font-weight: 400;
    letter-spacing: 0;
    text-transform: none;
}

.tag-items {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tag-checkbox-label {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border: 1px solid #ddd;
    border-radius: 12px;
    font-size: 12px;
    cursor: pointer;
    background: #f5f5f5;
    transition: background 0.15s, border-color 0.15s;
    user-select: none;
}

.tag-checkbox-label:hover {
    background: #ffe0cc;
    border-color: #f76b1c;
}

.tag-checkbox-label input[type="checkbox"] {
    accent-color: #f76b1c;
    cursor: pointer;
}

.tag-checkbox-label:has(input:checked) {
    background: #f76b1c;
    color: white;
    border-color: #f76b1c;
}

.tag-jp {
    margin-left: 5px;
    font-size: 11px;
    color: rgba(0,0,0,0.4);
    font-weight: 400;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tag-checkbox-label[data-tip] {
    position: relative;
}

.tag-checkbox-label[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    left: 0;
    top: calc(100% + 4px);
    background: #333;
    color: #fff;
    font-size: 11px;
    font-weight: 400;
    padding: 5px 8px;
    border-radius: 5px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 100;
}

.tag-checkbox-label[data-tip]:hover::after {
    opacity: 1;
}

.tag-count {
    display: inline-block;
    margin-left: 4px;
    padding: 0 5px;
    background: rgba(0,0,0,0.15);
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
    line-height: 1.6;
}

/* ===== Card layout (mobile) ===== */
.card-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.course-card {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 13px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
}

.card-title {
    font-weight: 600;
    font-size: 14px;
    line-height: 1.4;
    flex: 1;
}

.card-title-jp {
    font-size: 12px;
    color: #3b82f6;
    margin-top: 2px;
}

.card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    font-size: 12px;
    color: #666;
}

.card-duration {
    background: #f3f4f6;
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 11px;
    color: #444;
}

.card-body {
    margin-top: 8px;
    border-top: 1px solid #f0f0f0;
    padding-top: 8px;
}

.card-desc-toggle {
    font-size: 12px;
    color: #f76b1c;
    cursor: pointer;
    user-select: none;
    font-weight: 600;
}

.card-desc-toggle:hover {
    text-decoration: underline;
}

.card-desc {
    margin-top: 6px;
    display: none;
}

.card-desc.open {
    display: block;
}

/* ===== Responsive ===== */

/* ===== Stats ===== */
.data-notice {
    font-size: 12px;
    color: #999;
    margin-bottom: 20px;
    transition: color 0.2s;
}

.control-subrow {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.stats {
    margin-bottom: 12px;
    font-size: 14px;
    color: #666;
    font-weight: 500;
}

/* ===== Table ===== */
.table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    table-layout: fixed;
}

thead {
    background: #f76b1c;
    color: white;
    position: sticky;
    top: 0;
    z-index: 1;
}

th {
    padding: 12px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    user-select: none;
}

th.sortable {
    cursor: pointer;
}

th.sortable:hover {
    background: #e55a0a;
}

th.sort-asc::after  { content: ' ▲'; font-size: 10px; }
th.sort-desc::after { content: ' ▼'; font-size: 10px; }

td {
    padding: 10px;
    border-bottom: 1px solid #eee;
    vertical-align: top;
}

tbody {
    counter-reset: row-num;
}

tbody tr {
    counter-increment: row-num;
}

td.col-num::before {
    content: counter(row-num);
}

tbody tr:hover {
    background-color: #fff8f3;
}

tbody tr:nth-child(even) {
    background-color: #fafafa;
}

tbody tr:nth-child(even):hover {
    background-color: #fff8f3;
}

/* ===== Column widths ===== */
.col-num      { width: 36px;  text-align: center; color: #aaa; }
.col-id       { width: 44px;  text-align: center; font-weight: 600; }
.col-center   { text-align: center; }
.col-title    { width: calc((100% - 368px) / 3);     font-weight: 500; overflow-wrap: break-word; }
.col-text     { overflow-wrap: break-word; }
td.col-text   { color: #555; }
.col-duration { width: 64px;  text-align: center; }
.col-tags     { width: 50px; overflow-wrap: break-word; }
.col-link     { width: 64px;  text-align: center; }

/* ===== Cell content ===== */
.html-content {
    font-size: 13px;
    line-height: 1.5;
    color: #444;
}

.html-content p {
    margin: 0 0 6px;
}

.html-content p:last-child {
    margin-bottom: 0;
}

.html-content ul,
.html-content ol {
    margin: 0 0 6px;
    padding-left: 1.4em;
}

.html-content li {
    margin-bottom: 2px;
}

.jp-text {
    color: #3b82f6;
    font-size: 12px;
    margin-top: 4px;
    line-height: 1.5;
}

.truncated {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
}

.badge-new {
    display: inline-block;
    padding: 2px 7px;
    background: #43a047;
    color: white;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 700;
}

.tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.tag {
    background: #eeeeee;
    color: #444;
    padding: 2px 7px;
    border-radius: 10px;
    font-size: 11px;
    white-space: nowrap;
}

.course-link {
    display: inline-block;
    padding: 4px 10px;
    background: #f76b1c;
    color: white;
    border-radius: 4px;
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    transition: background 0.2s;
}

.course-link:hover {
    background: #e55a0a;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: #aaa;
    font-size: 15px;
}

.tag-label-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.tag-toggle-btn {
    display: none;
}

/* ===== Responsive ===== */
@media (max-width: 700px) {
    body           { padding: 10px; }
    .container     { background: transparent; border-radius: 0; box-shadow: none; padding: 8px 0; }
    h1             { font-size: 1.3em; margin-bottom: 8px; color: white; border-bottom-color: rgba(255,255,255,0.5); }
    .data-notice   { color: rgba(255,255,255,0.8); margin-bottom: 12px; }
    .stats         { color: rgba(255,255,255,0.9); }
    .controls      { padding: 10px; gap: 8px; margin-bottom: 12px; }
    .control-row   { flex-wrap: wrap; gap: 8px; }
    .control-subrow { width: 100%; justify-content: space-between; }
    .control-subrow .control-item:first-child { flex: 1; }
    .tag-toggle-btn { display: none; }
    .tag-checkboxes { padding: 4px; flex-direction: column; }
    .tag-category-label { cursor: pointer; }
    .tag-category-label::after { display: inline; content: ' ▶'; }
    .tag-category.open > .tag-category-label::after { content: ' ▼'; }
    .tag-items { display: none; margin-top: 4px; }
    .tag-category.open > .tag-items { display: flex; }
    .table-wrapper { display: none; }
    #cardList      { display: flex !important; }
    .tag-category  { min-width: 0; width: 100%; padding: 6px 8px; }
    .tag-category + .tag-category { border-left: none; border-top: 1px solid #e8e8e8; }
}

@media (min-width: 701px) {
    #cardList { display: none !important; }
}
